Scope knowledge and image libraries by brand
This commit is contained in:
@@ -15,36 +15,39 @@ const countActiveImagesInFolder = `-- name: CountActiveImagesInFolder :one
|
||||
SELECT COUNT(*)::INT AS count
|
||||
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 CountActiveImagesInFolderParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
FolderID pgtype.Int8 `json:"folder_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountActiveImagesInFolder(ctx context.Context, arg CountActiveImagesInFolderParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, countActiveImagesInFolder, arg.TenantID, arg.FolderID)
|
||||
row := q.db.QueryRow(ctx, countActiveImagesInFolder, arg.TenantID, arg.BrandID, arg.FolderID)
|
||||
var count int32
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createImageFolder = `-- name: CreateImageFolder :one
|
||||
INSERT INTO image_folders (tenant_id, name)
|
||||
VALUES ($1, $2)
|
||||
INSERT INTO image_folders (tenant_id, brand_id, name)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type CreateImageFolderParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImageFolder(ctx context.Context, arg CreateImageFolderParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, createImageFolder, arg.TenantID, arg.Name)
|
||||
row := q.db.QueryRow(ctx, createImageFolder, arg.TenantID, arg.BrandID, arg.Name)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
@@ -52,44 +55,52 @@ func (q *Queries) CreateImageFolder(ctx context.Context, arg CreateImageFolderPa
|
||||
|
||||
const deleteImageFolder = `-- name: DeleteImageFolder :exec
|
||||
DELETE FROM image_folders
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
WHERE id = $1
|
||||
AND tenant_id = $2
|
||||
AND brand_id = $3
|
||||
`
|
||||
|
||||
type DeleteImageFolderParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteImageFolder(ctx context.Context, arg DeleteImageFolderParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteImageFolder, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, deleteImageFolder, arg.ID, arg.TenantID, arg.BrandID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getImageFolder = `-- name: GetImageFolder :one
|
||||
SELECT id, tenant_id, name, created_at, updated_at
|
||||
SELECT id, tenant_id, brand_id, name, created_at, updated_at
|
||||
FROM image_folders
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
WHERE id = $1
|
||||
AND tenant_id = $2
|
||||
AND brand_id = $3
|
||||
`
|
||||
|
||||
type GetImageFolderParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
type GetImageFolderRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetImageFolder(ctx context.Context, arg GetImageFolderParams) (GetImageFolderRow, error) {
|
||||
row := q.db.QueryRow(ctx, getImageFolder, arg.ID, arg.TenantID)
|
||||
row := q.db.QueryRow(ctx, getImageFolder, arg.ID, arg.TenantID, arg.BrandID)
|
||||
var i GetImageFolderRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.BrandID,
|
||||
&i.Name,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
@@ -98,26 +109,33 @@ func (q *Queries) GetImageFolder(ctx context.Context, arg GetImageFolderParams)
|
||||
}
|
||||
|
||||
const listImageFolders = `-- name: ListImageFolders :many
|
||||
SELECT f.id, f.tenant_id, f.name, f.created_at, f.updated_at,
|
||||
SELECT f.id, f.tenant_id, f.brand_id, f.name, f.created_at, f.updated_at,
|
||||
COUNT(ia.id) FILTER (WHERE ia.status = 'active' AND ia.deleted_at IS NULL)::INT AS image_count
|
||||
FROM image_folders f
|
||||
LEFT JOIN image_assets ia ON ia.tenant_id = f.tenant_id AND ia.folder_id = f.id
|
||||
LEFT JOIN image_assets ia ON ia.tenant_id = f.tenant_id AND ia.brand_id = f.brand_id AND ia.folder_id = f.id
|
||||
WHERE f.tenant_id = $1
|
||||
AND f.brand_id = $2
|
||||
GROUP BY f.id
|
||||
ORDER BY f.name
|
||||
`
|
||||
|
||||
type ListImageFoldersParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
type ListImageFoldersRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ImageCount int32 `json:"image_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListImageFolders(ctx context.Context, tenantID int64) ([]ListImageFoldersRow, error) {
|
||||
rows, err := q.db.Query(ctx, listImageFolders, tenantID)
|
||||
func (q *Queries) ListImageFolders(ctx context.Context, arg ListImageFoldersParams) ([]ListImageFoldersRow, error) {
|
||||
rows, err := q.db.Query(ctx, listImageFolders, arg.TenantID, arg.BrandID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -128,6 +146,7 @@ func (q *Queries) ListImageFolders(ctx context.Context, tenantID int64) ([]ListI
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.BrandID,
|
||||
&i.Name,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
@@ -146,16 +165,24 @@ func (q *Queries) ListImageFolders(ctx context.Context, tenantID int64) ([]ListI
|
||||
const updateImageFolder = `-- name: UpdateImageFolder :exec
|
||||
UPDATE image_folders
|
||||
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 UpdateImageFolderParams struct {
|
||||
Name string `json:"name"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
BrandID int64 `json:"brand_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateImageFolder(ctx context.Context, arg UpdateImageFolderParams) error {
|
||||
_, err := q.db.Exec(ctx, updateImageFolder, arg.Name, arg.ID, arg.TenantID)
|
||||
_, err := q.db.Exec(ctx, updateImageFolder,
|
||||
arg.Name,
|
||||
arg.ID,
|
||||
arg.TenantID,
|
||||
arg.BrandID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user