package application import ( "context" "mengstack/internal/kernel/model" "mengstack/internal/modules/example/domain" ) // Service contains the business logic for examples. type Service struct { repo domain.Repository } // NewService creates a new example service. func NewService(repo domain.Repository) *Service { return &Service{repo: repo} } func (s *Service) Create(ctx context.Context, tenantID string, req domain.CreateExampleRequest) (*domain.ExampleDTO, error) { e := &domain.Example{ BaseModel: model.BaseModel{TenantID: tenantID}, Name: req.Name, Description: req.Description, Status: 1, ExpiresAt: req.ExpiresAt, } if err := s.repo.Create(ctx, e); err != nil { return nil, err } dto := domain.ToDTO(e) return &dto, nil } func (s *Service) Get(ctx context.Context, tenantID string, id uint) (*domain.ExampleDTO, error) { e, err := s.repo.FindByID(ctx, tenantID, id) if err != nil { return nil, err } dto := domain.ToDTO(e) return &dto, nil } func (s *Service) List(ctx context.Context, tenantID string) ([]domain.ExampleDTO, error) { items, err := s.repo.FindAll(ctx, tenantID) if err != nil { return nil, err } dtos := make([]domain.ExampleDTO, len(items)) for i := range items { dtos[i] = domain.ToDTO(&items[i]) } return dtos, nil } func (s *Service) Delete(ctx context.Context, tenantID string, id uint) error { return s.repo.Delete(ctx, tenantID, id) }