UPDATE: Submission module
All checks were successful
Build and Release / release (push) Successful in 1m14s

This commit is contained in:
2026-05-04 09:55:17 +07:00
parent f3f2e09fd5
commit bcc2e192c1
48 changed files with 2918 additions and 359 deletions

View File

@@ -204,3 +204,31 @@ func (q *Queries) SearchCommits(ctx context.Context, arg SearchCommitsParams) ([
}
return items, nil
}
const updateCommitSnapshot = `-- name: UpdateCommitSnapshot :one
UPDATE commits
SET snapshot_json = $2
WHERE id = $1
RETURNING id, project_id, snapshot_json, snapshot_hash, user_id, edit_summary, is_deleted, created_at
`
type UpdateCommitSnapshotParams struct {
ID pgtype.UUID `json:"id"`
SnapshotJson json.RawMessage `json:"snapshot_json"`
}
func (q *Queries) UpdateCommitSnapshot(ctx context.Context, arg UpdateCommitSnapshotParams) (Commit, error) {
row := q.db.QueryRow(ctx, updateCommitSnapshot, arg.ID, arg.SnapshotJson)
var i Commit
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.SnapshotJson,
&i.SnapshotHash,
&i.UserID,
&i.EditSummary,
&i.IsDeleted,
&i.CreatedAt,
)
return i, err
}

View File

