Enhance Tender Approval Filtering with Created Date Parameters

- Added new query parameters `created_from` and `created_to` to the tender approval endpoints for filtering by creation date using Unix timestamps.
- Updated the `GetByCompanyID` method in the repository and service layers to support the new filtering options.
- Modified the handler methods to parse and pass the new parameters, improving the flexibility of tender approval retrieval.
- Updated API documentation to reflect the new query parameters, ensuring clarity for API consumers.
This commit is contained in:
n.nakhostin
2025-09-03 10:23:47 +03:30
parent 8d3a021fbf
commit 61a217cf09
6 changed files with 64 additions and 9 deletions
+9 -2
View File
@@ -17,7 +17,7 @@ type Repository interface {
GetByID(ctx context.Context, id string) (*TenderApproval, error)
GetByTenderAndCompany(ctx context.Context, tenderID, companyID string) (*TenderApproval, error)
GetByTenderID(ctx context.Context, tenderID string) ([]*TenderApproval, error)
GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApproval, error)
GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApproval, error)
GetByIDs(ctx context.Context, ids []string) ([]*TenderApproval, error)
Update(ctx context.Context, tenderApproval *TenderApproval) error
Delete(ctx context.Context, id string) error
@@ -160,7 +160,7 @@ func (r *tenderApprovalRepository) GetByTenderID(ctx context.Context, tenderID s
}
// GetByCompanyID retrieves all tender approvals for a specific company with optional filters
func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApproval, error) {
func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApproval, error) {
filter := bson.M{"company_id": companyID}
// Add submission mode filter if provided
@@ -173,6 +173,13 @@ func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID
filter["status"] = *status
}
if from != nil {
filter["created_at"] = bson.M{"$gte": *from}
}
if to != nil {
filter["created_at"] = bson.M{"$lte": *to}
}
result, err := r.ormRepo.FindAll(ctx, filter, mongo.NewPaginationBuilder().SortDesc("created_at").Build())
if err != nil {
r.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{