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)
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"bugulma/backend/internal/domain"
|
|
"bugulma/backend/internal/matching"
|
|
)
|
|
|
|
// IncrementalMatchCalculator handles incremental match recalculations
|
|
type IncrementalMatchCalculator struct {
|
|
matchingService *matching.Service
|
|
matchRepo domain.MatchRepository
|
|
}
|
|
|
|
// RecalculateMatch performs incremental recalculation for a single match
|
|
func (imc *IncrementalMatchCalculator) RecalculateMatch(ctx context.Context, matchID string) error {
|
|
match, err := imc.matchRepo.GetByID(ctx, matchID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get match: %w", err)
|
|
}
|
|
|
|
// Get current resource flows
|
|
sourceFlow, err := imc.matchingService.GetResourceFlowByID(ctx, match.SourceResourceID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get source flow: %w", err)
|
|
}
|
|
|
|
targetFlow, err := imc.matchingService.GetResourceFlowByID(ctx, match.TargetResourceID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get target flow: %w", err)
|
|
}
|
|
|
|
// Calculate distance
|
|
sourceSite, err := imc.matchingService.GetSiteByID(ctx, sourceFlow.SiteID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get source site: %w", err)
|
|
}
|
|
|
|
targetSite, err := imc.matchingService.GetSiteByID(ctx, targetFlow.SiteID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get target site: %w", err)
|
|
}
|
|
|
|
distance := imc.matchingService.CalculateDistance(
|
|
sourceSite.Latitude, sourceSite.Longitude,
|
|
targetSite.Latitude, targetSite.Longitude,
|
|
)
|
|
|
|
// TODO: Recalculate economic analysis using new financial calculator
|
|
// For now, skip economic recalculation
|
|
_ = sourceFlow
|
|
_ = targetFlow
|
|
_ = distance
|
|
|
|
// Recalculate compatibility and other scores
|
|
// This would involve running the scoring algorithms again
|
|
|
|
return imc.matchRepo.Update(ctx, match)
|
|
}
|
|
|
|
// RecalculateAffectedMatches recalculates multiple affected matches
|
|
func (imc *IncrementalMatchCalculator) RecalculateAffectedMatches(ctx context.Context, matchIDs []string) error {
|
|
for _, matchID := range matchIDs {
|
|
if err := imc.RecalculateMatch(ctx, matchID); err != nil {
|
|
log.Printf("Failed to recalculate match %s: %v", matchID, err)
|
|
// Continue with other matches even if one fails
|
|
}
|
|
}
|
|
return nil
|
|
}
|