Files
tm_back/internal/feedback/entity.go
T
n.nakhostin 8f909618d8 Refactor Feedback Service to Include Tender Information in Responses
- Updated the FeedbackService to include a new dependency on TenderService, allowing feedback responses to include associated tender details.
- Modified the ListFeedback method to return a new FeedbackListWithTenderResponse type, which includes feedback along with tender information.
- Enhanced the feedback entity and form structures to support the new response format, improving the API's capability to provide comprehensive feedback data.
- Adjusted the main application initialization to reflect the changes in the feedback service dependencies.
2025-09-02 11:31:59 +03:30

65 lines
2.2 KiB
Go

package feedback
import (
"time"
"tm/pkg/mongo"
)
// 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"`
}
// 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()
}