Refactor Tender Approval Logic and Update Statistics Structure
- Modified the Reject method in the TenderApproval entity to reset the SubmissionMode field upon rejection, ensuring proper state management. - Simplified the TenderApprovalStatsResponse and CompanyTenderApprovalStatsResponse structures by removing unnecessary fields related to submission modes, streamlining the data model for tender approval statistics. - Updated the GetTenderApprovalStats and GetCompanyTenderApprovalStats methods in the repository to reflect the changes in the statistics structure, enhancing clarity and maintainability. - These adjustments improve the overall functionality and data handling of the tender management system.
This commit is contained in:
@@ -145,6 +145,7 @@ func (ta *TenderApproval) Approve() {
|
|||||||
// Reject rejects the tender with a reason
|
// Reject rejects the tender with a reason
|
||||||
func (ta *TenderApproval) Reject() {
|
func (ta *TenderApproval) Reject() {
|
||||||
ta.Status = ApprovalStatusRejected
|
ta.Status = ApprovalStatusRejected
|
||||||
|
ta.SubmissionMode = ""
|
||||||
ta.CreatedAt = time.Now().Unix()
|
ta.CreatedAt = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ type TenderApprovalStatsResponse struct {
|
|||||||
TotalApprovals int64 `json:"total_approvals"`
|
TotalApprovals int64 `json:"total_approvals"`
|
||||||
ApprovedTenders int64 `json:"approved_tenders"`
|
ApprovedTenders int64 `json:"approved_tenders"`
|
||||||
RejectedTenders int64 `json:"rejected_tenders"`
|
RejectedTenders int64 `json:"rejected_tenders"`
|
||||||
ApprovalsByStatus map[string]int64 `json:"approvals_by_status"`
|
|
||||||
ApprovalsBySubmission map[string]int64 `json:"approvals_by_submission"`
|
|
||||||
LastUpdated int64 `json:"last_updated"`
|
LastUpdated int64 `json:"last_updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +75,6 @@ type CompanyTenderApprovalStatsResponse struct {
|
|||||||
RejectedTenders int64 `json:"rejected_tenders"`
|
RejectedTenders int64 `json:"rejected_tenders"`
|
||||||
SelfApplyCount int64 `json:"self_apply_count"`
|
SelfApplyCount int64 `json:"self_apply_count"`
|
||||||
PartnershipCount int64 `json:"partnership_count"`
|
PartnershipCount int64 `json:"partnership_count"`
|
||||||
ApprovalsByStatus map[string]int64 `json:"approvals_by_status"`
|
|
||||||
ApprovalsBySubmission map[string]int64 `json:"approvals_by_submission"`
|
|
||||||
LastUpdated int64 `json:"last_updated"`
|
LastUpdated int64 `json:"last_updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -478,27 +478,13 @@ func (r *tenderApprovalRepository) GetTenderApprovalStats(ctx context.Context) (
|
|||||||
approvedTenders, _ := r.CountByStatus(ctx, ApprovalStatusApproved)
|
approvedTenders, _ := r.CountByStatus(ctx, ApprovalStatusApproved)
|
||||||
rejectedTenders, _ := r.CountByStatus(ctx, ApprovalStatusRejected)
|
rejectedTenders, _ := r.CountByStatus(ctx, ApprovalStatusRejected)
|
||||||
|
|
||||||
// For this implementation, we'll return basic stats
|
|
||||||
// In a real implementation, you'd use MongoDB aggregation pipelines
|
|
||||||
stats := &TenderApprovalStatsResponse{
|
stats := &TenderApprovalStatsResponse{
|
||||||
TotalApprovals: totalApprovals,
|
TotalApprovals: totalApprovals,
|
||||||
ApprovedTenders: approvedTenders,
|
ApprovedTenders: approvedTenders,
|
||||||
RejectedTenders: rejectedTenders,
|
RejectedTenders: rejectedTenders,
|
||||||
ApprovalsByStatus: make(map[string]int64),
|
|
||||||
ApprovalsBySubmission: make(map[string]int64),
|
|
||||||
LastUpdated: time.Now().Unix(),
|
LastUpdated: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add status breakdown
|
|
||||||
stats.ApprovalsByStatus["approved"] = approvedTenders
|
|
||||||
stats.ApprovalsByStatus["rejected"] = rejectedTenders
|
|
||||||
|
|
||||||
// Add submission mode breakdown
|
|
||||||
selfApplyCount, _ := r.CountBySubmissionMode(ctx, SubmissionModeSelfApply)
|
|
||||||
partnershipCount, _ := r.CountBySubmissionMode(ctx, SubmissionModePartnership)
|
|
||||||
stats.ApprovalsBySubmission["self-apply"] = selfApplyCount
|
|
||||||
stats.ApprovalsBySubmission["partnership"] = partnershipCount
|
|
||||||
|
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,10 +501,10 @@ func (r *tenderApprovalRepository) GetCompanyTenderApprovalStats(ctx context.Con
|
|||||||
rejectedTenders, _ := r.ormRepo.Count(ctx, rejectedFilter)
|
rejectedTenders, _ := r.ormRepo.Count(ctx, rejectedFilter)
|
||||||
|
|
||||||
// Count by submission mode for this company
|
// Count by submission mode for this company
|
||||||
selfApplyFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModeSelfApply)}
|
selfApplyFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusApproved), "submission_mode": string(SubmissionModeSelfApply)}
|
||||||
selfApplyCount, _ := r.ormRepo.Count(ctx, selfApplyFilter)
|
selfApplyCount, _ := r.ormRepo.Count(ctx, selfApplyFilter)
|
||||||
|
|
||||||
partnershipFilter := bson.M{"company_id": companyID, "submission_mode": string(SubmissionModePartnership)}
|
partnershipFilter := bson.M{"company_id": companyID, "status": string(ApprovalStatusApproved), "submission_mode": string(SubmissionModePartnership)}
|
||||||
partnershipCount, _ := r.ormRepo.Count(ctx, partnershipFilter)
|
partnershipCount, _ := r.ormRepo.Count(ctx, partnershipFilter)
|
||||||
|
|
||||||
stats := &CompanyTenderApprovalStatsResponse{
|
stats := &CompanyTenderApprovalStatsResponse{
|
||||||
@@ -528,19 +514,9 @@ func (r *tenderApprovalRepository) GetCompanyTenderApprovalStats(ctx context.Con
|
|||||||
RejectedTenders: rejectedTenders,
|
RejectedTenders: rejectedTenders,
|
||||||
SelfApplyCount: selfApplyCount,
|
SelfApplyCount: selfApplyCount,
|
||||||
PartnershipCount: partnershipCount,
|
PartnershipCount: partnershipCount,
|
||||||
ApprovalsByStatus: make(map[string]int64),
|
|
||||||
ApprovalsBySubmission: make(map[string]int64),
|
|
||||||
LastUpdated: time.Now().Unix(),
|
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
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -698,10 +698,6 @@ func (s *tenderApprovalService) GetAggregatedCompanyStats(ctx context.Context) (
|
|||||||
TotalApprovals: generalStats.TotalApprovals,
|
TotalApprovals: generalStats.TotalApprovals,
|
||||||
TotalApprovedTenders: generalStats.ApprovedTenders,
|
TotalApprovedTenders: generalStats.ApprovedTenders,
|
||||||
TotalRejectedTenders: generalStats.RejectedTenders,
|
TotalRejectedTenders: generalStats.RejectedTenders,
|
||||||
TotalSelfApplyCount: generalStats.ApprovalsBySubmission["self-apply"],
|
|
||||||
TotalPartnershipCount: generalStats.ApprovalsBySubmission["partnership"],
|
|
||||||
ApprovalsByStatus: generalStats.ApprovalsByStatus,
|
|
||||||
ApprovalsBySubmission: generalStats.ApprovalsBySubmission,
|
|
||||||
CompanyStats: []*CompanyTenderApprovalStatsResponse{}, // Empty for now
|
CompanyStats: []*CompanyTenderApprovalStatsResponse{}, // Empty for now
|
||||||
LastUpdated: time.Now().Unix(),
|
LastUpdated: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user