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
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/ent"
|
|
"github.com/hay-kot/homebox/backend/ent/documenttoken"
|
|
"github.com/hay-kot/homebox/backend/internal/types"
|
|
)
|
|
|
|
// DocumentTokensRepository is a repository for Document entity
|
|
type DocumentTokensRepository struct {
|
|
db *ent.Client
|
|
}
|
|
|
|
func (r *DocumentTokensRepository) Create(ctx context.Context, data types.DocumentTokenCreate) (*ent.DocumentToken, error) {
|
|
result, err := r.db.DocumentToken.Create().
|
|
SetDocumentID(data.DocumentID).
|
|
SetToken(data.TokenHash).
|
|
SetExpiresAt(data.ExpiresAt).
|
|
Save(ctx)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.db.DocumentToken.Query().
|
|
Where(documenttoken.ID(result.ID)).
|
|
WithDocument().
|
|
Only(ctx)
|
|
}
|
|
|
|
func (r *DocumentTokensRepository) PurgeExpiredTokens(ctx context.Context) (int, error) {
|
|
return r.db.DocumentToken.Delete().Where(documenttoken.ExpiresAtLT(time.Now())).Exec(ctx)
|
|
}
|
|
|
|
func (r *DocumentTokensRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
|
return r.db.DocumentToken.DeleteOneID(id).Exec(ctx)
|
|
}
|