Files
tm_back/internal/tender/ai_reference.go
T
Mazyar fa258020f1
continuous-integration/drone/push Build is passing
Add AI procedure reference formatting and parsing functions with unit tests
- 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.
2026-06-21 15:36:36 +03:30

57 lines
1.6 KiB
Go

package tender
import (
"strings"
"go.mongodb.org/mongo-driver/v2/bson"
)
const aiProcedurePrefix = "PROC_"
// FormatAIProcedureRef builds the AI service tender reference:
// PROC_{contract_folder_id}/{notice_publication_id}
func FormatAIProcedureRef(contractFolderID, noticePublicationID string) string {
contractFolderID = strings.TrimSpace(contractFolderID)
noticePublicationID = strings.TrimSpace(noticePublicationID)
if contractFolderID == "" || noticePublicationID == "" {
return ""
}
return aiProcedurePrefix + contractFolderID + "/" + noticePublicationID
}
// ParseAIProcedureRef parses PROC_{contract_folder_id}/{notice_publication_id}.
func ParseAIProcedureRef(ref string) (contractFolderID, noticePublicationID string, ok bool) {
ref = strings.TrimSpace(ref)
if ref == "" {
return "", "", false
}
withoutPrefix := ref
if len(ref) >= len(aiProcedurePrefix) && strings.EqualFold(ref[:len(aiProcedurePrefix)], aiProcedurePrefix) {
withoutPrefix = ref[len(aiProcedurePrefix):]
}
slash := strings.Index(withoutPrefix, "/")
if slash <= 0 || slash >= len(withoutPrefix)-1 {
return "", "", false
}
contractFolderID = strings.TrimSpace(withoutPrefix[:slash])
noticePublicationID = strings.TrimSpace(withoutPrefix[slash+1:])
if contractFolderID == "" || noticePublicationID == "" {
return "", "", false
}
return contractFolderID, noticePublicationID, true
}
// IsMongoObjectIDRef reports whether ref is a 24-char hex MongoDB ObjectId.
func IsMongoObjectIDRef(ref string) bool {
ref = strings.TrimSpace(ref)
if len(ref) != 24 {
return false
}
_, err := bson.ObjectIDFromHex(ref)
return err == nil
}