35 lines
847 B
Go
35 lines
847 B
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
)
|
|
|
|
var ErrKnowledgeChunkNotFound = errString("knowledge chunk not found")
|
|
|
|
// ListKnowledgeChunks returns catalog.
|
|
func (s *Service) ListKnowledgeChunks(ctx context.Context) ([]repository.KnowledgeChunkRow, error) {
|
|
items, err := s.Repo.ListKnowledgeChunks(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if items == nil {
|
|
items = []repository.KnowledgeChunkRow{}
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
// GetKnowledgeChunk loads one.
|
|
func (s *Service) GetKnowledgeChunk(ctx context.Context, id uuid.UUID) (*repository.KnowledgeChunkRow, error) {
|
|
row, err := s.Repo.GetKnowledgeChunk(ctx, id)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return nil, ErrKnowledgeChunkNotFound
|
|
}
|
|
return row, err
|
|
}
|