71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
package services
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"nearle/models"
|
|
"nearle/repositories"
|
|
)
|
|
|
|
// CatalogueUploadService keeps the record of what was sent to the ingest
|
|
// service, for which shop, and what became of it.
|
|
//
|
|
// Deliberately thin. There is no business rule here yet and inventing one would
|
|
// be the wrong move: the ingest service is the authority on a drop's progress,
|
|
// and Fiesta's job is to remember the id long enough for somebody to ask it.
|
|
//
|
|
// In particular this service does NOT call the ingest service itself. It could,
|
|
// and it should not: their host is a single CPU-bound container that spends
|
|
// minutes per batch on image search, and pointing a Go backend's retry loop at
|
|
// it would turn our uptime into theirs. The browser already polls anonymously —
|
|
// the batch id is the credential — so the reading happens where the person
|
|
// waiting for it is, and Fiesta stores what that reading found.
|
|
type CatalogueUploadService interface {
|
|
Record(upload *models.CatalogueUpload) error
|
|
List(tenantID, locationID, pageNo, pageSize int) ([]models.CatalogueUpload, error)
|
|
UpdateStatus(upload *models.CatalogueUpload) error
|
|
MarkShelved(batchID string, shelved, skipped int) error
|
|
AttachSheet(batchID, sheetRows string) error
|
|
}
|
|
|
|
type catalogueUploadService struct {
|
|
repo repositories.CatalogueUploadRepository
|
|
}
|
|
|
|
func NewCatalogueUploadService(repo repositories.CatalogueUploadRepository) CatalogueUploadService {
|
|
return &catalogueUploadService{repo: repo}
|
|
}
|
|
|
|
func (s *catalogueUploadService) Record(upload *models.CatalogueUpload) error {
|
|
if upload.Laststatus == "" {
|
|
// The service's own first answer for an accepted drop. Not "queued":
|
|
// nothing runs on arrival, and a receipt that said queued would claim
|
|
// the pipeline had it when it is in fact waiting for a person.
|
|
upload.Laststatus = "pending"
|
|
}
|
|
if strings.TrimSpace(upload.Sheetrows) == "" {
|
|
// `sheetrows` is jsonb, and Postgres rejects an empty string for it —
|
|
// "invalid input syntax for type json" — which would fail the whole
|
|
// receipt over a field nobody supplied. An empty ARRAY is the honest
|
|
// value: no rows were sent, so there is nothing to shelve from later.
|
|
upload.Sheetrows = "[]"
|
|
}
|
|
return s.repo.Record(upload)
|
|
}
|
|
|
|
func (s *catalogueUploadService) List(tenantID, locationID, pageNo, pageSize int) ([]models.CatalogueUpload, error) {
|
|
return s.repo.List(tenantID, locationID, pageNo, pageSize)
|
|
}
|
|
|
|
func (s *catalogueUploadService) UpdateStatus(upload *models.CatalogueUpload) error {
|
|
return s.repo.UpdateStatus(upload)
|
|
}
|
|
|
|
func (s *catalogueUploadService) MarkShelved(batchID string, shelved, skipped int) error {
|
|
return s.repo.MarkShelved(batchID, shelved, skipped)
|
|
}
|
|
|
|
func (s *catalogueUploadService) AttachSheet(batchID, sheetRows string) error {
|
|
return s.repo.AttachSheet(batchID, sheetRows)
|
|
}
|