Files
tm_back/internal/feedback/entity.go
T
n.nakhostin a8ef631e43 Add Feedback Retrieval Endpoint for Tender ID
- Introduced a new API endpoint to retrieve feedback details by tender ID, enhancing the feedback management system for public users.
- Updated Swagger documentation to accurately reflect the new endpoint, including detailed descriptions, parameters, and response formats.
- Implemented necessary service and repository methods to support the new functionality, ensuring adherence to Clean Architecture principles.
- Modified existing routes to include the new feedback retrieval functionality, maintaining a clear separation of concerns in the handler layer.
- Enhanced feedback types to include 'unlike' and 'undislike' options for better user interaction.
2025-08-17 13:29:44 +03:30

74 lines
2.5 KiB
Go

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"
FeedbackTypeUnLike FeedbackType = "unlike"
FeedbackTypeUnDislike FeedbackType = "undislike"
)
// 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()
}