Refactor Feedback Module for Consistency and Clarity
- Updated feedback repository and service methods to use a consistent naming convention, changing `NewTenderRepository` and similar methods to `NewRepository`. - Refactored feedback handler methods to improve clarity by renaming methods such as `ListFeedback` to `Search` and `GetFeedback` to `Get`. - Enhanced feedback response structures to include detailed company and tender information, improving the clarity of feedback data returned to API consumers. - Updated Swagger documentation to reflect changes in feedback response structures and endpoint paths, ensuring accurate representation of the API for consumers.
This commit is contained in:
+43
-85
@@ -1,61 +1,37 @@
|
||||
package feedback
|
||||
|
||||
import (
|
||||
"time"
|
||||
"tm/pkg/response"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
}
|
||||
import "tm/pkg/response"
|
||||
|
||||
// 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"`
|
||||
Tender string `json:"tender_id" validate:"required"`
|
||||
Type 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"`
|
||||
// SearchForm represents search criteria for feedback
|
||||
type SearchForm struct {
|
||||
Tender *string `json:"tender_id,omitempty" valid:"optional"`
|
||||
Customer *string `json:"customer_id,omitempty" valid:"optional"`
|
||||
Company *string `json:"company_id,omitempty" valid:"optional"`
|
||||
Type *FeedbackType `json:"feedback_type,omitempty" valid:"optional,in(like|dislike)"`
|
||||
DateFrom *int64 `json:"date_from,omitempty" valid:"optional"`
|
||||
DateTo *int64 `json:"date_to,omitempty" valid:"optional"`
|
||||
}
|
||||
|
||||
// FeedbackListResponse represents a paginated list of feedback
|
||||
type FeedbackListResponse struct {
|
||||
Feedback []*FeedbackResponse `json:"feedback"`
|
||||
Meta *response.Meta `json:"meta"`
|
||||
}
|
||||
|
||||
// FeedbackListResponse represents a paginated list of feedback
|
||||
type FeedbackListWithTenderResponse struct {
|
||||
Feedback []*FeedbackWithTenderResponse `json:"feedback"`
|
||||
Meta *response.Meta `json:"meta"`
|
||||
}
|
||||
type FeedbackWithTenderResponse struct {
|
||||
ID string `json:"id"`
|
||||
FeedbackType FeedbackType `json:"feedback_type"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
TenderID string `json:"tender_id"`
|
||||
CustomerID *string `json:"customer_id"`
|
||||
CompanyId *string `json:"company_id"`
|
||||
Tender *tenderDetails `json:"tender"`
|
||||
}
|
||||
|
||||
// tenderDetails represents essential tender information for the response
|
||||
type (
|
||||
tenderDetails struct {
|
||||
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_id"`
|
||||
CustomerID *string `json:"customer_id"`
|
||||
CompanyId *string `json:"company_id"`
|
||||
Tender *tenderResponse `json:"tender"`
|
||||
Company *companyResponse `json:"company"`
|
||||
}
|
||||
|
||||
tenderResponse struct {
|
||||
ID string `json:"id"`
|
||||
NoticePublicationID string `json:"notice_publication_id"`
|
||||
PublicationDate int64 `json:"publication_date"`
|
||||
@@ -73,39 +49,23 @@ type (
|
||||
BuyerOrganization *organizationResponse `json:"buyer_organization"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
organizationResponse struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
companyResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
// 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
|
||||
type FeedbackListResponse struct {
|
||||
Feedback []*FeedbackResponse `json:"feedback"`
|
||||
Meta *response.Meta `json:"meta"`
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (f *Feedback) ToResponse(tender *tenderResponse, company *companyResponse) *FeedbackResponse {
|
||||
return &FeedbackResponse{
|
||||
ID: f.ID.Hex(),
|
||||
FeedbackType: f.FeedbackType,
|
||||
@@ -114,18 +74,16 @@ func (f *Feedback) ToResponse() *FeedbackResponse {
|
||||
CompanyId: f.CompanyID,
|
||||
UpdatedAt: f.UpdatedAt,
|
||||
CreatedAt: f.CreatedAt,
|
||||
Tender: tender,
|
||||
Company: company,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Feedback) ToResponseWithTender(tender *tenderDetails) *FeedbackWithTenderResponse {
|
||||
return &FeedbackWithTenderResponse{
|
||||
ID: f.ID.Hex(),
|
||||
FeedbackType: f.FeedbackType,
|
||||
TenderID: f.TenderID,
|
||||
CustomerID: f.CustomerID,
|
||||
CompanyId: f.CompanyID,
|
||||
UpdatedAt: f.UpdatedAt,
|
||||
CreatedAt: f.CreatedAt,
|
||||
Tender: tender,
|
||||
}
|
||||
type StatsResponse struct {
|
||||
CompanyID string `json:"company_id"`
|
||||
Company *companyResponse `json:"company"`
|
||||
TotalLikes int64 `json:"total_likes"`
|
||||
TotalDislikes int64 `json:"total_dislikes"`
|
||||
TotalFeedback int64 `json:"total_feedback"`
|
||||
LastUpdated int64 `json:"last_updated"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user