Enhance Tender API with New Recommendation Endpoint and Route Updates
- Updated the tender API to include a new endpoint for recommending public tenders based on company profiles, enhancing user experience for mobile application users. - Modified existing routes to reflect the new structure, changing the tender details route and adding a dedicated recommendation route. - Improved Swagger documentation to accurately represent the new endpoint, including detailed descriptions, parameters, and response formats. - Ensured adherence to Clean Architecture principles by maintaining clear separation of concerns in the service and handler layers.
This commit is contained in:
@@ -285,6 +285,65 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
|
||||
return response.Success(c, result, "Tenders retrieved successfully")
|
||||
}
|
||||
|
||||
// GetPublicTenders retrieves public tenders for mobile app
|
||||
// @Summary Get public tenders
|
||||
// @Description Retrieve active tenders for mobile application users with automatic company-based matching from customer profile
|
||||
// @Tags Tenders
|
||||
// @Produce json
|
||||
// @Param limit query int false "Number of items per page (default: 20, max: 50)"
|
||||
// @Param offset query int false "Number of items to skip (default: 0)"
|
||||
// @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"
|
||||
// @Success 200 {object} response.APIResponse{data=map[string]interface{}}
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/tenders/recommend [get]
|
||||
func (h *TenderHandler) RecommendTenders(c echo.Context) error {
|
||||
// Parse pagination parameters (more restrictive for public API)
|
||||
limit := 20
|
||||
if parsed, err := strconv.Atoi(c.QueryParam("limit")); err == nil && parsed > 0 && parsed <= 50 {
|
||||
limit = parsed
|
||||
}
|
||||
|
||||
offset := 0
|
||||
if parsed, err := strconv.Atoi(c.QueryParam("offset")); err == nil && parsed >= 0 {
|
||||
offset = parsed
|
||||
}
|
||||
|
||||
// Build search criteria for public API (only active tenders)
|
||||
criteria := TenderSearchCriteria{
|
||||
Status: []TenderStatus{TenderStatusActive},
|
||||
}
|
||||
|
||||
if countryCode := c.QueryParam("country_code"); countryCode != "" {
|
||||
criteria.CountryCodes = []string{countryCode}
|
||||
}
|
||||
|
||||
// Parse numeric parameters
|
||||
if parsed, err := strconv.ParseFloat(c.QueryParam("min_estimated_value"), 64); err == nil {
|
||||
criteria.MinEstimatedValue = &parsed
|
||||
}
|
||||
|
||||
if parsed, err := strconv.ParseFloat(c.QueryParam("max_estimated_value"), 64); err == nil {
|
||||
criteria.MaxEstimatedValue = &parsed
|
||||
}
|
||||
|
||||
// Get company ID from customer context for automatic matching
|
||||
var companyID *string
|
||||
if customerCompanyID, ok := c.Get("company_id").(string); ok {
|
||||
companyID = &customerCompanyID
|
||||
}
|
||||
|
||||
result, err := h.service.RecommendTenders(c.Request().Context(), companyID, limit, offset)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to retrieve tenders")
|
||||
}
|
||||
|
||||
return response.Success(c, result, "Tenders retrieved successfully")
|
||||
}
|
||||
|
||||
// GetPublicTenderDetails retrieves public tender details for mobile app
|
||||
// @Summary Get public tender details
|
||||
// @Description Retrieve detailed information about a specific tender for mobile application users
|
||||
@@ -295,7 +354,7 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
|
||||
// @Failure 404 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/tenders/{id} [get]
|
||||
// @Router /api/v1/tenders/details/{id} [get]
|
||||
func (h *TenderHandler) GetPublicTenderDetails(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
|
||||
Reference in New Issue
Block a user