Update Configuration and Enhance Tender Approval Pagination
- Changed the server port from 8081 to 8082 for the web application. - Updated MongoDB URI to include authentication credentials for improved security. - Added new query parameters `limit` and `offset` for pagination in tender approval retrieval, enhancing the API's flexibility. - Modified the response structure to include metadata for pagination, improving the clarity of responses. - Updated API documentation to reflect the new pagination parameters and response format, ensuring consistency for API consumers.
This commit is contained in:
@@ -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, from *int64, to *int64) ([]*TenderApproval, error)
|
||||
GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, limit int, offset int, from *int64, to *int64) ([]*TenderApproval, int64, error)
|
||||
GetByIDs(ctx context.Context, ids []string) ([]*TenderApproval, error)
|
||||
Update(ctx context.Context, tenderApproval *TenderApproval) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
@@ -160,9 +160,16 @@ 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, from *int64, to *int64) ([]*TenderApproval, error) {
|
||||
func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, limit int, offset int, from *int64, to *int64) ([]*TenderApproval, int64, error) {
|
||||
filter := bson.M{"company_id": companyID}
|
||||
|
||||
pagination := mongo.Pagination{
|
||||
Limit: limit,
|
||||
Skip: offset,
|
||||
SortField: "created_at",
|
||||
SortOrder: -1,
|
||||
}
|
||||
|
||||
// Add submission mode filter if provided
|
||||
if submissionMode != nil {
|
||||
filter["submission_mode"] = *submissionMode
|
||||
@@ -180,13 +187,13 @@ func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID
|
||||
filter["created_at"] = bson.M{"$lte": *to}
|
||||
}
|
||||
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, mongo.NewPaginationBuilder().SortDesc("created_at").Build())
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"company_id": companyID,
|
||||
})
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Convert []TenderApproval to []*TenderApproval
|
||||
@@ -195,7 +202,7 @@ func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID
|
||||
tenderApprovals[i] = &result.Items[i]
|
||||
}
|
||||
|
||||
return tenderApprovals, nil
|
||||
return tenderApprovals, result.TotalCount, nil
|
||||
}
|
||||
|
||||
// GetByIDs retrieves multiple tender approvals by their IDs
|
||||
|
||||
Reference in New Issue
Block a user