add document service and acitons
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mediarr/ident"
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id ident.UUID) (*Document, error) {
|
||||
document, err := s.getDocument(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return documentFromDB(*document), nil
|
||||
}
|
||||
|
||||
func (s *Service) ListChildren(ctx context.Context, parentID ident.UUID) ([]Document, error) {
|
||||
if _, err := s.getActiveDocument(ctx, parentID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err := s.db.Queries.ListDocumentChildren(ctx, &parentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
documents := make([]Document, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
documents = append(documents, *documentFromDB(row))
|
||||
}
|
||||
|
||||
return documents, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListLibraries(ctx context.Context) ([]Document, error) {
|
||||
rows, err := s.db.Queries.ListLibraries(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
documents := make([]Document, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
documents = append(documents, *documentFromDB(row))
|
||||
}
|
||||
|
||||
return documents, nil
|
||||
}
|
||||
Reference in New Issue
Block a user