add document service and acitons

This commit is contained in:
venture
2026-11-14 11:37:27 +01:00
parent 9d4f827d38
commit 03da7d9fff
13 changed files with 2177 additions and 5 deletions
+48
View File
@@ -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
}