Scope knowledge and image libraries by brand
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
type ImageAsset struct {
|
||||
ID int64
|
||||
TenantID int64
|
||||
BrandID int64
|
||||
FolderID *int64
|
||||
ObjectKey string
|
||||
Name string
|
||||
@@ -22,6 +23,7 @@ type ImageAsset struct {
|
||||
|
||||
type ImageAssetListParams struct {
|
||||
TenantID int64
|
||||
BrandID int64
|
||||
FolderID *int64
|
||||
SearchQuery *string
|
||||
PageSize int
|
||||
@@ -30,6 +32,7 @@ type ImageAssetListParams struct {
|
||||
|
||||
type InsertImageAssetInput struct {
|
||||
TenantID int64
|
||||
BrandID int64
|
||||
FolderID *int64
|
||||
ObjectKey string
|
||||
Name string
|
||||
@@ -46,15 +49,15 @@ type FolderImageSummary struct {
|
||||
|
||||
type ImageRepository interface {
|
||||
List(ctx context.Context, params ImageAssetListParams) ([]ImageAsset, int, error)
|
||||
Get(ctx context.Context, tenantID, id int64) (*ImageAsset, error)
|
||||
Get(ctx context.Context, tenantID, brandID, id int64) (*ImageAsset, error)
|
||||
Insert(ctx context.Context, input InsertImageAssetInput) (int64, error)
|
||||
UpdateStatus(ctx context.Context, tenantID, id int64, status string) error
|
||||
MarkDeleted(ctx context.Context, tenantID, id int64) error
|
||||
UpdateName(ctx context.Context, tenantID, id int64, name string) error
|
||||
UpdateFolder(ctx context.Context, tenantID, id int64, folderID *int64) error
|
||||
ListActiveByFolder(ctx context.Context, tenantID, folderID int64) ([]FolderImageSummary, error)
|
||||
MarkImagesInFolderPendingDelete(ctx context.Context, tenantID, folderID int64) error
|
||||
CountUncategorized(ctx context.Context, tenantID int64) (int, error)
|
||||
UpdateStatus(ctx context.Context, tenantID, brandID, id int64, status string) error
|
||||
MarkDeleted(ctx context.Context, tenantID, brandID, id int64) error
|
||||
UpdateName(ctx context.Context, tenantID, brandID, id int64, name string) error
|
||||
UpdateFolder(ctx context.Context, tenantID, brandID, id int64, folderID *int64) error
|
||||
ListActiveByFolder(ctx context.Context, tenantID, brandID, folderID int64) ([]FolderImageSummary, error)
|
||||
MarkImagesInFolderPendingDelete(ctx context.Context, tenantID, brandID, folderID int64) error
|
||||
CountUncategorized(ctx context.Context, tenantID, brandID int64) (int, error)
|
||||
}
|
||||
|
||||
type imageRepository struct {
|
||||
@@ -68,6 +71,7 @@ func NewImageRepository(db generated.DBTX) ImageRepository {
|
||||
func (r *imageRepository) List(ctx context.Context, params ImageAssetListParams) ([]ImageAsset, int, error) {
|
||||
listParams := generated.ListImageAssetsParams{
|
||||
TenantID: params.TenantID,
|
||||
BrandID: params.BrandID,
|
||||
FolderID: pgInt8(params.FolderID),
|
||||
PageOffset: int32(params.PageOffset),
|
||||
PageSize: int32(params.PageSize),
|
||||
@@ -81,6 +85,7 @@ func (r *imageRepository) List(ctx context.Context, params ImageAssetListParams)
|
||||
|
||||
total, err := r.q.CountImageAssets(ctx, generated.CountImageAssetsParams{
|
||||
TenantID: params.TenantID,
|
||||
BrandID: params.BrandID,
|
||||
FolderID: listParams.FolderID,
|
||||
SearchQuery: listParams.SearchQuery,
|
||||
})
|
||||
@@ -93,6 +98,7 @@ func (r *imageRepository) List(ctx context.Context, params ImageAssetListParams)
|
||||
assets[i] = ImageAsset{
|
||||
ID: row.ID,
|
||||
TenantID: row.TenantID,
|
||||
BrandID: row.BrandID,
|
||||
FolderID: nullableInt64(row.FolderID),
|
||||
ObjectKey: row.ObjectKey,
|
||||
Name: row.Name,
|
||||
@@ -107,10 +113,11 @@ func (r *imageRepository) List(ctx context.Context, params ImageAssetListParams)
|
||||
return assets, int(total), nil
|
||||
}
|
||||
|
||||
func (r *imageRepository) Get(ctx context.Context, tenantID, id int64) (*ImageAsset, error) {
|
||||
func (r *imageRepository) Get(ctx context.Context, tenantID, brandID, id int64) (*ImageAsset, error) {
|
||||
row, err := r.q.GetImageAsset(ctx, generated.GetImageAssetParams{
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -119,6 +126,7 @@ func (r *imageRepository) Get(ctx context.Context, tenantID, id int64) (*ImageAs
|
||||
return &ImageAsset{
|
||||
ID: row.ID,
|
||||
TenantID: row.TenantID,
|
||||
BrandID: row.BrandID,
|
||||
FolderID: nullableInt64(row.FolderID),
|
||||
ObjectKey: row.ObjectKey,
|
||||
Name: row.Name,
|
||||
@@ -133,6 +141,7 @@ func (r *imageRepository) Get(ctx context.Context, tenantID, id int64) (*ImageAs
|
||||
func (r *imageRepository) Insert(ctx context.Context, input InsertImageAssetInput) (int64, error) {
|
||||
return r.q.InsertImageAsset(ctx, generated.InsertImageAssetParams{
|
||||
TenantID: input.TenantID,
|
||||
BrandID: input.BrandID,
|
||||
FolderID: pgInt8(input.FolderID),
|
||||
ObjectKey: input.ObjectKey,
|
||||
Name: input.Name,
|
||||
@@ -142,40 +151,45 @@ func (r *imageRepository) Insert(ctx context.Context, input InsertImageAssetInpu
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) UpdateStatus(ctx context.Context, tenantID, id int64, status string) error {
|
||||
func (r *imageRepository) UpdateStatus(ctx context.Context, tenantID, brandID, id int64, status string) error {
|
||||
return r.q.UpdateImageAssetStatus(ctx, generated.UpdateImageAssetStatusParams{
|
||||
Status: status,
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) MarkDeleted(ctx context.Context, tenantID, id int64) error {
|
||||
func (r *imageRepository) MarkDeleted(ctx context.Context, tenantID, brandID, id int64) error {
|
||||
return r.q.UpdateImageAssetDeleted(ctx, generated.UpdateImageAssetDeletedParams{
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) UpdateName(ctx context.Context, tenantID, id int64, name string) error {
|
||||
func (r *imageRepository) UpdateName(ctx context.Context, tenantID, brandID, id int64, name string) error {
|
||||
return r.q.UpdateImageAssetName(ctx, generated.UpdateImageAssetNameParams{
|
||||
Name: name,
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) UpdateFolder(ctx context.Context, tenantID, id int64, folderID *int64) error {
|
||||
func (r *imageRepository) UpdateFolder(ctx context.Context, tenantID, brandID, id int64, folderID *int64) error {
|
||||
return r.q.UpdateImageAssetFolder(ctx, generated.UpdateImageAssetFolderParams{
|
||||
FolderID: pgInt8(folderID),
|
||||
ID: id,
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) ListActiveByFolder(ctx context.Context, tenantID, folderID int64) ([]FolderImageSummary, error) {
|
||||
func (r *imageRepository) ListActiveByFolder(ctx context.Context, tenantID, brandID, folderID int64) ([]FolderImageSummary, error) {
|
||||
rows, err := r.q.ListActiveImagesByFolder(ctx, generated.ListActiveImagesByFolderParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
FolderID: pgInt8(&folderID),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -193,15 +207,19 @@ func (r *imageRepository) ListActiveByFolder(ctx context.Context, tenantID, fold
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *imageRepository) MarkImagesInFolderPendingDelete(ctx context.Context, tenantID, folderID int64) error {
|
||||
func (r *imageRepository) MarkImagesInFolderPendingDelete(ctx context.Context, tenantID, brandID, folderID int64) error {
|
||||
return r.q.MarkImagesInFolderPendingDelete(ctx, generated.MarkImagesInFolderPendingDeleteParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
FolderID: pgInt8(&folderID),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *imageRepository) CountUncategorized(ctx context.Context, tenantID int64) (int, error) {
|
||||
count, err := r.q.CountUncategorizedImages(ctx, tenantID)
|
||||
func (r *imageRepository) CountUncategorized(ctx context.Context, tenantID, brandID int64) (int, error) {
|
||||
count, err := r.q.CountUncategorizedImages(ctx, generated.CountUncategorizedImagesParams{
|
||||
TenantID: tenantID,
|
||||
BrandID: brandID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user