Enhance tender and company context handling with new features and error management
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced `PickAssignedCompanyID` function to determine the appropriate company ID for company-scoped operations, improving company assignment logic. - Added `ResolveMongoID` method in the tender service to map MongoDB IDs and AI procedure references to canonical tender IDs, enhancing ID resolution. - Updated `ToggleTenderApproval` to handle company ID validation and improve error handling, ensuring robust processing of tender approvals. - Enhanced logging for error scenarios in the tender approval service, providing better insights into failures during operations. - Refactored the `GetByID` and `GetByTenderAndCompany` methods in the tender approval repository to utilize custom error types for improved clarity. This update significantly improves the handling of company and tender operations, enhancing error management and overall service reliability.
This commit is contained in:
@@ -249,12 +249,19 @@ func (r *tenderRepository) GetByIDs(ctx context.Context, ids []string) ([]Tender
|
||||
|
||||
objectIDs := make([]bson.ObjectID, 0, len(batch))
|
||||
for _, id := range batch {
|
||||
objectID, err := bson.ObjectIDFromHex(id)
|
||||
objectID, err := bson.ObjectIDFromHex(strings.TrimSpace(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
r.logger.Warn("Skipping invalid tender ID in batch lookup", map[string]interface{}{
|
||||
"tender_id": id,
|
||||
"error": err.Error(),
|
||||
})
|
||||
continue
|
||||
}
|
||||
objectIDs = append(objectIDs, objectID)
|
||||
}
|
||||
if len(objectIDs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
pagination := orm.Pagination{
|
||||
Limit: len(objectIDs),
|
||||
|
||||
@@ -55,6 +55,8 @@ type Service interface {
|
||||
// Tender operations
|
||||
GetByID(ctx context.Context, id string, language string) (*TenderResponse, error)
|
||||
GetByIDs(ctx context.Context, ids []string) (map[string]*TenderResponse, error)
|
||||
// ResolveMongoID maps a MongoDB id or AI procedure ref to the canonical tender MongoDB id.
|
||||
ResolveMongoID(ctx context.Context, tenderRef string) (string, error)
|
||||
Update(ctx context.Context, req UpdateTenderRequest) (*TenderResponse, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
Search(ctx context.Context, req *SearchForm, pagination *response.Pagination) (*SearchResponse, error)
|
||||
@@ -181,6 +183,35 @@ func (s *tenderService) GetByIDs(ctx context.Context, ids []string) (map[string]
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ResolveMongoID maps a MongoDB id or AI procedure ref (PROC_{folder}/{notice}) to the canonical tender id.
|
||||
func (s *tenderService) ResolveMongoID(ctx context.Context, tenderRef string) (string, error) {
|
||||
tenderRef = strings.TrimSpace(tenderRef)
|
||||
if tenderRef == "" {
|
||||
return "", fmt.Errorf("tender reference is required")
|
||||
}
|
||||
|
||||
if IsMongoObjectIDRef(tenderRef) {
|
||||
if _, err := s.repository.GetByID(ctx, tenderRef); err != nil {
|
||||
return "", fmt.Errorf("tender not found")
|
||||
}
|
||||
return tenderRef, nil
|
||||
}
|
||||
|
||||
if folder, notice, ok := ParseAIProcedureRef(tenderRef); ok {
|
||||
t, err := s.repository.GetByProcedureReference(ctx, folder, notice)
|
||||
if err != nil || t == nil {
|
||||
return "", fmt.Errorf("tender not found")
|
||||
}
|
||||
return t.GetID(), nil
|
||||
}
|
||||
|
||||
if _, err := s.repository.GetByID(ctx, tenderRef); err == nil {
|
||||
return tenderRef, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("tender not found")
|
||||
}
|
||||
|
||||
// buildDetailResponse maps a tender to API form and enriches translation (MinIO) and summary.
|
||||
func (s *tenderService) buildDetailResponse(ctx context.Context, tender *Tender, language string) *TenderResponse {
|
||||
resp := tender.ToResponseWithLanguage("")
|
||||
|
||||
Reference in New Issue
Block a user