package collection import ( "context" "tercul/internal/domain" ) // CollectionCommands contains the command handlers for the collection aggregate. type CollectionCommands struct { repo domain.CollectionRepository } // NewCollectionCommands creates a new CollectionCommands handler. func NewCollectionCommands(repo domain.CollectionRepository) *CollectionCommands { return &CollectionCommands{repo: repo} } // CreateCollectionInput represents the input for creating a new collection. type CreateCollectionInput struct { Name string Description string UserID uint IsPublic bool CoverImageURL string } // CreateCollection creates a new collection. func (c *CollectionCommands) CreateCollection(ctx context.Context, input CreateCollectionInput) (*domain.Collection, error) { collection := &domain.Collection{ Name: input.Name, Description: input.Description, UserID: input.UserID, IsPublic: input.IsPublic, CoverImageURL: input.CoverImageURL, } err := c.repo.Create(ctx, collection) if err != nil { return nil, err } return collection, nil } // UpdateCollectionInput represents the input for updating an existing collection. type UpdateCollectionInput struct { ID uint Name string Description string IsPublic bool CoverImageURL string } // UpdateCollection updates an existing collection. func (c *CollectionCommands) UpdateCollection(ctx context.Context, input UpdateCollectionInput) (*domain.Collection, error) { collection, err := c.repo.GetByID(ctx, input.ID) if err != nil { return nil, err } collection.Name = input.Name collection.Description = input.Description collection.IsPublic = input.IsPublic collection.CoverImageURL = input.CoverImageURL err = c.repo.Update(ctx, collection) if err != nil { return nil, err } return collection, nil } // DeleteCollection deletes a collection by ID. func (c *CollectionCommands) DeleteCollection(ctx context.Context, id uint) error { return c.repo.Delete(ctx, id) } // AddWorkToCollectionInput represents the input for adding a work to a collection. type AddWorkToCollectionInput struct { CollectionID uint WorkID uint } // AddWorkToCollection adds a work to a collection. func (c *CollectionCommands) AddWorkToCollection(ctx context.Context, input AddWorkToCollectionInput) error { return c.repo.AddWorkToCollection(ctx, input.CollectionID, input.WorkID) } // RemoveWorkFromCollectionInput represents the input for removing a work from a collection. type RemoveWorkFromCollectionInput struct { CollectionID uint WorkID uint } // RemoveWorkFromCollection removes a work from a collection. func (c *CollectionCommands) RemoveWorkFromCollection(ctx context.Context, input RemoveWorkFromCollectionInput) error { return c.repo.RemoveWorkFromCollection(ctx, input.CollectionID, input.WorkID) }