8f409e60a8
Error handling * basic
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package documenttext
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/document"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (s *Service) executeExtraction(ctx context.Context, cleanId uuid.UUID) (*document.Location, error) {
|
|
entry, err := s.cfg.GetDBQueries().GetCleanEntry(ctx, database.MustToDBUUID(cleanId))
|
|
if err != nil {
|
|
return nil, err
|
|
} else if entry.Fail.Valid {
|
|
return nil, fmt.Errorf("no valid cleaning")
|
|
}
|
|
|
|
return &document.Location{
|
|
Bucket: *entry.Bucket,
|
|
Key: *entry.Key,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Service) extract(ctx context.Context, cleanId uuid.UUID) error {
|
|
outLocation, err := s.executeExtraction(ctx, cleanId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
version := s.svc.Version.GetVersion()
|
|
|
|
err = s.cfg.GetDBQueries().AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
|
Version: version,
|
|
Bucket: outLocation.Bucket,
|
|
Key: outLocation.Key,
|
|
Cleanentryid: database.MustToDBUUID(cleanId),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|