Add GetScrapePortals endpoint and related service functionality
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced the GetScrapePortals method in the AI pipeline handler to list document scraping portals supported by the Opplens AI service. - Updated the service layer to include GetScrapePortals, which retrieves the portals from the client and handles errors appropriately. - Enhanced the routes to register the new endpoint for retrieving scrape portals. - Added a new error type for invalid date ranges in the document scraper, improving validation and error handling. This update expands the AI pipeline capabilities, allowing for better management of document scraping portals within the tender management system.
This commit is contained in:
@@ -23,7 +23,7 @@ func isDocumentScraperCountry(countryCode string) bool {
|
||||
// Service defines business logic for the document scraper API
|
||||
type Service interface {
|
||||
// ListPendingTenders retrieves tenders that need document scraping
|
||||
ListPendingTenders(ctx context.Context, limit, offset int) (*DocumentScraperListResponse, *response.Meta, error)
|
||||
ListPendingTenders(ctx context.Context, req DocumentScraperListRequest) (*DocumentScraperListResponse, *response.Meta, error)
|
||||
// GetTenderByNoticeID retrieves a specific tender by its notice publication ID
|
||||
GetTenderByNoticeID(ctx context.Context, noticeID string) (*DocumentScraperTenderResponse, error)
|
||||
}
|
||||
@@ -42,16 +42,36 @@ func NewService(tenderRepo tender.TenderRepository, logger logger.Logger) Servic
|
||||
}
|
||||
|
||||
// ListPendingTenders retrieves tenders that have not yet been scraped for documents.
|
||||
// Only returns tenders from Sweden, Finland, and Norway with active deadlines (deadline not yet reached).
|
||||
func (s *service) ListPendingTenders(ctx context.Context, limit, offset int) (*DocumentScraperListResponse, *response.Meta, error) {
|
||||
// Only returns tenders from Sweden, Finland, and Norway. By default only tenders with active
|
||||
// deadlines are included; set IncludeExpired to include tenders whose deadline has passed.
|
||||
func (s *service) ListPendingTenders(ctx context.Context, req DocumentScraperListRequest) (*DocumentScraperListResponse, *response.Meta, error) {
|
||||
req.Normalize()
|
||||
|
||||
if req.CreatedAtFrom != nil && req.CreatedAtTo != nil && *req.CreatedAtFrom > *req.CreatedAtTo {
|
||||
return nil, nil, ErrInvalidDateRange
|
||||
}
|
||||
|
||||
s.logger.Info("Listing pending tenders for document scraper", map[string]interface{}{
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
"limit": req.Limit,
|
||||
"offset": req.Offset,
|
||||
"created_at_from": req.CreatedAtFrom,
|
||||
"created_at_to": req.CreatedAtTo,
|
||||
"include_expired": req.IncludeExpired,
|
||||
})
|
||||
|
||||
now := time.Now().Unix()
|
||||
filter := tender.PendingDocumentScrapeFilter{
|
||||
CountryCodes: documentScraperCountryCodes,
|
||||
CreatedAtFrom: req.CreatedAtFrom,
|
||||
CreatedAtTo: req.CreatedAtTo,
|
||||
Limit: req.Limit,
|
||||
Skip: req.Offset,
|
||||
}
|
||||
if !req.IncludeExpired {
|
||||
now := time.Now().Unix()
|
||||
filter.MinDeadline = &now
|
||||
}
|
||||
|
||||
tenders, hasMore, err := s.tenderRepo.GetPendingDocumentScrapeTenders(ctx, documentScraperCountryCodes, now, limit, offset)
|
||||
tenders, hasMore, err := s.tenderRepo.GetPendingDocumentScrapeTenders(ctx, filter)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to list pending tenders", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -69,12 +89,12 @@ func (s *service) ListPendingTenders(ctx context.Context, limit, offset int) (*D
|
||||
|
||||
meta := &response.Meta{
|
||||
Total: len(tenders),
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Limit: req.Limit,
|
||||
Offset: req.Offset,
|
||||
HasMore: hasMore,
|
||||
}
|
||||
if meta.Limit > 0 {
|
||||
meta.Page = (offset / meta.Limit) + 1
|
||||
meta.Page = (req.Offset / meta.Limit) + 1
|
||||
}
|
||||
|
||||
s.logger.Info("Pending tenders retrieved successfully", map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user