turash/bugulma/backend/internal/domain/service.go
Damir Mukimov 000eab4740
Major repository reorganization and missing backend endpoints implementation
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)
2025-11-25 06:01:16 +01:00

84 lines
3.2 KiB
Go

package domain
import (
"context"
"fmt"
"time"
"gorm.io/datatypes"
)
// ServiceType defines the type of service
type ServiceType string
const (
ServiceTypeMaintenance ServiceType = "maintenance"
ServiceTypeConsulting ServiceType = "consulting"
ServiceTypeTransport ServiceType = "transport"
ServiceTypeInspection ServiceType = "inspection"
ServiceTypeTraining ServiceType = "training"
ServiceTypeRepair ServiceType = "repair"
ServiceTypeOther ServiceType = "other"
)
// Service represents a service offered by an organization (database entity)
// Note: There's also a ServiceJSON struct in organization.go for API serialization
type Service struct {
ID string `gorm:"primaryKey;type:text"`
Type ServiceType `gorm:"not null;type:varchar(50);index"`
Domain string `gorm:"not null;type:text;index"` // Service domain (compressors, HVAC, etc.)
Description string `gorm:"type:text"`
OnSite bool `gorm:"not null;default:false"` // Whether service is performed on-site
HourlyRate float64 `gorm:"type:decimal(10,2)"` // € per hour
ServiceAreaKm float64 `gorm:"type:decimal(8,2)"` // Service area radius in km
Certifications datatypes.JSON `gorm:"default:'[]'"` // []string
// Business information
OrganizationID string `gorm:"not null;type:text;index"`
Organization *Organization `gorm:"foreignKey:OrganizationID"`
// Additional metadata
ResponseTime string `gorm:"type:text"` // Response time SLA
Warranty string `gorm:"type:text"` // Warranty terms
Specializations datatypes.JSON `gorm:"type:jsonb;default:'[]'"` // []string - specific specializations
Availability string `gorm:"type:text"` // Service availability
Sources datatypes.JSON `gorm:"type:jsonb"` // Data sources
// Timestamps
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
// TableName specifies the table name for GORM
func (Service) TableName() string {
return "services"
}
// ServiceRepository defines operations for service management
type ServiceRepository interface {
Create(ctx context.Context, service *Service) error
GetByID(ctx context.Context, id string) (*Service, error)
GetByOrganization(ctx context.Context, organizationID string) ([]*Service, error)
GetByType(ctx context.Context, serviceType ServiceType) ([]*Service, error)
GetByDomain(ctx context.Context, domain string) ([]*Service, error)
SearchByDescription(ctx context.Context, description string) ([]*Service, error)
GetByServiceArea(ctx context.Context, lat, lng, radiusKm float64) ([]*Service, error)
Update(ctx context.Context, service *Service) error
Delete(ctx context.Context, id string) error
GetAll(ctx context.Context) ([]*Service, error)
}
// Validate performs business rule validation
func (s *Service) Validate() error {
if s.Domain == "" {
return fmt.Errorf("service domain cannot be empty")
}
if s.HourlyRate < 0 {
return fmt.Errorf("hourly rate cannot be negative")
}
if s.ServiceAreaKm < 0 {
return fmt.Errorf("service area cannot be negative")
}
return nil
}