66 "errors"
77 "fmt"
88
9- "github.com/google/uuid"
109 "github.com/jackc/pgx/v5"
10+ "github.com/knoguchi/rag/internal/ids"
1111 "github.com/knoguchi/rag/internal/repository"
1212)
1313
@@ -43,7 +43,7 @@ func (r *DocumentRepo) Create(ctx context.Context, doc *repository.Document) err
4343}
4444
4545// GetByID retrieves a document by ID, scoped to a tenant
46- func (r * DocumentRepo ) GetByID (ctx context.Context , tenantID , id uuid. UUID ) (* repository.Document , error ) {
46+ func (r * DocumentRepo ) GetByID (ctx context.Context , tenantID , id ids. ID ) (* repository.Document , error ) {
4747 query := `
4848 SELECT id, tenant_id, source, title, content_hash, chunk_count, status, error_message, metadata, created_at, updated_at
4949 FROM documents
@@ -53,7 +53,7 @@ func (r *DocumentRepo) GetByID(ctx context.Context, tenantID, id uuid.UUID) (*re
5353}
5454
5555// GetByHash retrieves a document by content hash for a tenant
56- func (r * DocumentRepo ) GetByHash (ctx context.Context , tenantID uuid. UUID , hash string ) (* repository.Document , error ) {
56+ func (r * DocumentRepo ) GetByHash (ctx context.Context , tenantID ids. ID , hash string ) (* repository.Document , error ) {
5757 query := `
5858 SELECT id, tenant_id, source, title, content_hash, chunk_count, status, error_message, metadata, created_at, updated_at
5959 FROM documents
@@ -63,7 +63,7 @@ func (r *DocumentRepo) GetByHash(ctx context.Context, tenantID uuid.UUID, hash s
6363}
6464
6565// ListBySource returns all documents for a tenant with the given source
66- func (r * DocumentRepo ) ListBySource (ctx context.Context , tenantID uuid. UUID , source string ) ([]* repository.Document , error ) {
66+ func (r * DocumentRepo ) ListBySource (ctx context.Context , tenantID ids. ID , source string ) ([]* repository.Document , error ) {
6767 query := `
6868 SELECT id, tenant_id, source, title, content_hash, chunk_count, status, error_message, metadata, created_at, updated_at
6969 FROM documents
@@ -119,7 +119,7 @@ func (r *DocumentRepo) scanDocument(ctx context.Context, query string, args ...a
119119}
120120
121121// List retrieves documents for a tenant with pagination
122- func (r * DocumentRepo ) List (ctx context.Context , tenantID uuid. UUID , status string , limit , offset int ) ([]* repository.Document , int , error ) {
122+ func (r * DocumentRepo ) List (ctx context.Context , tenantID ids. ID , status string , limit , offset int ) ([]* repository.Document , int , error ) {
123123 // Build query with optional status filter
124124 countQuery := `SELECT COUNT(*) FROM documents WHERE tenant_id = $1`
125125 listQuery := `
@@ -197,7 +197,7 @@ func (r *DocumentRepo) Update(ctx context.Context, doc *repository.Document) err
197197}
198198
199199// Delete deletes a document, scoped to a tenant
200- func (r * DocumentRepo ) Delete (ctx context.Context , tenantID , id uuid. UUID ) error {
200+ func (r * DocumentRepo ) Delete (ctx context.Context , tenantID , id ids. ID ) error {
201201 result , err := r .db .Pool .Exec (ctx , `DELETE FROM documents WHERE tenant_id = $1 AND id = $2` , tenantID , id )
202202 if err != nil {
203203 return fmt .Errorf ("failed to delete document: %w" , err )
@@ -239,7 +239,7 @@ func (r *DocumentRepo) CreateChunks(ctx context.Context, chunks []*repository.Do
239239}
240240
241241// GetChunks retrieves chunks for a document, scoped to a tenant
242- func (r * DocumentRepo ) GetChunks (ctx context.Context , tenantID , documentID uuid. UUID , limit , offset int ) ([]* repository.DocumentChunk , error ) {
242+ func (r * DocumentRepo ) GetChunks (ctx context.Context , tenantID , documentID ids. ID , limit , offset int ) ([]* repository.DocumentChunk , error ) {
243243 query := `
244244 SELECT id, document_id, chunk_index, content, metadata, created_at
245245 FROM document_chunks
@@ -272,7 +272,7 @@ func (r *DocumentRepo) GetChunks(ctx context.Context, tenantID, documentID uuid.
272272}
273273
274274// DeleteChunks deletes all chunks for a document, scoped to a tenant
275- func (r * DocumentRepo ) DeleteChunks (ctx context.Context , tenantID , documentID uuid. UUID ) error {
275+ func (r * DocumentRepo ) DeleteChunks (ctx context.Context , tenantID , documentID ids. ID ) error {
276276 _ , err := r .db .Pool .Exec (ctx , `DELETE FROM document_chunks WHERE tenant_id = $1 AND document_id = $2` , tenantID , documentID )
277277 if err != nil {
278278 return fmt .Errorf ("failed to delete chunks: %w" , err )
0 commit comments