Enhance Tender Management with Company-Based Matching and API Updates

- Updated the tender service to include company-based matching for tenders, allowing for more relevant results based on company CPV codes.
- Modified the ListTenders endpoint to accept a company ID parameter for calculating match percentages and sorting tenders accordingly.
- Refactored the tender response structure to include match percentage and days until deadline for better client-side handling.
- Updated API documentation to reflect changes in the tender listing functionality and added new endpoints for public tender access.
- Removed deprecated customer-related methods and streamlined customer listing functionality for improved clarity and performance.
This commit is contained in:
n.nakhostin
2025-08-13 19:47:58 +03:30
parent 96c21b8b78
commit 0a23ff985a
13 changed files with 4543 additions and 668 deletions
+36 -20
View File
@@ -154,11 +154,12 @@ func (h *TenderHandler) DeleteTender(c echo.Context) error {
// ListTenders retrieves tenders with pagination and filtering
// @Summary List tenders
// @Description Retrieve tenders with pagination, filtering, and search capabilities
// @Description Retrieve tenders with pagination, filtering, and search capabilities with optional company-based matching
// @Tags Admin-Tenders
// @Produce json
// @Param limit query int false "Number of items per page (default: 20, max: 100)"
// @Param offset query int false "Number of items to skip (default: 0)"
// @Param company_id query string false "Company ID for match percentage calculation and sorting"
// @Param query query string false "Search query for title and description"
// @Param notice_type query string false "Filter by notice type code"
// @Param procurement_type query string false "Filter by procurement type code"
@@ -231,10 +232,17 @@ func (h *TenderHandler) ListTenders(c echo.Context) error {
}
}
// Parse company_id parameter for matching
var companyID *string
if companyIDParam := c.QueryParam("company_id"); companyIDParam != "" {
companyID = &companyIDParam
}
req := ListTendersRequest{
Criteria: criteria,
Limit: limit,
Offset: offset,
Criteria: criteria,
Limit: limit,
Offset: offset,
CompanyID: companyID,
}
result, err := h.service.ListTenders(c.Request().Context(), req)
@@ -242,14 +250,8 @@ func (h *TenderHandler) ListTenders(c echo.Context) error {
return response.InternalServerError(c, "Failed to retrieve tenders")
}
// Convert tenders to response format
tenderResponses := make([]TenderResponse, len(result.Tenders))
for i, tender := range result.Tenders {
tenderResponses[i] = *tender.ToTenderResponse()
}
responseData := map[string]interface{}{
"tenders": tenderResponses,
"tenders": result.Tenders,
"total": result.Total,
"limit": result.Limit,
"offset": result.Offset,
@@ -493,7 +495,7 @@ func (h *TenderHandler) CancelScrapingJob(c echo.Context) error {
// GetPublicTenders retrieves public tenders for mobile app
// @Summary Get public tenders
// @Description Retrieve active tenders for mobile application users
// @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)"
@@ -504,7 +506,7 @@ func (h *TenderHandler) CancelScrapingJob(c echo.Context) error {
// @Success 200 {object} response.APIResponse{data=map[string]interface{}}
// @Failure 400 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
// @Router /tenders [get]
// @Router /api/v1/tenders [get]
func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
// Parse pagination parameters (more restrictive for public API)
limit := 20
@@ -543,10 +545,17 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
}
}
// Get company ID from customer context for automatic matching
var companyID *string
if customerCompanyID, ok := c.Get("company_id").(string); ok && customerCompanyID != "" {
companyID = &customerCompanyID
}
req := ListTendersRequest{
Criteria: criteria,
Limit: limit,
Offset: offset,
Criteria: criteria,
Limit: limit,
Offset: offset,
CompanyID: companyID,
}
result, err := h.service.ListTenders(c.Request().Context(), req)
@@ -557,7 +566,7 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
// Convert tenders to public response format (limited fields)
publicTenders := make([]map[string]interface{}, len(result.Tenders))
for i, tender := range result.Tenders {
publicTenders[i] = map[string]interface{}{
tenderData := map[string]interface{}{
"id": tender.ID,
"title": tender.Title,
"description": tender.Description,
@@ -565,15 +574,22 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
"main_classification": tender.MainClassification,
"estimated_value": tender.EstimatedValue,
"currency": tender.Currency,
"formatted_estimated_value": tender.GetFormattedEstimatedValue(),
"formatted_estimated_value": tender.FormattedEstimatedValue,
"tender_deadline": tender.TenderDeadline,
"country_code": tender.CountryCode,
"city_name": tender.CityName,
"tender_url": tender.TenderURL,
"publication_date": tender.PublicationDate,
"buyer_organization": tender.BuyerOrganization,
"is_expired": tender.IsExpired(),
"is_expired": tender.IsExpired,
}
// Add match percentage if available
if tender.MatchPercentage != nil {
tenderData["match_percentage"] = *tender.MatchPercentage
}
publicTenders[i] = tenderData
}
responseData := map[string]interface{}{
@@ -595,7 +611,7 @@ func (h *TenderHandler) GetPublicTenders(c echo.Context) error {
// @Success 200 {object} response.APIResponse{data=map[string]interface{}}
// @Failure 404 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
// @Router /tenders/{id} [get]
// @Router /api/v1/tenders/{id} [get]
func (h *TenderHandler) GetPublicTenderDetails(c echo.Context) error {
id := c.Param("id")
if id == "" {