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:
+26
-26
@@ -1,8 +1,9 @@
|
||||
package feedback
|
||||
|
||||
import (
|
||||
"time"
|
||||
"tm/pkg/mongo"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// FeedbackType represents the type of feedback
|
||||
@@ -22,31 +23,36 @@ type Feedback struct {
|
||||
FeedbackType FeedbackType `bson:"feedback_type" json:"feedback_type" validate:"required,oneof=like dislike"`
|
||||
}
|
||||
|
||||
// FeedbackSummary represents aggregated feedback statistics for a tender
|
||||
type FeedbackSummary struct {
|
||||
TenderID string `bson:"tender_id" json:"tender_id"`
|
||||
TotalLikes int64 `bson:"total_likes" json:"total_likes"`
|
||||
TotalDislikes int64 `bson:"total_dislikes" json:"total_dislikes"`
|
||||
LastUpdated int64 `bson:"last_updated" json:"last_updated"` // Unix timestamp
|
||||
// SetID sets the feedback ID (implements IDSetter interface)
|
||||
func (f *Feedback) SetID(id string) {
|
||||
f.ID, _ = bson.ObjectIDFromHex(id)
|
||||
}
|
||||
|
||||
// FeedbackSearchCriteria represents search criteria for feedback
|
||||
type FeedbackSearchCriteria struct {
|
||||
TenderID *string `json:"tender_id,omitempty"`
|
||||
CustomerID *string `json:"customer_id,omitempty"`
|
||||
CompanyID *string `json:"company_id,omitempty"`
|
||||
FeedbackType *FeedbackType `json:"feedback_type,omitempty"`
|
||||
DateFrom *int64 `json:"date_from,omitempty"` // Unix timestamp
|
||||
DateTo *int64 `json:"date_to,omitempty"` // Unix timestamp
|
||||
Limit int `json:"limit,omitempty"`
|
||||
Offset int `json:"offset,omitempty"`
|
||||
}
|
||||
|
||||
// GetID returns the feedback ID
|
||||
// GetID returns the feedback ID (implements IDGetter interface)
|
||||
func (f *Feedback) GetID() string {
|
||||
return f.ID.Hex()
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the created timestamp (implements Timestamp interface)
|
||||
func (f *Feedback) SetCreatedAt(timestamp int64) {
|
||||
f.CreatedAt = timestamp
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
|
||||
func (f *Feedback) SetUpdatedAt(timestamp int64) {
|
||||
f.UpdatedAt = timestamp
|
||||
}
|
||||
|
||||
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
|
||||
func (f *Feedback) GetCreatedAt() int64 {
|
||||
return f.CreatedAt
|
||||
}
|
||||
|
||||
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
|
||||
func (f *Feedback) GetUpdatedAt() int64 {
|
||||
return f.UpdatedAt
|
||||
}
|
||||
|
||||
// IsLike returns true if the feedback is a like
|
||||
func (f *Feedback) IsLike() bool {
|
||||
return f.FeedbackType == FeedbackTypeLike
|
||||
@@ -56,9 +62,3 @@ func (f *Feedback) IsLike() bool {
|
||||
func (f *Feedback) IsDislike() bool {
|
||||
return f.FeedbackType == FeedbackTypeDislike
|
||||
}
|
||||
|
||||
// UpdateFeedbackType updates the feedback type and updated timestamp
|
||||
func (f *Feedback) UpdateFeedbackType(feedbackType FeedbackType) {
|
||||
f.FeedbackType = feedbackType
|
||||
f.UpdatedAt = time.Now().Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user