Merged in feature/batch-status (pull request #215)
Implement and test the batch status feature * working
This commit is contained in:
@@ -26,15 +26,39 @@ type Create struct {
|
||||
FolderID *uuid.UUID // Optional folder ID if folder hierarchy was pre-created
|
||||
}
|
||||
|
||||
func (s *Service) Create(ctx context.Context, doc *Create) (uuid.UUID, error) {
|
||||
// CreateResult contains the result of document creation.
|
||||
//
|
||||
// Fields:
|
||||
// - ID: the document's UUID (new or existing)
|
||||
// - IsDuplicate: true if a document with the same hash already existed
|
||||
// - BatchID: the batch this document belongs to (nil for non-batch uploads)
|
||||
// - Filename: the original filename (nil for non-batch uploads)
|
||||
type CreateResult struct {
|
||||
ID uuid.UUID
|
||||
IsDuplicate bool
|
||||
BatchID *uuid.UUID
|
||||
Filename *string
|
||||
}
|
||||
|
||||
// Create processes a new document upload by checking for duplicates, creating
|
||||
// database records, and forwarding new documents to the sync queue.
|
||||
//
|
||||
// Parameters:
|
||||
// - ctx: request context
|
||||
// - doc: document creation parameters (bucket, key, hash, filename, etc.)
|
||||
//
|
||||
// Returns:
|
||||
// - *CreateResult: result containing document ID, duplicate status, and batch info
|
||||
// - error: if any infrastructure operation (DB, S3, queue) fails
|
||||
func (s *Service) Create(ctx context.Context, doc *Create) (*CreateResult, error) {
|
||||
params, err := s.getCreateParams(ctx, doc)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := s.submitCreate(ctx, params)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if params.ID == nil {
|
||||
@@ -45,11 +69,16 @@ func (s *Service) Create(ctx context.Context, doc *Create) (uuid.UUID, error) {
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return id, nil
|
||||
return &CreateResult{
|
||||
ID: id,
|
||||
IsDuplicate: params.ID != nil,
|
||||
BatchID: doc.Key.BatchID,
|
||||
Filename: doc.Filename,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type createDocumentParams struct {
|
||||
|
||||
Reference in New Issue
Block a user