Implement AI onboarding and recommendation features in company service
- Added new AI onboarding and recommendation endpoints in the company handler for starting onboarding and retrieving ranked tender recommendations. - Introduced `StartAIOnboarding` and `GetAIRecommendations` methods in the company service to handle AI interactions. - Updated the company service constructor to include the AI recommendation client. - Enhanced the AI summarizer client with methods for onboarding and fetching recommendations. - Added response structures for onboarding and recommended tenders in the company form. This update enhances the tender management system by integrating AI capabilities for onboarding and tender recommendations, improving user experience and operational efficiency.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package company
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mime/multipart"
|
||||
|
||||
"tm/internal/user"
|
||||
@@ -53,6 +54,72 @@ func (h *Handler) MyCompany(c echo.Context) error {
|
||||
return response.Success(c, company, "Company retrieved successfully")
|
||||
}
|
||||
|
||||
// StartOnboarding starts AI onboarding for the authenticated customer's company (Mobile App)
|
||||
// @Summary Start AI company onboarding
|
||||
// @Description Send company profile, uploaded documents, and website URL to the AI team to start tender recommendation onboarding
|
||||
// @Tags Company
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.APIResponse{data=OnboardingResponse}
|
||||
// @Failure 401 {object} response.APIResponse "Unauthorized - User not authenticated"
|
||||
// @Failure 404 {object} response.APIResponse "Company not found"
|
||||
// @Failure 503 {object} response.APIResponse "AI recommendation service unavailable"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/onboarding [post]
|
||||
func (h *Handler) StartOnboarding(c echo.Context) error {
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.Unauthorized(c, "User not authenticated")
|
||||
}
|
||||
|
||||
result, err := h.service.StartAIOnboarding(c.Request().Context(), companyID)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrAIRecommendationNotConfigured) {
|
||||
return response.ServiceUnavailable(c, "AI recommendation service is not configured")
|
||||
}
|
||||
if err.Error() == "company not found" {
|
||||
return response.NotFound(c, "Company not found")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to start AI onboarding")
|
||||
}
|
||||
|
||||
return response.Success(c, result, "AI onboarding started successfully")
|
||||
}
|
||||
|
||||
// RecommendTenders returns AI-ranked tender recommendations for the authenticated customer's company (Mobile App)
|
||||
// @Summary Get AI tender recommendations
|
||||
// @Description Retrieve ranked tender recommendations from the AI team for the authenticated customer's company
|
||||
// @Tags Company
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.APIResponse{data=[]RecommendedTenderResponse}
|
||||
// @Failure 401 {object} response.APIResponse "Unauthorized - User not authenticated"
|
||||
// @Failure 404 {object} response.APIResponse "Company not found"
|
||||
// @Failure 503 {object} response.APIResponse "AI recommendation service unavailable"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/recommend [post]
|
||||
func (h *Handler) RecommendTenders(c echo.Context) error {
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.Unauthorized(c, "User not authenticated")
|
||||
}
|
||||
|
||||
result, err := h.service.GetAIRecommendations(c.Request().Context(), companyID)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrAIRecommendationNotConfigured) {
|
||||
return response.ServiceUnavailable(c, "AI recommendation service is not configured")
|
||||
}
|
||||
if err.Error() == "company not found" {
|
||||
return response.NotFound(c, "Company not found")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to retrieve AI recommendations")
|
||||
}
|
||||
|
||||
return response.Success(c, result, "AI recommendations retrieved successfully")
|
||||
}
|
||||
|
||||
// **************************** ADMIN ENDPOINTS ****************************
|
||||
|
||||
// Create creates a new company (Web Panel)
|
||||
|
||||
Reference in New Issue
Block a user