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:
@@ -6025,6 +6025,18 @@ const docTemplate = `{
|
|||||||
"description": "Filter by status Enums(submitted, rejected)",
|
"description": "Filter by status Enums(submitted, rejected)",
|
||||||
"name": "status",
|
"name": "status",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by created date from (Unix timestamp)",
|
||||||
|
"name": "created_from",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by created date to (Unix timestamp)",
|
||||||
|
"name": "created_to",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -6019,6 +6019,18 @@
|
|||||||
"description": "Filter by status Enums(submitted, rejected)",
|
"description": "Filter by status Enums(submitted, rejected)",
|
||||||
"name": "status",
|
"name": "status",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by created date from (Unix timestamp)",
|
||||||
|
"name": "created_from",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Filter by created date to (Unix timestamp)",
|
||||||
|
"name": "created_to",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -5075,6 +5075,14 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
name: status
|
name: status
|
||||||
type: string
|
type: string
|
||||||
|
- description: Filter by created date from (Unix timestamp)
|
||||||
|
in: query
|
||||||
|
name: created_from
|
||||||
|
type: integer
|
||||||
|
- description: Filter by created date to (Unix timestamp)
|
||||||
|
in: query
|
||||||
|
name: created_to
|
||||||
|
type: integer
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ func (h *Handler) GetTenderApprovalByTenderAndCompany(c echo.Context) error {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param submission_mode query string false "Filter by submission mode Enums(self-apply, partnership)"
|
// @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 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"
|
// @Success 200 {object} response.APIResponse{data=[]TenderApprovalWithTenderResponse} "Tender approvals retrieved successfully"
|
||||||
// @Failure 400 {object} response.APIResponse "Bad request - Invalid company ID"
|
// @Failure 400 {object} response.APIResponse "Bad request - Invalid company ID"
|
||||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||||
@@ -166,7 +168,21 @@ func (h *Handler) PublicGetTenderApprovals(c echo.Context) error {
|
|||||||
status = &statusVal
|
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 {
|
if err != nil {
|
||||||
return response.InternalServerError(c, "Failed to get tender approvals")
|
return response.InternalServerError(c, "Failed to get tender approvals")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type Repository interface {
|
|||||||
GetByID(ctx context.Context, id string) (*TenderApproval, error)
|
GetByID(ctx context.Context, id string) (*TenderApproval, error)
|
||||||
GetByTenderAndCompany(ctx context.Context, tenderID, companyID string) (*TenderApproval, error)
|
GetByTenderAndCompany(ctx context.Context, tenderID, companyID string) (*TenderApproval, error)
|
||||||
GetByTenderID(ctx context.Context, tenderID 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)
|
GetByIDs(ctx context.Context, ids []string) ([]*TenderApproval, error)
|
||||||
Update(ctx context.Context, tenderApproval *TenderApproval) error
|
Update(ctx context.Context, tenderApproval *TenderApproval) error
|
||||||
Delete(ctx context.Context, id string) 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
|
// 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}
|
filter := bson.M{"company_id": companyID}
|
||||||
|
|
||||||
// Add submission mode filter if provided
|
// Add submission mode filter if provided
|
||||||
@@ -173,6 +173,13 @@ func (r *tenderApprovalRepository) GetByCompanyID(ctx context.Context, companyID
|
|||||||
filter["status"] = *status
|
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())
|
result, err := r.ormRepo.FindAll(ctx, filter, mongo.NewPaginationBuilder().SortDesc("created_at").Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
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)
|
GetTenderApprovalByTenderAndCompany(ctx context.Context, tenderID, companyID string) (*TenderApproval, error)
|
||||||
GetTenderApprovalByTenderAndCompanyWithTender(ctx context.Context, tenderID, companyID string) (*TenderApprovalWithTenderResponse, error)
|
GetTenderApprovalByTenderAndCompanyWithTender(ctx context.Context, tenderID, companyID string) (*TenderApprovalWithTenderResponse, error)
|
||||||
GetTenderApprovalsByTenderID(ctx context.Context, tenderID string) ([]*TenderApproval, error)
|
GetTenderApprovalsByTenderID(ctx context.Context, tenderID string) ([]*TenderApproval, error)
|
||||||
GetTenderApprovalsByCompanyID(ctx context.Context, companyID string, submissionMode *SubmissionMode, status *ApprovalStatus) ([]*TenderApproval, 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) ([]*TenderApprovalWithTenderResponse, 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)
|
GetTenderApprovalsByIDs(ctx context.Context, ids []string) ([]*TenderApproval, error)
|
||||||
UpdateTenderApproval(ctx context.Context, id string, form *UpdateTenderApprovalForm) (*TenderApproval, error)
|
UpdateTenderApproval(ctx context.Context, id string, form *UpdateTenderApprovalForm) (*TenderApproval, error)
|
||||||
UpdateTenderApprovalWithTender(ctx context.Context, id string, form *UpdateTenderApprovalForm) (*TenderApprovalWithTenderResponse, 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
|
// 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) {
|
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)
|
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status, from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
||||||
"error": err.Error(),
|
"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
|
// 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) {
|
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)
|
tenderApprovals, err := s.repository.GetByCompanyID(ctx, companyID, submissionMode, status, from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
s.logger.Error("Failed to get tender approvals by company ID", map[string]interface{}{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
|
|||||||
Reference in New Issue
Block a user