Files
tm_back/internal/feedback/form.go
T
n.nakhostin 0e14a11daf Add Company Feedback Statistics Endpoint and Update API Documentation
- Introduced a new endpoint to retrieve comprehensive feedback statistics for the authenticated user's company, including total likes, dislikes, and percentage calculations.
- Implemented the GetCompanyFeedbackStats method in the feedback handler to handle requests, ensuring proper authentication and error handling.
- Updated Swagger JSON, YAML, and Go documentation to accurately reflect the new endpoint, including detailed descriptions, parameters, and response formats for the CompanyFeedbackStatsResponse.
- Enhanced the feedback repository and service layers to support the new statistics functionality, improving the overall data handling capabilities of the tender management system.
- These changes enhance the usability and functionality of the API, providing valuable insights into company feedback statistics.
2025-08-25 13:39:35 +03:30

71 lines
2.2 KiB
Go

package feedback
import (
"time"
)
// ListFeedbackForm represents the form for listing feedback
type ListFeedbackForm struct {
Feedbacks []FeedbackResponse `json:"feedbacks"`
DateFrom *int64 `json:"date_from,omitempty" validate:"omitempty,min=0"`
DateTo *int64 `json:"date_to,omitempty" validate:"omitempty,min=0"`
Limit int `json:"limit" validate:"required,min=1,max=100"`
Offset int `json:"offset" validate:"required,min=0"`
}
// ToggleFeedbackForm represents the form for toggling feedback (like/dislike)
type ToggleFeedbackForm struct {
TenderID string `json:"tender_id" validate:"required"`
FeedbackType FeedbackType `json:"feedback_type" validate:"required,oneof=like dislike"`
}
// FeedbackResponse represents the response for feedback operations
type FeedbackResponse struct {
ID string `json:"id"`
FeedbackType FeedbackType `json:"feedback_type"`
UpdatedAt int64 `json:"updated_at"`
CreatedAt int64 `json:"created_at"`
TenderID string `json:"tender"`
CustomerID *string `json:"customer_id"`
CompanyId *string `json:"company_id"`
}
// CompanyFeedbackStatsResponse represents the response for company feedback statistics
type CompanyFeedbackStatsResponse struct {
CompanyID string `json:"company_id"`
TotalLikes int64 `json:"total_likes"`
TotalDislikes int64 `json:"total_dislikes"`
TotalFeedback int64 `json:"total_feedback"`
LastUpdated int64 `json:"last_updated"` // Unix timestamp
}
// GetDateFromTime returns the date_from as time.Time
func (f *ListFeedbackForm) GetDateFromTime() *time.Time {
if f.DateFrom == nil {
return nil
}
t := time.Unix(*f.DateFrom, 0)
return &t
}
// GetDateToTime returns the date_to as time.Time
func (f *ListFeedbackForm) GetDateToTime() *time.Time {
if f.DateTo == nil {
return nil
}
t := time.Unix(*f.DateTo, 0)
return &t
}
func (f *Feedback) ToResponse() *FeedbackResponse {
return &FeedbackResponse{
ID: f.ID.Hex(),
FeedbackType: f.FeedbackType,
TenderID: f.TenderID,
CustomerID: f.CustomerID,
CompanyId: f.CompanyID,
UpdatedAt: f.UpdatedAt,
CreatedAt: f.CreatedAt,
}
}