Add customer feedback statistics endpoint and refactor feedback handling
This commit is contained in:
@@ -195,7 +195,7 @@ func (h *Handler) Toggle(c echo.Context) error {
|
||||
|
||||
// ListFeedback retrieves feedback with pagination and filtering
|
||||
// @Summary List feedback with filters
|
||||
// @Description Retrieve paginated list of feedback with optional filtering by various criteria. This endpoint is for public use and filters results based on the authenticated user's company.
|
||||
// @Description Retrieve paginated list of feedback for the authenticated customer with optional filters.
|
||||
// @Tags Feedback
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -214,16 +214,16 @@ func (h *Handler) Toggle(c echo.Context) error {
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/feedback [get]
|
||||
func (h *Handler) PublicList(c echo.Context) error {
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
customerID, err := customer.GetCustomerIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "Company ID required", "User must be associated with a company")
|
||||
return response.BadRequest(c, "Customer ID required", "User must be associated with a customer")
|
||||
}
|
||||
|
||||
form, err := response.Parse[SearchForm](c)
|
||||
if err != nil {
|
||||
return response.ValidationError(c, "Invalid request data", err.Error())
|
||||
}
|
||||
form.Company = &companyID
|
||||
form.Customer = &customerID
|
||||
|
||||
pagination, err := response.NewPagination(c)
|
||||
if err != nil {
|
||||
@@ -287,12 +287,12 @@ func (h *Handler) PublicGetByTenderID(c echo.Context) error {
|
||||
return response.BadRequest(c, "Tender ID is required", "Tender ID parameter is missing")
|
||||
}
|
||||
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
customerID, err := customer.GetCustomerIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "Company ID required", "User must be associated with a company")
|
||||
return response.BadRequest(c, "Customer ID required", "User must be associated with a customer")
|
||||
}
|
||||
|
||||
feedback, err := h.service.GetByTenderID(c.Request().Context(), tenderID, companyID)
|
||||
feedback, err := h.service.GetByTenderIDForCustomer(c.Request().Context(), tenderID, customerID)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "Failed to get feedback", "")
|
||||
}
|
||||
@@ -300,28 +300,44 @@ func (h *Handler) PublicGetByTenderID(c echo.Context) error {
|
||||
return response.Success(c, feedback, "Feedback retrieved successfully")
|
||||
}
|
||||
|
||||
// GetCompanyFeedbackStats retrieves feedback statistics for the authenticated user's company
|
||||
// @Summary Get company feedback statistics
|
||||
// @Description Retrieve comprehensive feedback statistics for the authenticated user's company including total likes, dislikes, and percentage calculations.
|
||||
// GetCustomerStats retrieves feedback statistics for the authenticated customer.
|
||||
// @Summary Get customer feedback statistics
|
||||
// @Description Retrieve feedback statistics (likes, dislikes, totals) for the authenticated customer only.
|
||||
// @Tags Feedback
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.APIResponse{data=StatsResponse} "Company feedback statistics retrieved successfully"
|
||||
// @Failure 400 {object} response.APIResponse{error=string,message=string} "Bad request - Missing company association"
|
||||
// @Success 200 {object} response.APIResponse{data=CustomerStatsResponse} "Customer feedback statistics retrieved successfully"
|
||||
// @Failure 400 {object} response.APIResponse{error=string,message=string} "Bad request - Missing customer association"
|
||||
// @Failure 401 {object} response.APIResponse{error=string,message=string} "Unauthorized - User not authenticated"
|
||||
// @Failure 500 {object} response.APIResponse{error=string,message=string} "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/feedback/stats/customer [get]
|
||||
func (h *Handler) GetCustomerStats(c echo.Context) error {
|
||||
customerID, err := customer.GetCustomerIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "Customer ID required", "User must be associated with a customer")
|
||||
}
|
||||
|
||||
stats, err := h.service.CustomerStats(c.Request().Context(), customerID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to retrieve customer stats")
|
||||
}
|
||||
|
||||
return response.Success(c, stats, "Customer stats retrieved successfully")
|
||||
}
|
||||
|
||||
// GetCompanyStats returns customer-scoped stats for backward compatibility with clients using /stats/company.
|
||||
// @Summary Get feedback statistics (customer-scoped, legacy path)
|
||||
// @Description Same as GET /feedback/stats/customer. Prefer /stats/customer for new integrations.
|
||||
// @Tags Feedback
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.APIResponse{data=CustomerStatsResponse} "Customer feedback statistics retrieved successfully"
|
||||
// @Failure 400 {object} response.APIResponse{error=string,message=string} "Bad request - Missing customer association"
|
||||
// @Failure 401 {object} response.APIResponse{error=string,message=string} "Unauthorized - User not authenticated"
|
||||
// @Failure 500 {object} response.APIResponse{error=string,message=string} "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/feedback/stats/company [get]
|
||||
func (h *Handler) GetCompanyStats(c echo.Context) error {
|
||||
companyID, err := user.GetCompanyIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "Company ID required", "User must be associated with a company")
|
||||
}
|
||||
|
||||
stats, err := h.service.CompanyStats(c.Request().Context(), companyID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to retrieve company stats")
|
||||
}
|
||||
|
||||
return response.Success(c, stats, "Company stats retrieved successfully")
|
||||
return h.GetCustomerStats(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user