@@ -13,27 +13,39 @@ import (
const createEntity = `-- name: CreateEntity :one
INSERT INTO entities (
name, description, thumbnail_url
id, name, slug, description, project_id, status
) VALUES (
$1, $2, $3
COALESCE($6::uuid, uuidv7()), $1, $2, $3, $4, $5
)
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
RETURNING id, project_id, name, slug, description, status, is_deleted, created_at, updated_at
`
type CreateEntityParams struct {
Name string `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
Name string `json:"name"`
Slug pgtype.Text `json:"slug"`
Description pgtype.Text `json:"description"`
ProjectID pgtype.UUID `json:"project_id"`
Status pgtype.Int2 `json:"status"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) CreateEntity(ctx context.Context, arg CreateEntityParams) (Entity, error) {
row := q.db.QueryRow(ctx, createEntity, arg.Name, arg.Description, arg.ThumbnailUrl)
row := q.db.QueryRow(ctx, createEntity,
arg.Name,
arg.Slug,
arg.Description,
arg.ProjectID,
arg.Status,
arg.ID,
)
var i Entity
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.ThumbnailUrl,
&i.Status,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
@@ -41,6 +53,17 @@ func (q *Queries) CreateEntity(ctx context.Context, arg CreateEntityParams) (Ent
return i, err
}
const deleteEntitiesByIDs = `-- name: DeleteEntitiesByIDs :exec
UPDATE entities
SET is_deleted = true
WHERE id = ANY($1::uuid[])
`
func (q *Queries) DeleteEntitiesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteEntitiesByIDs, dollar_1)
return err
}
const deleteEntity = `-- name: DeleteEntity :exec
UPDATE entities
SET
@@ -54,7 +77,7 @@ func (q *Queries) DeleteEntity(ctx context.Context, id pgtype.UUID) error {
}
const getEntitiesByIDs = `-- name: GetEntitiesByIDs :many
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at FROM entities WHERE id = ANY($1::uuid[]) AND is_deleted = false
SELECT id, project_id, name, slug, description, status, is_deleted, created_at, updated_at FROM entities WHERE id = ANY($1::uuid[]) AND is_deleted = false
`
func (q *Queries) GetEntitiesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Entity, error) {
@@ -68,9 +91,47 @@ func (q *Queries) GetEntitiesByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
var i Entity
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.ThumbnailUrl,
&i.Status,
&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 getEntitiesByProjectId = `-- name: GetEntitiesByProjectId :many
SELECT id, project_id, name, slug, description, status, is_deleted, created_at, updated_at
FROM entities
WHERE project_id = $1 AND is_deleted = false
`
func (q *Queries) GetEntitiesByProjectId(ctx context.Context, projectID pgtype.UUID) ([]Entity, error) {
rows, err := q.db.Query(ctx, getEntitiesByProjectId, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Entity{}
for rows.Next() {
var i Entity
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.Status,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
@@ -86,7 +147,7 @@ func (q *Queries) GetEntitiesByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
}
const getEntityById = `-- name: GetEntityById :one
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
SELECT id, project_id, name, slug, description, status, is_deleted, created_at, updated_at
FROM entities
WHERE id = $1 AND is_deleted = false
`
@@ -96,9 +157,11 @@ func (q *Queries) GetEntityById(ctx context.Context, id pgtype.UUID) (Entity, er
var i Entity
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.ThumbnailUrl,
&i.Status,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
@@ -107,23 +170,30 @@ func (q *Queries) GetEntityById(ctx context.Context, id pgtype.UUID) (Entity, er
}
const searchEntities = `-- name: SearchEntities :many
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
SELECT id, project_id, name, slug, description, status, is_deleted, created_at, updated_at
FROM entities
WHERE is_deleted = false
AND name ILIKE '%' || $1::text || '%'
AND ($2::uuid IS NULL OR id < $2::uuid)
AND ($1::uuid IS NULL OR project_id = $1::uuid)
AND name ILIKE '%' || $2::text || '%'
AND ($3::uuid IS NULL OR id < $3::uuid)
ORDER BY id DESC
LIMIT $3
LIMIT $4
`
type SearchEntitiesParams struct {
ProjectID pgtype.UUID `json:"project_id"`
Name string `json:"name"`
CursorID pgtype.UUID `json:"cursor_id"`
LimitCount int32 `json:"limit_count"`
}
func (q *Queries) SearchEntities(ctx context.Context, arg SearchEntitiesParams) ([]Entity, error) {
rows, err := q.db.Query(ctx, searchEntities, arg.Name, arg.CursorID, arg.LimitCount)
rows, err := q.db.Query(ctx, searchEntities,
arg.ProjectID,
arg.Name,
arg.CursorID,
arg.LimitCount,
)
if err != nil {
return nil, err
}
@@ -133,9 +203,11 @@ func (q *Queries) SearchEntities(ctx context.Context, arg SearchEntitiesParams)
var i Entity
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.ThumbnailUrl,
&i.Status,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,
@@ -154,32 +226,40 @@ const updateEntity = `-- name: UpdateEntity :one
UPDATE entities
SET
name = COALESCE($1, name),
description = COALESCE($2, description),
thumbnail_url = COALESCE($3, thumbnail_url)
WHERE id = $4 AND is_deleted = false
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
slug = COALESCE($2, slug),
description = COALESCE($3, description),
project_id = COALESCE($4, project_id),
status = COALESCE($5, status)
WHERE id = $6 AND is_deleted = false
RETURNING id, project_id, name, slug, description, status, is_deleted, created_at, updated_at
`
type UpdateEntityParams struct {
Name pgtype.Text `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
ID pgtype.UUID `json:"id"`
Name pgtype.Text `json:"name"`
Slug pgtype.Text `json:"slug"`
Description pgtype.Text `json:"description"`
ProjectID pgtype.UUID `json:"project_id"`
Status pgtype.Int2 `json:"status"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateEntity(ctx context.Context, arg UpdateEntityParams) (Entity, error) {
row := q.db.QueryRow(ctx, updateEntity,
arg.Name,
arg.Slug,
arg.Description,
arg.ThumbnailUrl,
arg.ProjectID,
arg.Status,
arg.ID,
)
var i Entity
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Name,
&i.Slug,
&i.Description,
&i.ThumbnailUrl,
&i.Status,
&i.IsDeleted,
&i.CreatedAt,
&i.UpdatedAt,

View File

@@ -38,30 +38,42 @@ func (q *Queries) BulkDeleteEntityGeometriesByEntityId(ctx context.Context, enti
return items, nil
}
const bulkDeleteEntityGeometriesByGeometryID = `-- name: BulkDeleteEntityGeometriesByGeometryID :exec
DELETE FROM entity_geometries
WHERE geometry_id = $1
`
func (q *Queries) BulkDeleteEntityGeometriesByGeometryID(ctx context.Context, geometryID pgtype.UUID) error {
_, err := q.db.Exec(ctx, bulkDeleteEntityGeometriesByGeometryID, geometryID)
return err
}
const createEntityGeometries = `-- name: CreateEntityGeometries :exec
INSERT INTO entity_geometries (
entity_id, geometry_id
entity_id, geometry_id, project_id
)
SELECT $1, unnest($2::uuid[])
SELECT $1, unnest($3::uuid[]), $2
ON CONFLICT DO NOTHING
`
type CreateEntityGeometriesParams struct {
EntityID pgtype.UUID `json:"entity_id"`
ProjectID pgtype.UUID `json:"project_id"`
GeometryIds []pgtype.UUID `json:"geometry_ids"`
}
func (q *Queries) CreateEntityGeometries(ctx context.Context, arg CreateEntityGeometriesParams) error {
_, err := q.db.Exec(ctx, createEntityGeometries, arg.EntityID, arg.GeometryIds)
_, err := q.db.Exec(ctx, createEntityGeometries, arg.EntityID, arg.ProjectID, arg.GeometryIds)
return err
}
const createGeometry = `-- name: CreateGeometry :one
INSERT INTO geometries (
geo_type, draw_geometry, binding, time_start, time_end, bbox
id, geo_type, draw_geometry, binding, time_start, time_end, bbox, project_id
) VALUES (
$1, $2, $3, $4, $5, ST_MakeEnvelope($6::float8, $7::float8, $8::float8, $9::float8, 4326)
COALESCE($7::uuid, uuidv7()), $1, $2, $3, $4, $5, ST_MakeEnvelope($8::float8, $9::float8, $10::float8, $11::float8, 4326), $6
)
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end,
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end, project_id,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
`
@@ -72,6 +84,8 @@ type CreateGeometryParams struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
ID pgtype.UUID `json:"id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -85,6 +99,7 @@ type CreateGeometryRow struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -101,6 +116,8 @@ func (q *Queries) CreateGeometry(ctx context.Context, arg CreateGeometryParams)
arg.Binding,
arg.TimeStart,
arg.TimeEnd,
arg.ProjectID,
arg.ID,
arg.MinLng,
arg.MinLat,
arg.MaxLng,
@@ -114,6 +131,7 @@ func (q *Queries) CreateGeometry(ctx context.Context, arg CreateGeometryParams)
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
@@ -125,6 +143,42 @@ func (q *Queries) CreateGeometry(ctx context.Context, arg CreateGeometryParams)
return i, err
}
const deleteEntityGeometriesByProjectID = `-- name: DeleteEntityGeometriesByProjectID :exec
DELETE FROM entity_geometries
WHERE project_id = $1
`
func (q *Queries) DeleteEntityGeometriesByProjectID(ctx context.Context, projectID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteEntityGeometriesByProjectID, projectID)
return err
}
const deleteEntityGeometry = `-- name: DeleteEntityGeometry :exec
DELETE FROM entity_geometries
WHERE entity_id = $1 AND geometry_id = $2
`
type DeleteEntityGeometryParams struct {
EntityID pgtype.UUID `json:"entity_id"`
GeometryID pgtype.UUID `json:"geometry_id"`
}
func (q *Queries) DeleteEntityGeometry(ctx context.Context, arg DeleteEntityGeometryParams) error {
_, err := q.db.Exec(ctx, deleteEntityGeometry, arg.EntityID, arg.GeometryID)
return err
}
const deleteGeometriesByIDs = `-- name: DeleteGeometriesByIDs :exec
UPDATE geometries
SET is_deleted = true
WHERE id = ANY($1::uuid[])
`
func (q *Queries) DeleteGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteGeometriesByIDs, dollar_1)
return err
}
const deleteGeometry = `-- name: DeleteGeometry :exec
UPDATE geometries
SET
@@ -139,7 +193,7 @@ func (q *Queries) DeleteGeometry(ctx context.Context, id pgtype.UUID) error {
const getGeometriesByIDs = `-- name: GetGeometriesByIDs :many
SELECT
id, geo_type, draw_geometry, binding, time_start, time_end,
id, geo_type, draw_geometry, binding, time_start, time_end, project_id,
ST_XMin(bbox)::float8 as min_lng,
ST_YMin(bbox)::float8 as min_lat,
ST_XMax(bbox)::float8 as max_lng,
@@ -156,6 +210,7 @@ type GetGeometriesByIDsRow struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -181,6 +236,71 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
&i.MaxLat,
&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 getGeometriesByProjectId = `-- name: GetGeometriesByProjectId :many
SELECT
id, geo_type, draw_geometry, binding, time_start, time_end, project_id,
ST_XMin(bbox)::float8 as min_lng,
ST_YMin(bbox)::float8 as min_lat,
ST_XMax(bbox)::float8 as max_lng,
ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
FROM geometries
WHERE project_id = $1 AND is_deleted = false
`
type GetGeometriesByProjectIdRow struct {
ID pgtype.UUID `json:"id"`
GeoType int16 `json:"geo_type"`
DrawGeometry json.RawMessage `json:"draw_geometry"`
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
MaxLat float64 `json:"max_lat"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype.UUID) ([]GetGeometriesByProjectIdRow, error) {
rows, err := q.db.Query(ctx, getGeometriesByProjectId, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetGeometriesByProjectIdRow{}
for rows.Next() {
var i GetGeometriesByProjectIdRow
if err := rows.Scan(
&i.ID,
&i.GeoType,
&i.DrawGeometry,
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
@@ -200,7 +320,7 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
}
const getGeometryById = `-- name: GetGeometryById :one
SELECT id, geo_type, draw_geometry, binding, time_start, time_end,
SELECT id, geo_type, draw_geometry, binding, time_start, time_end, project_id,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
FROM geometries
@@ -214,6 +334,7 @@ type GetGeometryByIdRow struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -233,6 +354,7 @@ func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeome
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
@@ -246,7 +368,7 @@ func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeome
const searchGeometries = `-- name: SearchGeometries :many
SELECT
g.id, g.geo_type, g.draw_geometry, g.binding, g.time_start, g.time_end,
g.id, g.geo_type, g.draw_geometry, g.binding, g.time_start, g.time_end, g.project_id,
ST_XMin(g.bbox)::float8 as min_lng,
ST_YMin(g.bbox)::float8 as min_lat,
ST_XMax(g.bbox)::float8 as max_lng,
@@ -254,36 +376,38 @@ SELECT
g.is_deleted, g.created_at, g.updated_at
FROM geometries g
WHERE g.is_deleted = false
AND ($1::uuid IS NULL OR g.project_id = $1::uuid)
AND (
$1::float8 IS NULL OR
$2::float8 IS NULL OR
$3::float8 IS NULL OR
$4::float8 IS NULL OR
$5::float8 IS NULL OR
g.bbox && ST_MakeEnvelope(
$1::float8,
$2::float8,
$3::float8,
$4::float8,
$5::float8,
4326
)
)
AND (
$5::int IS NULL OR
(g.time_start <= $5::int AND g.time_end >= $5::int)
$6::int IS NULL OR
(g.time_start <= $6::int AND g.time_end >= $6::int)
)
AND (
$6::uuid IS NULL OR
$7::uuid IS NULL OR
EXISTS (
SELECT 1
FROM entity_geometries eg
WHERE eg.geometry_id = g.id
AND eg.entity_id = $6::uuid
AND eg.entity_id = $7::uuid
)
)
ORDER BY g.id DESC
`
type SearchGeometriesParams struct {
ProjectID pgtype.UUID `json:"project_id"`
SearchMinLng pgtype.Float8 `json:"search_min_lng"`
SearchMinLat pgtype.Float8 `json:"search_min_lat"`
SearchMaxLng pgtype.Float8 `json:"search_max_lng"`
@@ -299,6 +423,7 @@ type SearchGeometriesRow struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -310,6 +435,7 @@ type SearchGeometriesRow struct {
func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesParams) ([]SearchGeometriesRow, error) {
rows, err := q.db.Query(ctx, searchGeometries,
arg.ProjectID,
arg.SearchMinLng,
arg.SearchMinLat,
arg.SearchMaxLng,
@@ -331,6 +457,7 @@ func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesPara
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,
@@ -357,14 +484,15 @@ SET
binding = COALESCE($3, binding),
time_start = COALESCE($4, time_start),
time_end = COALESCE($5, time_end),
project_id = COALESCE($6, project_id),
bbox = CASE
WHEN $6::boolean = true THEN
ST_MakeEnvelope($7::float8, $8::float8, $9::float8, $10::float8, 4326)
WHEN $7::boolean = true THEN
ST_MakeEnvelope($8::float8, $9::float8, $10::float8, $11::float8, 4326)
ELSE bbox
END,
updated_at = now()
WHERE id = $11 AND is_deleted = false
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end,
WHERE id = $12 AND is_deleted = false
RETURNING id, geo_type, draw_geometry, binding, time_start, time_end, project_id,
ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat,
is_deleted, created_at, updated_at
`
@@ -375,6 +503,7 @@ type UpdateGeometryParams struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
UpdateBbox pgtype.Bool `json:"update_bbox"`
MinLng pgtype.Float8 `json:"min_lng"`
MinLat pgtype.Float8 `json:"min_lat"`
@@ -390,6 +519,7 @@ type UpdateGeometryRow struct {
Binding []byte `json:"binding"`
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
ProjectID pgtype.UUID `json:"project_id"`
MinLng float64 `json:"min_lng"`
MinLat float64 `json:"min_lat"`
MaxLng float64 `json:"max_lng"`
@@ -406,6 +536,7 @@ func (q *Queries) UpdateGeometry(ctx context.Context, arg UpdateGeometryParams)
arg.Binding,
arg.TimeStart,
arg.TimeEnd,
arg.ProjectID,
arg.UpdateBbox,
arg.MinLng,
arg.MinLat,
@@ -421,6 +552,7 @@ func (q *Queries) UpdateGeometry(ctx context.Context, arg UpdateGeometryParams)
&i.Binding,
&i.TimeStart,
&i.TimeEnd,
&i.ProjectID,
&i.MinLng,
&i.MinLat,
&i.MaxLng,

View File

@@ -22,23 +22,27 @@ type Commit struct {
}
type Entity struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Description pgtype.Text `json:"description"`
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ID pgtype.UUID `json:"id"`
ProjectID pgtype.UUID `json:"project_id"`
Name string `json:"name"`
Slug pgtype.Text `json:"slug"`
Description pgtype.Text `json:"description"`
Status pgtype.Int2 `json:"status"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type EntityGeometry struct {
EntityID pgtype.UUID `json:"entity_id"`
GeometryID pgtype.UUID `json:"geometry_id"`
ProjectID pgtype.UUID `json:"project_id"`
}
type EntityWiki struct {
EntityID pgtype.UUID `json:"entity_id"`
WikiID pgtype.UUID `json:"wiki_id"`
EntityID pgtype.UUID `json:"entity_id"`
WikiID pgtype.UUID `json:"wiki_id"`
ProjectID pgtype.UUID `json:"project_id"`
}
type Geometry struct {
@@ -49,6 +53,7 @@ type Geometry struct {
TimeStart pgtype.Int4 `json:"time_start"`
TimeEnd pgtype.Int4 `json:"time_end"`
Bbox interface{} `json:"bbox"`
ProjectID pgtype.UUID `json:"project_id"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
@@ -161,8 +166,9 @@ type VerificationMedia struct {
type Wiki struct {
ID pgtype.UUID `json:"id"`
ProjectID pgtype.UUID `json:"project_id"`
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
Content []byte `json:"content"`
IsDeleted bool `json:"is_deleted"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`

View File

@@ -136,7 +136,7 @@ SELECT
'avatar_url', up.avatar_url
)::json AS user,
'[]'::json AS commits,
'{}'::uuid[] AS submission_ids,
'[]'::json AS submissions,
'[]'::json AS members
FROM inserted_project p
JOIN users u ON p.user_id = u.id
@@ -163,7 +163,7 @@ type CreateProjectRow struct {
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
User []byte `json:"user"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
Members []byte `json:"members"`
}
@@ -188,7 +188,7 @@ func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (C
&i.UpdatedAt,
&i.User,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.Members,
)
return i, err
@@ -215,9 +215,9 @@ SELECT
'[]'
)::json AS commits,
COALESCE(
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
'{}'
)::uuid[] AS submission_ids,
(SELECT json_agg(json_build_object('id', s.id, 'status', s.status)) FROM submissions s WHERE s.project_id = p.id),
'[]'
)::json AS submissions,
json_build_object(
'id', u.id,
'email', u.email,
@@ -254,7 +254,7 @@ type GetProjectByIdRow struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
User []byte `json:"user"`
Members []byte `json:"members"`
}
@@ -274,7 +274,7 @@ func (q *Queries) GetProjectById(ctx context.Context, id pgtype.UUID) (GetProjec
&i.CreatedAt,
&i.UpdatedAt,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.User,
&i.Members,
)
@@ -289,7 +289,10 @@ SELECT
FROM commits c WHERE c.project_id = p.id AND c.is_deleted = false),
'[]'
)::json AS commits,
COALESCE((SELECT array_agg(id) FROM submissions WHERE project_id = p.id), '{}')::uuid[] AS submission_ids,
COALESCE(
(SELECT json_agg(json_build_object('id', s.id, 'status', s.status)) FROM submissions s WHERE s.project_id = p.id),
'[]'
)::json AS submissions,
json_build_object(
'id', u.id,
'email', u.email,
@@ -326,7 +329,7 @@ type GetProjectsByIDsRow struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
User []byte `json:"user"`
Members []byte `json:"members"`
}
@@ -352,7 +355,7 @@ func (q *Queries) GetProjectsByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
&i.CreatedAt,
&i.UpdatedAt,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.User,
&i.Members,
); err != nil {
@@ -375,9 +378,9 @@ SELECT
'[]'
)::json AS commits,
COALESCE(
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
'{}'
)::uuid[] AS submission_ids,
(SELECT json_agg(json_build_object('id', s.id, 'status', s.status)) FROM submissions s WHERE s.project_id = p.id),
'[]'
)::json AS submissions,
json_build_object(
'id', u.id,
'email', u.email,
@@ -424,7 +427,7 @@ type GetProjectsByUserIdRow struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
User []byte `json:"user"`
Members []byte `json:"members"`
}
@@ -450,7 +453,7 @@ func (q *Queries) GetProjectsByUserId(ctx context.Context, arg GetProjectsByUser
&i.CreatedAt,
&i.UpdatedAt,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.User,
&i.Members,
); err != nil {
@@ -488,9 +491,9 @@ SELECT
'[]'
)::json AS commits,
COALESCE(
(SELECT array_agg(id) FROM submissions WHERE project_id = p.id),
'{}'
)::uuid[] AS submission_ids,
(SELECT json_agg(json_build_object('id', s.id, 'status', s.status)) FROM submissions s WHERE s.project_id = p.id),
'[]'
)::json AS submissions,
json_build_object(
'id', u.id,
'email', u.email,
@@ -561,7 +564,7 @@ type SearchProjectsRow struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
User []byte `json:"user"`
Members []byte `json:"members"`
}
@@ -597,7 +600,7 @@ func (q *Queries) SearchProjects(ctx context.Context, arg SearchProjectsParams)
&i.CreatedAt,
&i.UpdatedAt,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.User,
&i.Members,
); err != nil {
@@ -654,7 +657,10 @@ RETURNING
FROM commits c WHERE c.project_id = projects.id AND c.is_deleted = false),
'[]'
)::json AS commits,
COALESCE((SELECT array_agg(id) FROM submissions WHERE project_id = projects.id), '{}')::uuid[] AS submission_ids,
COALESCE(
(SELECT json_agg(json_build_object('id', s.id, 'status', s.status)) FROM submissions s WHERE s.project_id = projects.id),
'[]'
)::json AS submissions,
COALESCE(
(SELECT json_agg(json_build_object(
'user_id', pm.user_id, 'role', pm.role,
@@ -690,7 +696,7 @@ type UpdateProjectRow struct {
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
User []byte `json:"user"`
Commits []byte `json:"commits"`
SubmissionIds []pgtype.UUID `json:"submission_ids"`
Submissions []byte `json:"submissions"`
Members []byte `json:"members"`
}
@@ -717,7 +723,7 @@ func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (U
&i.UpdatedAt,
&i.User,
&i.Commits,
&i.SubmissionIds,
&i.Submissions,
&i.Members,
)
return i, err

View File

@@ -37,42 +37,62 @@ func (q *Queries) BulkDeleteEntityWikisByEntityId(ctx context.Context, entityID
return items, nil
}
const bulkDeleteEntityWikisByWikiID = `-- name: BulkDeleteEntityWikisByWikiID :exec
DELETE FROM entity_wikis
WHERE wiki_id = $1
`
func (q *Queries) BulkDeleteEntityWikisByWikiID(ctx context.Context, wikiID pgtype.UUID) error {
_, err := q.db.Exec(ctx, bulkDeleteEntityWikisByWikiID, wikiID)
return err
}
const createEntityWikis = `-- name: CreateEntityWikis :exec
INSERT INTO entity_wikis (
entity_id, wiki_id
entity_id, wiki_id, project_id
)
SELECT $1, unnest($2::uuid[])
SELECT $1, unnest($3::uuid[]), $2
ON CONFLICT DO NOTHING
`
type CreateEntityWikisParams struct {
EntityID pgtype.UUID `json:"entity_id"`
WikiIds []pgtype.UUID `json:"wiki_ids"`
EntityID pgtype.UUID `json:"entity_id"`
ProjectID pgtype.UUID `json:"project_id"`
WikiIds []pgtype.UUID `json:"wiki_ids"`
}
func (q *Queries) CreateEntityWikis(ctx context.Context, arg CreateEntityWikisParams) error {
_, err := q.db.Exec(ctx, createEntityWikis, arg.EntityID, arg.WikiIds)
_, err := q.db.Exec(ctx, createEntityWikis, arg.EntityID, arg.ProjectID, arg.WikiIds)
return err
}
const createWiki = `-- name: CreateWiki :one
INSERT INTO wikis (
title, content
id, title, content, project_id
) VALUES (
$1, $2
COALESCE($4::uuid, uuidv7()), $1, $2, $3
)
RETURNING id, title, content, is_deleted, created_at, updated_at
RETURNING id, project_id, title, content, is_deleted, created_at, updated_at
`
type CreateWikiParams struct {
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
Title pgtype.Text `json:"title"`
Content []byte `json:"content"`
ProjectID pgtype.UUID `json:"project_id"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) CreateWiki(ctx context.Context, arg CreateWikiParams) (Wiki, error) {
row := q.db.QueryRow(ctx, createWiki, arg.Title, arg.Content)
row := q.db.QueryRow(ctx, createWiki,
arg.Title,
arg.Content,
arg.ProjectID,
arg.ID,
)
var i Wiki
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&i.IsDeleted,
@@ -82,6 +102,31 @@ func (q *Queries) CreateWiki(ctx context.Context, arg CreateWikiParams) (Wiki, e
return i, err
}
const deleteEntityWiki = `-- name: DeleteEntityWiki :exec
DELETE FROM entity_wikis
WHERE entity_id = $1 AND wiki_id = $2
`
type DeleteEntityWikiParams struct {
EntityID pgtype.UUID `json:"entity_id"`
WikiID pgtype.UUID `json:"wiki_id"`
}
func (q *Queries) DeleteEntityWiki(ctx context.Context, arg DeleteEntityWikiParams) error {
_, err := q.db.Exec(ctx, deleteEntityWiki, arg.EntityID, arg.WikiID)
return err
}
const deleteEntityWikisByProjectID = `-- name: DeleteEntityWikisByProjectID :exec
DELETE FROM entity_wikis
WHERE project_id = $1
`
func (q *Queries) DeleteEntityWikisByProjectID(ctx context.Context, projectID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteEntityWikisByProjectID, projectID)
return err
}
const deleteWiki = `-- name: DeleteWiki :exec
UPDATE wikis
SET
@@ -94,8 +139,19 @@ func (q *Queries) DeleteWiki(ctx context.Context, id pgtype.UUID) error {
return err
}
const deleteWikisByIDs = `-- name: DeleteWikisByIDs :exec
UPDATE wikis
SET is_deleted = true
WHERE id = ANY($1::uuid[])
`
func (q *Queries) DeleteWikisByIDs(ctx context.Context, dollar_1 []pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteWikisByIDs, dollar_1)
return err
}
const getWikiById = `-- name: GetWikiById :one
SELECT id, title, content, is_deleted, created_at, updated_at
SELECT id, project_id, title, content, is_deleted, created_at, updated_at
FROM wikis
WHERE id = $1 AND is_deleted = false
`
@@ -105,6 +161,7 @@ func (q *Queries) GetWikiById(ctx context.Context, id pgtype.UUID) (Wiki, error)
var i Wiki
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&i.IsDeleted,
@@ -115,7 +172,7 @@ func (q *Queries) GetWikiById(ctx context.Context, id pgtype.UUID) (Wiki, error)
}
const getWikisByIDs = `-- name: GetWikisByIDs :many
SELECT id, title, content, is_deleted, created_at, updated_at FROM wikis WHERE id = ANY($1::uuid[]) AND is_deleted = false
SELECT id, project_id, title, content, is_deleted, created_at, updated_at FROM wikis WHERE id = ANY($1::uuid[]) AND is_deleted = false
`
func (q *Queries) GetWikisByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Wiki, error) {
@@ -129,6 +186,41 @@ func (q *Queries) GetWikisByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]
var i Wiki
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&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 getWikisByProjectId = `-- name: GetWikisByProjectId :many
SELECT id, project_id, title, content, is_deleted, created_at, updated_at
FROM wikis
WHERE project_id = $1 AND is_deleted = false
`
func (q *Queries) GetWikisByProjectId(ctx context.Context, projectID pgtype.UUID) ([]Wiki, error) {
rows, err := q.db.Query(ctx, getWikisByProjectId, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Wiki{}
for rows.Next() {
var i Wiki
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&i.IsDeleted,
@@ -146,26 +238,28 @@ func (q *Queries) GetWikisByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]
}
const searchWikis = `-- name: SearchWikis :many
SELECT w.id, w.title, w.content, w.is_deleted, w.created_at, w.updated_at
SELECT w.id, w.project_id, w.title, w.content, w.is_deleted, w.created_at, w.updated_at
FROM wikis w
WHERE w.is_deleted = false
AND w.title ILIKE '%' || $1::text || '%'
AND ($1::uuid IS NULL OR w.project_id = $1::uuid)
AND w.title ILIKE '%' || $2::text || '%'
AND (
$2::uuid IS NULL OR
$3::uuid IS NULL OR
EXISTS (
SELECT 1
FROM entity_wikis ew
WHERE ew.wiki_id = w.id
AND ew.entity_id = $2::uuid
AND ew.entity_id = $3::uuid
)
)
AND ($3::uuid IS NULL OR w.id < $3::uuid)
AND ($4::uuid IS NULL OR w.id < $4::uuid)
ORDER BY w.id DESC
LIMIT $4
LIMIT $5
`
type SearchWikisParams struct {
ProjectID pgtype.UUID `json:"project_id"`
Title string `json:"title"`
EntityID pgtype.UUID `json:"entity_id"`
CursorID pgtype.UUID `json:"cursor_id"`
@@ -174,6 +268,7 @@ type SearchWikisParams struct {
func (q *Queries) SearchWikis(ctx context.Context, arg SearchWikisParams) ([]Wiki, error) {
rows, err := q.db.Query(ctx, searchWikis,
arg.ProjectID,
arg.Title,
arg.EntityID,
arg.CursorID,
@@ -188,6 +283,7 @@ func (q *Queries) SearchWikis(ctx context.Context, arg SearchWikisParams) ([]Wik
var i Wiki
if err := rows.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&i.IsDeleted,
@@ -208,22 +304,30 @@ const updateWiki = `-- name: UpdateWiki :one
UPDATE wikis
SET
title = COALESCE($1, title),
content = COALESCE($2, content)
WHERE id = $3 AND is_deleted = false
RETURNING id, title, content, is_deleted, created_at, updated_at
content = COALESCE($2, content),
project_id = COALESCE($3, project_id)
WHERE id = $4 AND is_deleted = false
RETURNING id, project_id, title, content, is_deleted, created_at, updated_at
`
type UpdateWikiParams struct {
Title pgtype.Text `json:"title"`
Content pgtype.Text `json:"content"`
ID pgtype.UUID `json:"id"`
Title pgtype.Text `json:"title"`
Content []byte `json:"content"`
ProjectID pgtype.UUID `json:"project_id"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateWiki(ctx context.Context, arg UpdateWikiParams) (Wiki, error) {
row := q.db.QueryRow(ctx, updateWiki, arg.Title, arg.Content, arg.ID)
row := q.db.QueryRow(ctx, updateWiki,
arg.Title,
arg.Content,
arg.ProjectID,
arg.ID,
)
var i Wiki
err := row.Scan(
&i.ID,
&i.ProjectID,
&i.Title,
&i.Content,
&i.IsDeleted,