turash/bugulma/backend/internal/service/proposal_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

76 lines
2.1 KiB
Go

package service
import (
"bugulma/backend/internal/domain"
"context"
"fmt"
"github.com/google/uuid"
)
// ProposalService handles business logic for proposals
type ProposalService struct {
repo domain.ProposalRepository
}
// NewProposalService creates a new proposal service
func NewProposalService(repo domain.ProposalRepository) *ProposalService {
return &ProposalService{repo: repo}
}
// CreateProposalRequest represents the request to create a proposal
type CreateProposalRequest struct {
FromOrgID string
ToOrgID string
ResourceID string
ResourceType domain.ResourceDirection
ResourceName string
Message string
}
// Create creates a new proposal
func (s *ProposalService) Create(ctx context.Context, req CreateProposalRequest) (*domain.Proposal, error) {
proposal := &domain.Proposal{
ID: uuid.New().String(),
FromOrgID: req.FromOrgID,
ToOrgID: req.ToOrgID,
ResourceID: req.ResourceID,
ResourceType: req.ResourceType,
ResourceName: req.ResourceName,
Message: req.Message,
Status: domain.ProposalStatusPending,
}
err := s.repo.Create(ctx, proposal)
if err != nil {
return nil, fmt.Errorf("failed to create proposal: %w", err)
}
return proposal, nil
}
// GetByID retrieves a proposal by ID
func (s *ProposalService) GetByID(ctx context.Context, id string) (*domain.Proposal, error) {
return s.repo.GetByID(ctx, id)
}
// GetAll retrieves all proposals
func (s *ProposalService) GetAll(ctx context.Context) ([]*domain.Proposal, error) {
return s.repo.GetAll(ctx)
}
// GetByOrganizationID retrieves proposals for an organization
func (s *ProposalService) GetByOrganizationID(ctx context.Context, orgID string) ([]*domain.Proposal, error) {
return s.repo.GetByOrganizationID(ctx, orgID)
}
// UpdateStatus updates the status of a proposal
func (s *ProposalService) UpdateStatus(ctx context.Context, id string, status domain.ProposalStatus) error {
return s.repo.UpdateStatus(ctx, id, status)
}
// Delete deletes a proposal
func (s *ProposalService) Delete(ctx context.Context, id string) error {
return s.repo.Delete(ctx, id)
}