Add AI procedure reference formatting and parsing functions with unit tests
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced `FormatAIProcedureRef` and `ParseAIProcedureRef` functions in the `tender` domain for handling AI service tender references. - Added unit tests for these functions in `ai_reference_test.go` to ensure correct parsing and formatting behavior. - Updated the `TenderResponse` struct to include a new `ProcedureRef` field for improved data representation. - Enhanced the `GetByProcedureReference` method in the repository to retrieve tenders based on the new procedure reference format. - Modified the `Recommend` method in the service layer to utilize the new procedure reference handling, improving the recommendation process. This update enhances the handling of AI procedure references, ensuring better data integrity and usability in the tender management system.
This commit is contained in:
@@ -21,6 +21,7 @@ type TenderRepository interface {
|
||||
GetByIDs(ctx context.Context, ids []string) ([]Tender, error)
|
||||
GetByContractNoticeID(ctx context.Context, contractNoticeID string) (*Tender, error)
|
||||
GetByNoticePublicationID(ctx context.Context, noticePublicationID string) (*Tender, error)
|
||||
GetByProcedureReference(ctx context.Context, contractFolderID, noticePublicationID string) (*Tender, error)
|
||||
GetByContractFolderID(ctx context.Context, contractFolderID string) (*Tender, error)
|
||||
// GetLatestByContractFolderIDs returns the most recently updated tender per distinct contract_folder_id.
|
||||
GetLatestByContractFolderIDs(ctx context.Context, contractFolderIDs []string) (map[string]*Tender, error)
|
||||
@@ -297,6 +298,41 @@ func (r *tenderRepository) GetByNoticePublicationID(ctx context.Context, noticeP
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// GetByProcedureReference retrieves a tender by contract folder and notice publication id.
|
||||
// Matches canonical notice_publication_id and related_notice_publication_ids.
|
||||
func (r *tenderRepository) GetByProcedureReference(ctx context.Context, contractFolderID, noticePublicationID string) (*Tender, error) {
|
||||
contractFolderID = strings.TrimSpace(contractFolderID)
|
||||
noticePublicationID = strings.TrimSpace(noticePublicationID)
|
||||
if contractFolderID == "" || noticePublicationID == "" {
|
||||
return nil, orm.ErrDocumentNotFound
|
||||
}
|
||||
|
||||
filter := bson.M{
|
||||
"contract_folder_id": contractFolderID,
|
||||
"$or": []bson.M{
|
||||
{"notice_publication_id": noticePublicationID},
|
||||
{"related_notice_publication_ids": noticePublicationID},
|
||||
},
|
||||
}
|
||||
pagination := orm.Pagination{Limit: 1, SortField: "updated_at", SortOrder: -1}
|
||||
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to get tender by procedure reference", map[string]interface{}{
|
||||
"contract_folder_id": contractFolderID,
|
||||
"notice_publication_id": noticePublicationID,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(result.Items) == 0 {
|
||||
return nil, orm.ErrDocumentNotFound
|
||||
}
|
||||
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// GetByContractFolderID retrieves a tender by its procedure-level identifier (ContractFolderID).
|
||||
// TED groups multiple notice publications (e.g. competition notice + result notice) under the same
|
||||
// ContractFolderID, so this lookup is the authoritative way to find the existing tender for a procedure
|
||||
|
||||
Reference in New Issue
Block a user