8a4029058b
Add demo dashboard settings table and CRUD API * Add demo dashboard settings table and CRUD API - Migration 00000000000123: create demoDashboardSettings table (id, guid, key, value JSONB, isDeleted, timestamps) - SQLC queries and repository for create, list, listByGuid, get, update, soft delete - OpenAPI paths and schemas in queryAPI.yaml; regenerate api.gen.go (embedded spec) - Handlers in api/queryAPI/demodashboardsettings.go; ConfigProvider GetDBQueries for repo access - Unit tests for demo dashboard settings CRUD * Fix sqlc-generated demo dashboard setting types Align demo dashboard settings handlers with sqlc output (DemoDashboardSetting model + pointer slices) so CI codegen/build succeeds. * Fix CI gosec and gofmt issues - Suppress gosec G115 for TotalCount len->int32 cast (consistent with other list endpoints) - gofmt mock GetDBQueries() in test helpers * gofmt query API demo settings * Tighten demo dashboard settings OpenAPI constraints * Regenerate query API embedded spec * refactor: generic UI settings (table, API, service) and three-layer architecture - Replace demo-dashboard-settings with generic UI settings: - Table uiSettings with namespace (was guid), key, value JSONB; UNIQUE(namespace, key) - Migration 123: create_ui_settings (single migration, no rename) - OpenAPI: /ui-settings, UISettingsService, UISetting schemas with namespace - API types and handlers: CreateUISetting, ListUISettings, GetUISetting, UpdateUISetting, DeleteUISetting - Add service layer (architecture fix): - internal/uisettings: Service with Create, List, ListByNamespace, Get, Update, SoftDelete - Controllers call s.svc.UISettings only; remove GetDBQueries from queryAPI ConfigProvider - Wire UISettings in Services, main.go, and testutils - Repository: uisettings.sql + uisettings.sql.go, UISetting model; remove demodashboardsettings - Controller: uisettings.go (replaces demodashboardsettings.go), ErrNotFound from uisettings package - Tests: uisettings_test.go with namespace-based list/cre… * Add UISetting model and generated queries for uiSettings table - models.go: add UISetting struct (sqlc 1.30.0) - uisettings.sql.go: generated CRUD for ui_settings feature Made-with: Cursor * Use repository.UiSetting to match sqlc-generated type - service and API use repository.UiSetting (sqlc struct name for uiSettings table) - uisettings.sql.go: keep CreateUISetting/GetUISetting etc. from query names, return *UiSetting - Fixes Docker/CI build undefined repository.UISetting * Fix import formatting for golangci-lint * Lint fix * uisettings list test * tests fixes * Merge main: resolve api.gen.go conflicts (UI settings + DeleteDocument) * Doc updates and elimination of index redundancy Approved-by: Jay Brown
184 lines
4.4 KiB
Go
184 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: uisettings.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createUISetting = `-- name: CreateUISetting :one
|
|
INSERT INTO "uiSettings" (namespace, key, value)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, namespace, key, value, "isDeleted", "createdAt", "updatedAt"
|
|
`
|
|
|
|
type CreateUISettingParams struct {
|
|
Namespace string `db:"namespace"`
|
|
Key string `db:"key"`
|
|
Value []byte `db:"value"`
|
|
}
|
|
|
|
// CreateUISetting
|
|
//
|
|
// INSERT INTO "uiSettings" (namespace, key, value)
|
|
// VALUES ($1, $2, $3)
|
|
// RETURNING id, namespace, key, value, "isDeleted", "createdAt", "updatedAt"
|
|
func (q *Queries) CreateUISetting(ctx context.Context, arg *CreateUISettingParams) (*UiSetting, error) {
|
|
row := q.db.QueryRow(ctx, createUISetting, arg.Namespace, arg.Key, arg.Value)
|
|
var i UiSetting
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Namespace,
|
|
&i.Key,
|
|
&i.Value,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getUISetting = `-- name: GetUISetting :one
|
|
SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
WHERE id = $1 AND "isDeleted" = FALSE
|
|
`
|
|
|
|
// GetUISetting
|
|
//
|
|
// SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
// WHERE id = $1 AND "isDeleted" = FALSE
|
|
func (q *Queries) GetUISetting(ctx context.Context, id uuid.UUID) (*UiSetting, error) {
|
|
row := q.db.QueryRow(ctx, getUISetting, id)
|
|
var i UiSetting
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Namespace,
|
|
&i.Key,
|
|
&i.Value,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listUISettings = `-- name: ListUISettings :many
|
|
SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
WHERE "isDeleted" = FALSE
|
|
ORDER BY "createdAt" ASC
|
|
`
|
|
|
|
// ListUISettings
|
|
//
|
|
// SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
// WHERE "isDeleted" = FALSE
|
|
// ORDER BY "createdAt" ASC
|
|
func (q *Queries) ListUISettings(ctx context.Context) ([]*UiSetting, error) {
|
|
rows, err := q.db.Query(ctx, listUISettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*UiSetting{}
|
|
for rows.Next() {
|
|
var i UiSetting
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Namespace,
|
|
&i.Key,
|
|
&i.Value,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listUISettingsByNamespace = `-- name: ListUISettingsByNamespace :many
|
|
SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
WHERE "isDeleted" = FALSE AND namespace = $1
|
|
ORDER BY "createdAt" ASC
|
|
`
|
|
|
|
// ListUISettingsByNamespace
|
|
//
|
|
// SELECT id, namespace, key, value, "isDeleted", "createdAt", "updatedAt" FROM "uiSettings"
|
|
// WHERE "isDeleted" = FALSE AND namespace = $1
|
|
// ORDER BY "createdAt" ASC
|
|
func (q *Queries) ListUISettingsByNamespace(ctx context.Context, namespace string) ([]*UiSetting, error) {
|
|
rows, err := q.db.Query(ctx, listUISettingsByNamespace, namespace)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*UiSetting{}
|
|
for rows.Next() {
|
|
var i UiSetting
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Namespace,
|
|
&i.Key,
|
|
&i.Value,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteUISetting = `-- name: SoftDeleteUISetting :exec
|
|
UPDATE "uiSettings"
|
|
SET "isDeleted" = TRUE, "updatedAt" = NOW()
|
|
WHERE id = $1
|
|
`
|
|
|
|
// SoftDeleteUISetting
|
|
//
|
|
// UPDATE "uiSettings"
|
|
// SET "isDeleted" = TRUE, "updatedAt" = NOW()
|
|
// WHERE id = $1
|
|
func (q *Queries) SoftDeleteUISetting(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, softDeleteUISetting, id)
|
|
return err
|
|
}
|
|
|
|
const updateUISetting = `-- name: UpdateUISetting :exec
|
|
UPDATE "uiSettings"
|
|
SET value = $2, "updatedAt" = NOW()
|
|
WHERE id = $1 AND "isDeleted" = FALSE
|
|
`
|
|
|
|
type UpdateUISettingParams struct {
|
|
ID uuid.UUID `db:"id"`
|
|
Value []byte `db:"value"`
|
|
}
|
|
|
|
// UpdateUISetting
|
|
//
|
|
// UPDATE "uiSettings"
|
|
// SET value = $2, "updatedAt" = NOW()
|
|
// WHERE id = $1 AND "isDeleted" = FALSE
|
|
func (q *Queries) UpdateUISetting(ctx context.Context, arg *UpdateUISettingParams) error {
|
|
_, err := q.db.Exec(ctx, updateUISetting, arg.ID, arg.Value)
|
|
return err
|
|
}
|