Scope knowledge and image libraries by brand
This commit is contained in:
@@ -15,24 +15,31 @@ const countImageAssets = `-- name: CountImageAssets :one
|
||||
SELECT COUNT(*)::INT AS total
|
||||
FROM image_assets
|
||||
WHERE tenant_id = $1
|
||||
AND brand_id = $2
|
||||
AND status = 'active'
|
||||
AND deleted_at IS NULL
|
||||
AND (
|
||||
$2::BIGINT IS NULL
|
||||
OR ($2::BIGINT = 0 AND folder_id IS NULL)
|
||||
OR folder_id = $2::BIGINT
|
||||
$3::BIGINT IS NULL
|
||||
OR ($3::BIGINT = 0 AND folder_id IS NULL)
|
||||
OR folder_id = $3::BIGINT
|
||||
)
|
||||
AND ($3::TEXT IS NULL OR name ILIKE '%' || $3::TEXT || '%')
|
||||
AND ($4::TEXT IS NULL OR name ILIKE '%' || $4::TEXT || '%')
|
||||
`
|
||||
|
||||
type CountImageAssetsParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
SearchQuery pgtype.Text `json:"search_query"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountImageAssets(ctx context.Context, arg CountImageAssetsParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countImageAssets, arg.TenantID, arg.FolderID, arg.SearchQuery)
|
||||
row := q.db.QueryRow(ctx, countImageAssets,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
arg.FolderID,
|
||||
arg.SearchQuery,
|
||||
)
|
||||
var total int32
|
||||
err := row.Scan(&total)
|
||||
return total, err
|
||||
@@ -42,32 +49,42 @@ const countUncategorizedImages = `-- name: CountUncategorizedImages :one
|
||||
SELECT COUNT(*)::INT AS count
|
||||
FROM image_assets
|
||||
WHERE tenant_id = $1
|
||||
AND brand_id = $2
|
||||
AND folder_id IS NULL
|
||||
AND status = 'active'
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) CountUncategorizedImages(ctx context.Context, tenantID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countUncategorizedImages, tenantID)
|
||||
type CountUncategorizedImagesParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUncategorizedImages(ctx context.Context, arg CountUncategorizedImagesParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countUncategorizedImages, arg.TenantID, arg.BrandID)
|
||||
var count int32
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getImageAsset = `-- name: GetImageAsset :one
|
||||
SELECT id, tenant_id, folder_id, object_key, name, size_bytes, status, created_by, created_at, updated_at
|
||||
SELECT id, tenant_id, brand_id, folder_id, object_key, name, size_bytes, status, created_by, created_at, updated_at
|
||||
FROM image_assets
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
WHERE id = $1
|
||||
AND tenant_id = $2
|
||||
AND brand_id = $3
|
||||
`
|
||||
|
||||
type GetImageAssetParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
type GetImageAssetRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
ObjectKey string `json:"object_key"`
|
||||
Name string `json:"name"`
|
||||
@@ -79,11 +96,12 @@ type GetImageAssetRow struct {
|
||||
}
|
||||
|
||||
func (q *Queries) GetImageAsset(ctx context.Context, arg GetImageAssetParams) (GetImageAssetRow, error) {
|
||||
row := q.db.QueryRow(ctx, getImageAsset, arg.ID, arg.TenantID)
|
||||
row := q.db.QueryRow(ctx, getImageAsset, arg.ID, arg.TenantID, arg.BrandID)
|
||||
var i GetImageAssetRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.BrandID,
|
||||
&i.FolderID,
|
||||
&i.ObjectKey,
|
||||
&i.Name,
|
||||
@@ -97,13 +115,14 @@ func (q *Queries) GetImageAsset(ctx context.Context, arg GetImageAssetParams) (G
|
||||
}
|
||||
|
||||
const insertImageAsset = `-- name: InsertImageAsset :one
|
||||
INSERT INTO image_assets (tenant_id, folder_id, object_key, name, size_bytes, status, created_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
INSERT INTO image_assets (tenant_id, brand_id, folder_id, object_key, name, size_bytes, status, created_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertImageAssetParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
ObjectKey string `json:"object_key"`
|
||||
Name string `json:"name"`
|
||||
@@ -115,6 +134,7 @@ type InsertImageAssetParams struct {
|
||||
func (q *Queries) InsertImageAsset(ctx context.Context, arg InsertImageAssetParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, insertImageAsset,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
arg.FolderID,
|
||||
arg.ObjectKey,
|
||||
arg.Name,
|
||||
@@ -131,13 +151,15 @@ const listActiveImagesByFolder = `-- name: ListActiveImagesByFolder :many
|
||||
SELECT id, object_key, size_bytes
|
||||
FROM image_assets
|
||||
WHERE tenant_id = $1
|
||||
AND folder_id = $2
|
||||
AND brand_id = $2
|
||||
AND folder_id = $3
|
||||
AND status = 'active'
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type ListActiveImagesByFolderParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
}
|
||||
|
||||
@@ -148,7 +170,7 @@ type ListActiveImagesByFolderRow struct {
|
||||
}
|
||||
|
||||
func (q *Queries) ListActiveImagesByFolder(ctx context.Context, arg ListActiveImagesByFolderParams) ([]ListActiveImagesByFolderRow, error) {
|
||||
rows, err := q.db.Query(ctx, listActiveImagesByFolder, arg.TenantID, arg.FolderID)
|
||||
rows, err := q.db.Query(ctx, listActiveImagesByFolder, arg.TenantID, arg.BrandID, arg.FolderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -168,23 +190,25 @@ func (q *Queries) ListActiveImagesByFolder(ctx context.Context, arg ListActiveIm
|
||||
}
|
||||
|
||||
const listImageAssets = `-- name: ListImageAssets :many
|
||||
SELECT id, tenant_id, folder_id, object_key, name, size_bytes, status, created_by, created_at, updated_at
|
||||
SELECT id, tenant_id, brand_id, folder_id, object_key, name, size_bytes, status, created_by, created_at, updated_at
|
||||
FROM image_assets
|
||||
WHERE tenant_id = $1
|
||||
AND brand_id = $2
|
||||
AND status = 'active'
|
||||
AND deleted_at IS NULL
|
||||
AND (
|
||||
$2::BIGINT IS NULL
|
||||
OR ($2::BIGINT = 0 AND folder_id IS NULL)
|
||||
OR folder_id = $2::BIGINT
|
||||
$3::BIGINT IS NULL
|
||||
OR ($3::BIGINT = 0 AND folder_id IS NULL)
|
||||
OR folder_id = $3::BIGINT
|
||||
)
|
||||
AND ($3::TEXT IS NULL OR name ILIKE '%' || $3::TEXT || '%')
|
||||
AND ($4::TEXT IS NULL OR name ILIKE '%' || $4::TEXT || '%')
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $5 OFFSET $4
|
||||
LIMIT $6 OFFSET $5
|
||||
`
|
||||
|
||||
type ListImageAssetsParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
SearchQuery pgtype.Text `json:"search_query"`
|
||||
PageOffset int32 `json:"page_offset"`
|
||||
@@ -194,6 +218,7 @@ type ListImageAssetsParams struct {
|
||||
type ListImageAssetsRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
ObjectKey string `json:"object_key"`
|
||||
Name string `json:"name"`
|
||||
@@ -207,6 +232,7 @@ type ListImageAssetsRow struct {
|
||||
func (q *Queries) ListImageAssets(ctx context.Context, arg ListImageAssetsParams) ([]ListImageAssetsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listImageAssets,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
arg.FolderID,
|
||||
arg.SearchQuery,
|
||||
arg.PageOffset,
|
||||
@@ -222,6 +248,7 @@ func (q *Queries) ListImageAssets(ctx context.Context, arg ListImageAssetsParams
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.BrandID,
|
||||
&i.FolderID,
|
||||
&i.ObjectKey,
|
||||
&i.Name,
|
||||
@@ -245,84 +272,113 @@ const markImagesInFolderPendingDelete = `-- name: MarkImagesInFolderPendingDelet
|
||||
UPDATE image_assets
|
||||
SET status = 'pending_delete', folder_id = NULL, updated_at = NOW()
|
||||
WHERE tenant_id = $1
|
||||
AND folder_id = $2
|
||||
AND brand_id = $2
|
||||
AND folder_id = $3
|
||||
AND status = 'active'
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type MarkImagesInFolderPendingDeleteParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkImagesInFolderPendingDelete(ctx context.Context, arg MarkImagesInFolderPendingDeleteParams) error {
|
||||
_, err := q.db.Exec(ctx, markImagesInFolderPendingDelete, arg.TenantID, arg.FolderID)
|
||||
_, err := q.db.Exec(ctx, markImagesInFolderPendingDelete, arg.TenantID, arg.BrandID, arg.FolderID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateImageAssetDeleted = `-- name: UpdateImageAssetDeleted :exec
|
||||
UPDATE image_assets
|
||||
SET status = 'deleted', deleted_at = NOW(), updated_at = NOW()
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
WHERE id = $1
|
||||
AND tenant_id = $2
|
||||
AND brand_id = $3
|
||||
`
|
||||
|
||||
type UpdateImageAssetDeletedParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImageAssetDeleted(ctx context.Context, arg UpdateImageAssetDeletedParams) error {
|
||||
_, err := q.db.Exec(ctx, updateImageAssetDeleted, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, updateImageAssetDeleted, arg.ID, arg.TenantID, arg.BrandID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateImageAssetFolder = `-- name: UpdateImageAssetFolder :exec
|
||||
UPDATE image_assets
|
||||
SET folder_id = $1, updated_at = NOW()
|
||||
WHERE id = $2 AND tenant_id = $3
|
||||
WHERE id = $2
|
||||
AND tenant_id = $3
|
||||
AND brand_id = $4
|
||||
`
|
||||
|
||||
type UpdateImageAssetFolderParams struct {
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImageAssetFolder(ctx context.Context, arg UpdateImageAssetFolderParams) error {
|
||||
_, err := q.db.Exec(ctx, updateImageAssetFolder, arg.FolderID, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, updateImageAssetFolder,
|
||||
arg.FolderID,
|
||||
arg.ID,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateImageAssetName = `-- name: UpdateImageAssetName :exec
|
||||
UPDATE image_assets
|
||||
SET name = $1, updated_at = NOW()
|
||||
WHERE id = $2 AND tenant_id = $3
|
||||
WHERE id = $2
|
||||
AND tenant_id = $3
|
||||
AND brand_id = $4
|
||||
`
|
||||
|
||||
type UpdateImageAssetNameParams struct {
|
||||
Name string `json:"name"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImageAssetName(ctx context.Context, arg UpdateImageAssetNameParams) error {
|
||||
_, err := q.db.Exec(ctx, updateImageAssetName, arg.Name, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, updateImageAssetName,
|
||||
arg.Name,
|
||||
arg.ID,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateImageAssetStatus = `-- name: UpdateImageAssetStatus :exec
|
||||
UPDATE image_assets
|
||||
SET status = $1, updated_at = NOW()
|
||||
WHERE id = $2 AND tenant_id = $3
|
||||
WHERE id = $2
|
||||
AND tenant_id = $3
|
||||
AND brand_id = $4
|
||||
`
|
||||
|
||||
type UpdateImageAssetStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImageAssetStatus(ctx context.Context, arg UpdateImageAssetStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateImageAssetStatus, arg.Status, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, updateImageAssetStatus,
|
||||
arg.Status,
|
||||
arg.ID,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user