Implement Feedback Management System with CRUD Operations and API Enhancements
- Introduced a new feedback management system, including the creation of feedback entities, services, and repositories. - Implemented CRUD operations for feedback, allowing users to submit likes and dislikes on tenders. - Developed administrative endpoints for listing and retrieving feedback with comprehensive filtering options. - Enhanced public API to allow users to view feedback related to tenders. - Updated Swagger documentation to reflect new feedback endpoints and their functionalities. - Removed obsolete configuration file `config.yaml` as part of the transition to a modular configuration system. - Ensured adherence to Clean Architecture principles throughout the implementation.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package feedback
|
||||
|
||||
import (
|
||||
"time"
|
||||
"tm/pkg/mongo"
|
||||
"tm/pkg/response"
|
||||
)
|
||||
|
||||
// FeedbackType represents the type of feedback
|
||||
type FeedbackType string
|
||||
|
||||
const (
|
||||
FeedbackTypeLike FeedbackType = "like"
|
||||
FeedbackTypeDislike FeedbackType = "dislike"
|
||||
)
|
||||
|
||||
// Feedback represents feedback given to a tender by a user
|
||||
type Feedback struct {
|
||||
mongo.Model `bson:",inline"`
|
||||
TenderID string `bson:"tender_id" json:"tender_id" validate:"required"`
|
||||
CustomerID *string `bson:"customer_id,omitempty" json:"customer_id,omitempty"`
|
||||
CompanyID *string `bson:"company_id,omitempty" json:"company_id,omitempty"`
|
||||
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
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// FeedbackListResponse represents a paginated list of feedback
|
||||
type FeedbackListResponse struct {
|
||||
Feedback []*FeedbackResponse `json:"feedback"`
|
||||
Meta *response.Meta `json:"meta"`
|
||||
}
|
||||
|
||||
// GetID returns the feedback ID
|
||||
func (f *Feedback) GetID() string {
|
||||
return f.ID.Hex()
|
||||
}
|
||||
|
||||
// IsLike returns true if the feedback is a like
|
||||
func (f *Feedback) IsLike() bool {
|
||||
return f.FeedbackType == FeedbackTypeLike
|
||||
}
|
||||
|
||||
// IsDislike returns true if the feedback is a dislike
|
||||
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