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.
This commit is contained in:
n.nakhostin
2025-09-02 11:31:59 +03:30
parent c684a12155
commit 8f909618d8
5 changed files with 106 additions and 23 deletions
+39 -10
View File
@@ -2,6 +2,7 @@ package feedback
import (
"context"
"tm/internal/tender"
"tm/pkg/logger"
"tm/pkg/response"
)
@@ -10,7 +11,7 @@ import (
type FeedbackService interface {
ToggleFeedback(ctx context.Context, req ToggleFeedbackForm, customerID *string, companyID *string) (*FeedbackResponse, error)
GetFeedback(ctx context.Context, id string) (*FeedbackResponse, error)
ListFeedback(ctx context.Context, criteria FeedbackSearchCriteria, limit, offset int) (*FeedbackListResponse, error)
ListFeedback(ctx context.Context, criteria FeedbackSearchCriteria, limit, offset int) (*FeedbackListWithTenderResponse, error)
DeleteFeedback(ctx context.Context, id string) error
GetFeedbackByTenderID(ctx context.Context, tenderID, companyID string) (*FeedbackResponse, error)
CompanyFeedbackStats(ctx context.Context, companyID string) (*CompanyFeedbackStatsResponse, error)
@@ -18,15 +19,17 @@ type FeedbackService interface {
// feedbackService implements FeedbackService interface
type feedbackService struct {
feedbackRepo Repository
logger logger.Logger
feedbackRepo Repository
tenderService tender.TenderService
logger logger.Logger
}
// NewFeedbackService creates a new feedback service
func NewFeedbackService(feedbackRepo Repository, logger logger.Logger) FeedbackService {
func NewFeedbackService(feedbackRepo Repository, tenderService tender.TenderService, logger logger.Logger) FeedbackService {
return &feedbackService{
feedbackRepo: feedbackRepo,
logger: logger,
feedbackRepo: feedbackRepo,
tenderService: tenderService,
logger: logger,
}
}
@@ -108,7 +111,7 @@ func (s *feedbackService) GetFeedback(ctx context.Context, id string) (*Feedback
return feedback.ToResponse(), nil
}
func (s *feedbackService) ListFeedback(ctx context.Context, criteria FeedbackSearchCriteria, limit, offset int) (*FeedbackListResponse, error) {
func (s *feedbackService) ListFeedback(ctx context.Context, criteria FeedbackSearchCriteria, limit, offset int) (*FeedbackListWithTenderResponse, error) {
feedbacks, total, err := s.feedbackRepo.List(ctx, criteria, limit, offset)
if err != nil {
s.logger.Error("Failed to list feedback", map[string]interface{}{
@@ -128,11 +131,37 @@ func (s *feedbackService) ListFeedback(ctx context.Context, criteria FeedbackSea
Pages: int((total + int64(limit) - 1) / int64(limit)),
}
result := make([]*FeedbackResponse, len(feedbacks))
result := make([]*FeedbackWithTenderResponse, len(feedbacks))
for i, feedback := range feedbacks {
result[i] = feedback.ToResponse()
tender, err := s.tenderService.GetTenderByID(ctx, feedback.TenderID)
if err != nil {
s.logger.Error("Failed to get tender", map[string]interface{}{
"tender_id": feedback.TenderID,
"error": err.Error(),
})
return nil, err
}
resp := feedback.ToResponseWithTender(&tenderDetails{
ID: tender.ID,
NoticePublicationID: tender.NoticePublicationID,
PublicationDate: tender.PublicationDate,
Title: tender.Title,
Description: tender.Description,
ProcurementTypeCode: tender.ProcurementTypeCode,
ProcedureCode: tender.ProcedureCode,
EstimatedValue: tender.EstimatedValue,
Currency: tender.Currency,
Duration: tender.Duration,
DurationUnit: tender.DurationUnit,
TenderDeadline: tender.TenderDeadline,
SubmissionDeadline: tender.SubmissionDeadline,
CountryCode: tender.CountryCode,
BuyerOrganization: &organizationResponse{Name: tender.BuyerOrganization.Name},
Status: string(tender.Status),
})
result[i] = resp
}
return &FeedbackListResponse{
return &FeedbackListWithTenderResponse{
Feedback: result,
Meta: meta,
}, nil