mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools
Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
* GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
* GET /api/v1/users/me/organizations - User organizations
* POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue
API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules
Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"bugulma/backend/internal/domain"
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
// SiteService handles business logic for sites
|
|
type SiteService struct {
|
|
repo domain.SiteRepository
|
|
}
|
|
|
|
// NewSiteService creates a new site service
|
|
func NewSiteService(repo domain.SiteRepository) *SiteService {
|
|
return &SiteService{repo: repo}
|
|
}
|
|
|
|
// CreateSiteRequest represents the request to create a site
|
|
type CreateSiteRequest struct {
|
|
Name string
|
|
Latitude float64
|
|
Longitude float64
|
|
SiteType domain.SiteType
|
|
FloorAreaM2 float64
|
|
Ownership domain.Ownership
|
|
OwnerOrganizationID string
|
|
AvailableUtilities []string
|
|
ParkingSpaces int
|
|
LoadingDocks int
|
|
CraneCapacityTonnes float64
|
|
EnergyRating string
|
|
}
|
|
|
|
// Create creates a new site
|
|
func (s *SiteService) Create(ctx context.Context, req CreateSiteRequest) (*domain.Site, error) {
|
|
utilitiesJSON, _ := json.Marshal(req.AvailableUtilities)
|
|
|
|
site := &domain.Site{
|
|
ID: uuid.New().String(),
|
|
Name: req.Name,
|
|
Latitude: req.Latitude,
|
|
Longitude: req.Longitude,
|
|
SiteType: req.SiteType,
|
|
FloorAreaM2: req.FloorAreaM2,
|
|
Ownership: req.Ownership,
|
|
OwnerOrganizationID: req.OwnerOrganizationID,
|
|
AvailableUtilities: datatypes.JSON(utilitiesJSON),
|
|
ParkingSpaces: req.ParkingSpaces,
|
|
LoadingDocks: req.LoadingDocks,
|
|
CraneCapacityTonnes: req.CraneCapacityTonnes,
|
|
EnergyRating: req.EnergyRating,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}
|
|
|
|
if err := s.repo.Create(ctx, site); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return site, nil
|
|
}
|
|
|
|
// GetByID retrieves a site by ID
|
|
func (s *SiteService) GetByID(ctx context.Context, id string) (*domain.Site, error) {
|
|
return s.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// GetAll retrieves all sites
|
|
func (s *SiteService) GetAll(ctx context.Context) ([]*domain.Site, error) {
|
|
return s.repo.GetAll(ctx)
|
|
}
|
|
|
|
// GetByOrganizationID retrieves sites owned by an organization
|
|
func (s *SiteService) GetByOrganizationID(ctx context.Context, organizationID string) ([]*domain.Site, error) {
|
|
return s.repo.GetByOrganizationID(ctx, organizationID)
|
|
}
|
|
|
|
// GetNearby retrieves sites within a radius
|
|
func (s *SiteService) GetNearby(ctx context.Context, lat, lng, radiusKm float64) ([]*domain.Site, error) {
|
|
return s.repo.GetWithinRadius(ctx, lat, lng, radiusKm)
|
|
}
|
|
|
|
// GetHeritageSites retrieves sites with heritage status
|
|
func (s *SiteService) GetHeritageSites(ctx context.Context, locale string) ([]*domain.Site, error) {
|
|
return s.repo.GetHeritageSites(ctx, locale)
|
|
}
|
|
|
|
// Update updates a site
|
|
func (s *SiteService) Update(ctx context.Context, site *domain.Site) error {
|
|
site.UpdatedAt = time.Now()
|
|
return s.repo.Update(ctx, site)
|
|
}
|
|
|
|
// Delete deletes a site
|
|
func (s *SiteService) Delete(ctx context.Context, id string) error {
|
|
return s.repo.Delete(ctx, id)
|
|
}
|