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:
@@ -131,6 +131,8 @@ func (h *Handler) GetTenderApprovalByTenderAndCompany(c echo.Context) error {
|
||||
// @Produce json
|
||||
// @Param submission_mode query string false "Filter by submission mode Enums(self-apply, partnership)"
|
||||
// @Param status query string false "Filter by status Enums(submitted, rejected)"
|
||||
// @Param created_from query integer false "Filter by created date from (Unix timestamp)"
|
||||
// @Param created_to query integer false "Filter by created date to (Unix timestamp)"
|
||||
// @Success 200 {object} response.APIResponse{data=[]TenderApprovalWithTenderResponse} "Tender approvals retrieved successfully"
|
||||
// @Failure 400 {object} response.APIResponse "Bad request - Invalid company ID"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
@@ -166,7 +168,21 @@ func (h *Handler) PublicGetTenderApprovals(c echo.Context) error {
|
||||
status = &statusVal
|
||||
}
|
||||
|
||||
tenderApprovalsWithTender, err := h.service.GetTenderApprovalsByCompanyIDWithTender(c.Request().Context(), companyID, submissionMode, status)
|
||||
var from *int64
|
||||
if fromParam := c.QueryParam("created_from"); fromParam != "" {
|
||||
if parsed, err := strconv.ParseInt(fromParam, 10, 64); err == nil {
|
||||
from = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
var to *int64
|
||||
if toParam := c.QueryParam("created_to"); toParam != "" {
|
||||
if parsed, err := strconv.ParseInt(toParam, 10, 64); err == nil {
|
||||
to = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
tenderApprovalsWithTender, err := h.service.GetTenderApprovalsByCompanyIDWithTender(c.Request().Context(), companyID, submissionMode, status, from, to)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to get tender approvals")
|
||||
}
|
||||
|
||||
@@ -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{}{
|
||||
|
||||
@@ -17,8 +17,8 @@ type Service interface {
|
||||
GetTenderApprovalByTenderAndCompany(ctx context.Context, tenderID, companyID string) (*TenderApproval, error)
|
||||
GetTenderApprovalByTenderAndCompanyWithTender(ctx context.Context, tenderID, companyID string) (*TenderApprovalWithTenderResponse, error)
|
||||
GetTenderApprovalsByTenderID(ctx context.Context, tenderID string) ([]*TenderApproval, error)
|
||||
GetTenderApprovalsByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApproval, error)
|
||||
GetTenderApprovalsByCompanyIDWithTender(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApprovalWithTenderResponse, error)
|
||||
GetTenderApprovalsByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApproval, error)
|
||||
GetTenderApprovalsByCompanyIDWithTender(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApprovalWithTenderResponse, error)
|
||||
GetTenderApprovalsByIDs(ctx context.Context, ids []string) ([]*TenderApproval, error)
|
||||
UpdateTenderApproval(ctx context.Context, id string, form *UpdateTenderApprovalForm) (*TenderApproval, error)
|
||||
UpdateTenderApprovalWithTender(ctx context.Context, id string, form *UpdateTenderApprovalForm) (*TenderApprovalWithTenderResponse, error)
|
||||
@@ -261,8 +261,8 @@ func (s *tenderApprovalService) GetTenderApprovalsByTenderID(ctx context.Context
|
||||
}
|
||||
|
||||
// GetTenderApprovalsByCompanyID retrieves all tender approvals for a specific company with optional filters
|
||||
func (s *tenderApprovalService) GetTenderApprovalsByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApproval, error) {
|
||||
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status)
|
||||
func (s *tenderApprovalService) GetTenderApprovalsByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApproval, error) {
|
||||
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status, from, to)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -280,8 +280,8 @@ func (s *tenderApprovalService) GetTenderApprovalsByCompanyID(ctx context.Contex
|
||||
}
|
||||
|
||||
// GetTenderApprovalsByCompanyIDWithTender retrieves all tender approvals for a specific company with tender details
|
||||
func (s *tenderApprovalService) GetTenderApprovalsByCompanyIDWithTender(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApprovalWithTenderResponse, error) {
|
||||
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status)
|
||||
func (s *tenderApprovalService) GetTenderApprovalsByCompanyIDWithTender(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus, from *int64, to *int64) ([]*TenderApprovalWithTenderResponse, error) {
|
||||
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status, from, to)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
|
||||
Reference in New Issue
Block a user