mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-19 05:26:31 +00:00
31b34241e0
* change /content/ -> /homebox/ * add cache to code generators * update env variables to set data storage * update env variables * set env variables in prod container * implement attachment post route (WIP) * get attachment endpoint * attachment download * implement string utilities lib * implement generic drop zone * use explicit truncate * remove clean dir * drop strings composable for lib * update item types and add attachments * add attachment API * implement service context * consolidate API code * implement editing attachments * implement upload limit configuration * improve error handling * add docs for max upload size * fix test cases
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/ent"
|
|
"github.com/hay-kot/homebox/backend/ent/document"
|
|
"github.com/hay-kot/homebox/backend/ent/group"
|
|
"github.com/hay-kot/homebox/backend/internal/types"
|
|
)
|
|
|
|
// DocumentRepository is a repository for Document entity
|
|
type DocumentRepository struct {
|
|
db *ent.Client
|
|
}
|
|
|
|
func (r *DocumentRepository) Create(ctx context.Context, gid uuid.UUID, doc types.DocumentCreate) (*ent.Document, error) {
|
|
return r.db.Document.Create().
|
|
SetGroupID(gid).
|
|
SetTitle(doc.Title).
|
|
SetPath(doc.Path).
|
|
Save(ctx)
|
|
}
|
|
|
|
func (r *DocumentRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]*ent.Document, error) {
|
|
return r.db.Document.Query().
|
|
Where(document.HasGroupWith(group.ID(gid))).
|
|
All(ctx)
|
|
}
|
|
|
|
func (r *DocumentRepository) Get(ctx context.Context, id uuid.UUID) (*ent.Document, error) {
|
|
return r.db.Document.Query().
|
|
Where(document.ID(id)).
|
|
Only(ctx)
|
|
}
|
|
|
|
func (r *DocumentRepository) Update(ctx context.Context, id uuid.UUID, doc types.DocumentUpdate) (*ent.Document, error) {
|
|
return r.db.Document.UpdateOneID(id).
|
|
SetTitle(doc.Title).
|
|
SetPath(doc.Path).
|
|
Save(ctx)
|
|
}
|
|
|
|
func (r *DocumentRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
|
return r.db.Document.DeleteOneID(id).Exec(ctx)
|
|
}
|