Enhance Tender entity with PublicationSubmissionDeadline method and corresponding tests
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Added the PublicationSubmissionDeadline method to the Tender entity, which calculates the submission deadline based on the publication date and stored submission deadline. - Updated the IsRecommendable method to utilize the new PublicationSubmissionDeadline logic for determining recommendation eligibility. - Introduced unit tests for the PublicationSubmissionDeadline method, ensuring accurate calculation and validation of submission deadlines. - Enhanced existing tests for the IsRecommendable method to cover new scenarios related to submission deadlines. This update improves the accuracy of submission deadline handling and enhances the recommendation logic for tenders based on publication dates.
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tm/pkg/mongo"
|
||||
"tm/ted"
|
||||
)
|
||||
|
||||
// DocumentSummary represents a summary of a tender document
|
||||
@@ -266,13 +268,27 @@ func (t *Tender) IsExpired() bool {
|
||||
return t.TenderDeadline < now
|
||||
}
|
||||
|
||||
// IsRecommendable reports whether a tender should appear in AI recommendation results.
|
||||
// PublicationSubmissionDeadline returns the submission window end derived from publication_date.
|
||||
// Stored submission_deadline is preferred; otherwise it is calculated as 48 working hours after publication.
|
||||
func (t *Tender) PublicationSubmissionDeadline() int64 {
|
||||
if t.SubmissionDeadline > 0 {
|
||||
return t.SubmissionDeadline
|
||||
}
|
||||
if t.PublicationDate <= 0 {
|
||||
return 0
|
||||
}
|
||||
return ted.CalculateSubmissionDeadline(time.Unix(t.PublicationDate, 0)).Unix()
|
||||
}
|
||||
|
||||
// IsRecommendable reports whether a tender should appear in customer AI recommendation results.
|
||||
// Recommendations use the publication-based submission window, not tender_deadline.
|
||||
func (t *Tender) IsRecommendable(now int64) bool {
|
||||
switch t.Status {
|
||||
case TenderStatusExpired, TenderStatusCancelled, TenderStatusAwarded, TenderStatusClosed:
|
||||
return false
|
||||
}
|
||||
if t.TenderDeadline <= now {
|
||||
deadline := t.PublicationSubmissionDeadline()
|
||||
if deadline <= 0 || deadline <= now {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user