Add Company Tender Approval Statistics Endpoint and Update API Documentation

- Introduced a new API endpoint to retrieve company-specific tender approval statistics, enhancing the analytics capabilities of the tender management system.
- Implemented the `GetCompanyTenderApprovalStats` method in the service layer to fetch detailed statistics, including total approvals, approved and rejected tenders, and submission counts.
- Updated Swagger documentation to accurately reflect the new endpoint, including detailed descriptions, parameters, and response formats for the `CompanyTenderApprovalStatsResponse`.
- Enhanced the router to include the new statistics route, ensuring adherence to Clean Architecture principles and maintaining a clear separation of concerns in the handler layer.
- Added necessary request and response forms to support the new functionality, improving the overall API structure and usability.
This commit is contained in:
n.nakhostin
2025-08-19 11:27:40 +03:30
parent 392b31626d
commit 81914e2eeb
8 changed files with 432 additions and 0 deletions
+43
View File
@@ -29,6 +29,7 @@ type Repository interface {
CountByTenderID(ctx context.Context, tenderID string) (int64, error)
CountByCompanyID(ctx context.Context, companyID string) (int64, error)
GetTenderApprovalStats(ctx context.Context) (*TenderApprovalStatsResponse, error)
GetCompanyTenderApprovalStats(ctx context.Context, companyID string) (*CompanyTenderApprovalStatsResponse, error)
SearchByCriteria(ctx context.Context, criteria *TenderApprovalSearchCriteria) ([]*TenderApproval, error)
}
@@ -501,6 +502,48 @@ func (r *tenderApprovalRepository) GetTenderApprovalStats(ctx context.Context) (
return stats, nil
}
// GetCompanyTenderApprovalStats returns company-specific tender approval statistics
func (r *tenderApprovalRepository) GetCompanyTenderApprovalStats(ctx context.Context, companyID string) (*CompanyTenderApprovalStatsResponse, error) {
// Get company-specific counts
totalApprovals, _ := r.CountByCompanyID(ctx, companyID)
// Count by status for this company
approvedFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusApproved)}
approvedTenders, _ := r.ormRepo.Count(ctx, approvedFilter)
rejectedFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusRejected)}
rejectedTenders, _ := r.ormRepo.Count(ctx, rejectedFilter)
// Count by submission mode for this company
selfApplyFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModeSelfApply)}
selfApplyCount, _ := r.ormRepo.Count(ctx, selfApplyFilter)
partnershipFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModePartnership)}
partnershipCount, _ := r.ormRepo.Count(ctx, partnershipFilter)
stats := &CompanyTenderApprovalStatsResponse{
CompanyID: companyID,
TotalApprovals: totalApprovals,
ApprovedTenders: approvedTenders,
RejectedTenders: rejectedTenders,
SelfApplyCount: selfApplyCount,
PartnershipCount: partnershipCount,
ApprovalsByStatus: make(map[string]int64),
ApprovalsBySubmission: make(map[string]int64),
LastUpdated: time.Now().Unix(),
}
// Add status breakdown
stats.ApprovalsByStatus["approved"] = approvedTenders
stats.ApprovalsByStatus["rejected"] = rejectedTenders
// Add submission mode breakdown
stats.ApprovalsBySubmission["self-apply"] = selfApplyCount
stats.ApprovalsBySubmission["partnership"] = partnershipCount
return stats, nil
}
// SearchByCriteria searches tender approvals using search criteria
func (r *tenderApprovalRepository) SearchByCriteria(ctx context.Context, criteria *TenderApprovalSearchCriteria) ([]*TenderApproval, error) {
// Convert criteria to search parameters