Refactor Tender Handler to Use ListTendersRequest Struct
- Updated the GetPublicTenders handler to utilize a new ListTendersRequest struct for improved clarity and organization of parameters. - Changed the handling of `publication_from` and `publication_to` query parameters to use pointers for optional timestamp values. - Enhanced the service call to ListTenders, aligning with the new request structure and improving the overall code maintainability.
This commit is contained in:
@@ -272,21 +272,29 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
|
|||||||
companyID = &customerCompanyID
|
companyID = &customerCompanyID
|
||||||
}
|
}
|
||||||
|
|
||||||
from := int64(0)
|
var from *int64
|
||||||
if fromParam := c.QueryParam("publication_from"); fromParam != "" {
|
if fromParam := c.QueryParam("publication_from"); fromParam != "" {
|
||||||
if parsed, err := strconv.ParseInt(fromParam, 10, 64); err == nil {
|
if parsed, err := strconv.ParseInt(fromParam, 10, 64); err == nil {
|
||||||
from = parsed
|
from = &parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
to := int64(0)
|
var to *int64
|
||||||
if toParam := c.QueryParam("publication_to"); toParam != "" {
|
if toParam := c.QueryParam("publication_to"); toParam != "" {
|
||||||
if parsed, err := strconv.ParseInt(toParam, 10, 64); err == nil {
|
if parsed, err := strconv.ParseInt(toParam, 10, 64); err == nil {
|
||||||
to = parsed
|
to = &parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.service.RecommendTenders(c.Request().Context(), companyID, &from, &to, limit, offset)
|
req := ListTendersRequest{
|
||||||
|
Criteria: criteria,
|
||||||
|
Limit: limit,
|
||||||
|
Offset: offset,
|
||||||
|
CompanyID: companyID,
|
||||||
|
From: from,
|
||||||
|
To: to,
|
||||||
|
}
|
||||||
|
result, err := h.service.ListTenders(c.Request().Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.InternalServerError(c, "Failed to retrieve tenders")
|
return response.InternalServerError(c, "Failed to retrieve tenders")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user