27389164b0
- Implemented image folder repository with CRUD operations. - Added image reference repository for managing image references to articles. - Created image repository for handling image assets, including listing, inserting, updating, and deleting images. - Introduced image usage repository to track storage usage and quotas for tenants. - Added SQL queries for image assets, folders, references, and usage. - Developed image handler for HTTP endpoints to manage images and folders. - Created database migration scripts for image-related tables and structures.
162 lines
4.1 KiB
Go
162 lines
4.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: image_folder.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countActiveImagesInFolder = `-- name: CountActiveImagesInFolder :one
|
|
SELECT COUNT(*)::INT AS count
|
|
FROM image_assets
|
|
WHERE tenant_id = $1
|
|
AND folder_id = $2
|
|
AND status = 'active'
|
|
AND deleted_at IS NULL
|
|
`
|
|
|
|
type CountActiveImagesInFolderParams struct {
|
|
TenantID int64 `json:"tenant_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)
|
|
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)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateImageFolderParams struct {
|
|
TenantID int64 `json:"tenant_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)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const deleteImageFolder = `-- name: DeleteImageFolder :exec
|
|
DELETE FROM image_folders
|
|
WHERE id = $1 AND tenant_id = $2
|
|
`
|
|
|
|
type DeleteImageFolderParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteImageFolder(ctx context.Context, arg DeleteImageFolderParams) error {
|
|
_, err := q.db.Exec(ctx, deleteImageFolder, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|
|
|
|
const getImageFolder = `-- name: GetImageFolder :one
|
|
SELECT id, tenant_id, name, created_at, updated_at
|
|
FROM image_folders
|
|
WHERE id = $1 AND tenant_id = $2
|
|
`
|
|
|
|
type GetImageFolderParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
type GetImageFolderRow struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_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)
|
|
var i GetImageFolderRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TenantID,
|
|
&i.Name,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listImageFolders = `-- name: ListImageFolders :many
|
|
SELECT f.id, f.tenant_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
|
|
WHERE f.tenant_id = $1
|
|
GROUP BY f.id
|
|
ORDER BY f.name
|
|
`
|
|
|
|
type ListImageFoldersRow struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_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)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListImageFoldersRow
|
|
for rows.Next() {
|
|
var i ListImageFoldersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TenantID,
|
|
&i.Name,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ImageCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateImageFolder = `-- name: UpdateImageFolder :exec
|
|
UPDATE image_folders
|
|
SET name = $1, updated_at = NOW()
|
|
WHERE id = $2 AND tenant_id = $3
|
|
`
|
|
|
|
type UpdateImageFolderParams struct {
|
|
Name string `json:"name"`
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateImageFolder(ctx context.Context, arg UpdateImageFolderParams) error {
|
|
_, err := q.db.Exec(ctx, updateImageFolder, arg.Name, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|