Update API Documentation and Enhance Tender Query Parameters

- Changed references in API documentation from `main.HealthResponse` to `bootstrap.HealthResponse` for consistency.
- Added new query parameters `publication_from` and `publication_to` to the tender listing and recommendation endpoints to allow filtering by publication date.
- Updated the `ListTendersRequest` struct to include optional fields for `from` and `to` timestamps.
- Modified the `TenderRepository` and `TenderService` interfaces to support the new filtering parameters in the tender listing functionality.
- Enhanced the service and handler layers to process the new query parameters, improving the flexibility of tender retrieval.
This commit is contained in:
n.nakhostin
2025-09-02 11:03:38 +03:30
parent cbf45a812d
commit c684a12155
7 changed files with 203 additions and 102 deletions
+2
View File
@@ -19,6 +19,8 @@ type ListTendersRequest struct {
Limit int `json:"limit" valid:"range(1|100)~Limit must be between 1 and 100"`
Offset int `json:"offset" valid:"range(0|999999)~Offset must be non-negative"`
CompanyID *string `json:"company_id,omitempty"` // Optional company ID for match percentage calculation
From *int64 `json:"from,omitempty"`
To *int64 `json:"to,omitempty"`
}
// ListTendersResponse represents the response for listing tenders
+32 -7
View File
@@ -229,6 +229,8 @@ func (h *TenderHandler) ListTenders(c echo.Context) error {
// @Param country_code query string false "Filter by country code"
// @Param min_estimated_value query number false "Minimum estimated value"
// @Param max_estimated_value query number false "Maximum estimated value"
// @Param publication_from query number false "Publication from"
// @Param publication_to query number false "Publication to"
// @Success 200 {object} response.APIResponse{data=map[string]interface{}}
// @Failure 400 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
@@ -270,14 +272,21 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
companyID = &customerCompanyID
}
req := ListTendersRequest{
Criteria: criteria,
Limit: limit,
Offset: offset,
CompanyID: companyID,
from := int64(0)
if fromParam := c.QueryParam("publication_from"); fromParam != "" {
if parsed, err := strconv.ParseInt(fromParam, 10, 64); err == nil {
from = parsed
}
}
result, err := h.service.ListTenders(c.Request().Context(), req)
to := int64(0)
if toParam := c.QueryParam("publication_to"); toParam != "" {
if parsed, err := strconv.ParseInt(toParam, 10, 64); err == nil {
to = parsed
}
}
result, err := h.service.RecommendTenders(c.Request().Context(), companyID, &from, &to, limit, offset)
if err != nil {
return response.InternalServerError(c, "Failed to retrieve tenders")
}
@@ -295,6 +304,8 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
// @Param country_code query string false "Filter by country code"
// @Param min_estimated_value query number false "Minimum estimated value"
// @Param max_estimated_value query number false "Maximum estimated value"
// @Param publication_from query number false "Publication from"
// @Param publication_to query number false "Publication to"
// @Success 200 {object} response.APIResponse{data=map[string]interface{}}
// @Failure 400 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
@@ -336,7 +347,21 @@ func (h *TenderHandler) RecommendTenders(c echo.Context) error {
companyID = &customerCompanyID
}
result, err := h.service.RecommendTenders(c.Request().Context(), companyID, limit, offset)
from := int64(0)
if fromParam := c.QueryParam("publication_from"); fromParam != "" {
if parsed, err := strconv.ParseInt(fromParam, 10, 64); err == nil {
from = parsed
}
}
to := int64(0)
if toParam := c.QueryParam("publication_to"); toParam != "" {
if parsed, err := strconv.ParseInt(toParam, 10, 64); err == nil {
to = parsed
}
}
result, err := h.service.RecommendTenders(c.Request().Context(), companyID, &from, &to, limit, offset)
if err != nil {
return response.InternalServerError(c, "Failed to retrieve tenders")
}
+10 -2
View File
@@ -19,7 +19,7 @@ type TenderRepository interface {
GetByNoticePublicationID(ctx context.Context, noticePublicationID string) (*Tender, error)
Update(ctx context.Context, tender *Tender) error
Delete(ctx context.Context, id string) error
List(ctx context.Context, criteria TenderSearchCriteria, limit, offset int) ([]Tender, int64, error)
List(ctx context.Context, criteria TenderSearchCriteria, limit, offset int, from *int64, to *int64) ([]Tender, int64, error)
// Bulk operations
CreateBatch(ctx context.Context, tenders []Tender) error
@@ -214,7 +214,7 @@ func (r *tenderRepository) Delete(ctx context.Context, id string) error {
}
// List retrieves tenders with pagination and filtering
func (r *tenderRepository) List(ctx context.Context, criteria TenderSearchCriteria, limit, offset int) ([]Tender, int64, error) {
func (r *tenderRepository) List(ctx context.Context, criteria TenderSearchCriteria, limit, offset int, from *int64, to *int64) ([]Tender, int64, error) {
filter := r.buildSearchFilter(criteria)
pagination := mongopkg.Pagination{
@@ -224,6 +224,14 @@ func (r *tenderRepository) List(ctx context.Context, criteria TenderSearchCriter
SortOrder: -1,
}
if from != nil {
filter["publication_date"] = bson.M{"$gte": *from}
}
if to != nil {
filter["publication_date"] = bson.M{"$lte": *to}
}
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
if err != nil {
r.logger.Error("Failed to list tenders", map[string]interface{}{
+6 -4
View File
@@ -17,7 +17,7 @@ type TenderService interface {
UpdateTender(ctx context.Context, req UpdateTenderRequest) (*Tender, error)
DeleteTender(ctx context.Context, id string) error
ListTenders(ctx context.Context, req ListTendersRequest) (*ListTendersResponse, error)
RecommendTenders(ctx context.Context, companyID *string, limit, offset int) (*ListTendersResponse, error)
RecommendTenders(ctx context.Context, companyID *string, from *int64, to *int64, limit, offset int) (*ListTendersResponse, error)
// Maintenance operations
UpdateExpiredTenders(ctx context.Context) error
@@ -136,6 +136,8 @@ func (s *tenderService) ListTenders(ctx context.Context, req ListTendersRequest)
"limit": req.Limit,
"offset": req.Offset,
"company_id": req.CompanyID,
"from": req.From,
"to": req.To,
})
if req.Limit <= 0 {
@@ -145,7 +147,7 @@ func (s *tenderService) ListTenders(ctx context.Context, req ListTendersRequest)
req.Limit = 100
}
tenders, total, err := s.repository.List(ctx, req.Criteria, req.Limit, req.Offset)
tenders, total, err := s.repository.List(ctx, req.Criteria, req.Limit, req.Offset, req.From, req.To)
if err != nil {
s.logger.Error("Failed to list tenders", map[string]interface{}{
"error": err.Error(),
@@ -220,7 +222,7 @@ func (s *tenderService) ListTenders(ctx context.Context, req ListTendersRequest)
}
// ListTenders retrieves tenders with pagination and filtering
func (s *tenderService) RecommendTenders(ctx context.Context, companyID *string, limit, offset int) (*ListTendersResponse, error) {
func (s *tenderService) RecommendTenders(ctx context.Context, companyID *string, from *int64, to *int64, limit, offset int) (*ListTendersResponse, error) {
s.logger.Info("Recommend tenders", map[string]interface{}{
"company_id": companyID,
})
@@ -244,7 +246,7 @@ func (s *tenderService) RecommendTenders(ctx context.Context, companyID *string,
tenders, total, err := s.repository.List(ctx, TenderSearchCriteria{
Status: []TenderStatus{TenderStatusActive},
Classifications: company.Tags.CPVCodes,
}, limit, offset)
}, limit, offset, from, to)
if err != nil {
s.logger.Error("Failed to list tenders", map[string]interface{}{
"error": err.Error(),