feat: implement geometry and battle replay repositories, services, and associated database schemas
Build and Release / release (push) Successful in 1m23s
Build and Release / release (push) Successful in 1m23s
This commit is contained in:
+70
-28
@@ -9,11 +9,17 @@ RETURNING id, geo_type, draw_geometry, bound_with, time_start, time_end, project
|
|||||||
is_deleted, created_at, updated_at;
|
is_deleted, created_at, updated_at;
|
||||||
|
|
||||||
-- name: GetGeometryById :one
|
-- name: GetGeometryById :one
|
||||||
SELECT id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.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,
|
ST_XMin(geometries.bbox)::float8 as min_lng, ST_YMin(geometries.bbox)::float8 as min_lat, ST_XMax(geometries.bbox)::float8 as max_lng, ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE id = $1 AND is_deleted = false;
|
WHERE geometries.id = $1 AND geometries.is_deleted = false;
|
||||||
|
|
||||||
-- name: UpdateGeometry :one
|
-- name: UpdateGeometry :one
|
||||||
UPDATE geometries
|
UPDATE geometries
|
||||||
@@ -52,7 +58,13 @@ SELECT
|
|||||||
ST_YMin(g.bbox)::float8 as min_lat,
|
ST_YMin(g.bbox)::float8 as min_lat,
|
||||||
ST_XMax(g.bbox)::float8 as max_lng,
|
ST_XMax(g.bbox)::float8 as max_lng,
|
||||||
ST_YMax(g.bbox)::float8 as max_lat,
|
ST_YMax(g.bbox)::float8 as max_lat,
|
||||||
g.is_deleted, g.created_at, g.updated_at
|
g.is_deleted, g.created_at, g.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries g
|
FROM geometries g
|
||||||
WHERE g.is_deleted = false
|
WHERE g.is_deleted = false
|
||||||
AND (sqlc.narg('project_id')::uuid IS NULL OR g.project_id = sqlc.narg('project_id')::uuid)
|
AND (sqlc.narg('project_id')::uuid IS NULL OR g.project_id = sqlc.narg('project_id')::uuid)
|
||||||
@@ -116,7 +128,13 @@ SELECT
|
|||||||
g.draw_geometry,
|
g.draw_geometry,
|
||||||
g.bound_with,
|
g.bound_with,
|
||||||
g.time_start,
|
g.time_start,
|
||||||
g.time_end
|
g.time_end,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM matched_entities me
|
FROM matched_entities me
|
||||||
LEFT JOIN entity_geometries eg
|
LEFT JOIN entity_geometries eg
|
||||||
ON eg.entity_id = me.id
|
ON eg.entity_id = me.id
|
||||||
@@ -143,25 +161,37 @@ WHERE project_id = $1;
|
|||||||
|
|
||||||
-- name: GetGeometriesByIDs :many
|
-- name: GetGeometriesByIDs :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE id = ANY($1::uuid[]) AND is_deleted = false;
|
WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false;
|
||||||
|
|
||||||
-- name: GetGeometriesByProjectId :many
|
-- name: GetGeometriesByProjectId :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE project_id = $1 AND is_deleted = false;
|
WHERE geometries.project_id = $1 AND geometries.is_deleted = false;
|
||||||
|
|
||||||
-- name: DeleteGeometriesByIDs :exec
|
-- name: DeleteGeometriesByIDs :exec
|
||||||
UPDATE geometries
|
UPDATE geometries
|
||||||
@@ -186,7 +216,13 @@ SELECT
|
|||||||
g.draw_geometry,
|
g.draw_geometry,
|
||||||
g.bound_with,
|
g.bound_with,
|
||||||
g.time_start,
|
g.time_start,
|
||||||
g.time_end
|
g.time_end,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM (
|
FROM (
|
||||||
SELECT unnest(@entity_ids::uuid[]) as eid, unnest(@geometry_ids::uuid[]) as gid
|
SELECT unnest(@entity_ids::uuid[]) as eid, unnest(@geometry_ids::uuid[]) as gid
|
||||||
) as pairs
|
) as pairs
|
||||||
@@ -198,11 +234,17 @@ AND g.is_deleted = false;
|
|||||||
|
|
||||||
-- name: GetGeometriesByBoundWith :many
|
-- name: GetGeometriesByBoundWith :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE bound_with = $1 AND is_deleted = false;
|
WHERE geometries.bound_with = $1 AND geometries.is_deleted = false;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type GeometryResponse struct {
|
|||||||
Bbox *Bbox `json:"bbox,omitempty"`
|
Bbox *Bbox `json:"bbox,omitempty"`
|
||||||
ProjectID string `json:"project_id"`
|
ProjectID string `json:"project_id"`
|
||||||
IsDeleted bool `json:"is_deleted,omitempty"`
|
IsDeleted bool `json:"is_deleted,omitempty"`
|
||||||
|
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ type EntityGeometrySearchGeo struct {
|
|||||||
BoundWith *string `json:"bound_with,omitempty"`
|
BoundWith *string `json:"bound_with,omitempty"`
|
||||||
TimeStart *int32 `json:"time_start,omitempty"`
|
TimeStart *int32 `json:"time_start,omitempty"`
|
||||||
TimeEnd *int32 `json:"time_end,omitempty"`
|
TimeEnd *int32 `json:"time_end,omitempty"`
|
||||||
|
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,13 @@ SELECT
|
|||||||
g.draw_geometry,
|
g.draw_geometry,
|
||||||
g.bound_with,
|
g.bound_with,
|
||||||
g.time_start,
|
g.time_start,
|
||||||
g.time_end
|
g.time_end,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM (
|
FROM (
|
||||||
SELECT unnest($1::uuid[]) as eid, unnest($2::uuid[]) as gid
|
SELECT unnest($1::uuid[]) as eid, unnest($2::uuid[]) as gid
|
||||||
) as pairs
|
) as pairs
|
||||||
@@ -227,6 +233,7 @@ type GetEntityGeometriesByPairsRow struct {
|
|||||||
BoundWith pgtype.UUID `json:"bound_with"`
|
BoundWith pgtype.UUID `json:"bound_with"`
|
||||||
TimeStart pgtype.Int4 `json:"time_start"`
|
TimeStart pgtype.Int4 `json:"time_start"`
|
||||||
TimeEnd pgtype.Int4 `json:"time_end"`
|
TimeEnd pgtype.Int4 `json:"time_end"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityGeometriesByPairsParams) ([]GetEntityGeometriesByPairsRow, error) {
|
func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityGeometriesByPairsParams) ([]GetEntityGeometriesByPairsRow, error) {
|
||||||
@@ -248,6 +255,7 @@ func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityG
|
|||||||
&i.BoundWith,
|
&i.BoundWith,
|
||||||
&i.TimeStart,
|
&i.TimeStart,
|
||||||
&i.TimeEnd,
|
&i.TimeEnd,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -261,14 +269,20 @@ func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityG
|
|||||||
|
|
||||||
const getGeometriesByBoundWith = `-- name: GetGeometriesByBoundWith :many
|
const getGeometriesByBoundWith = `-- name: GetGeometriesByBoundWith :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE bound_with = $1 AND is_deleted = false
|
WHERE geometries.bound_with = $1 AND geometries.is_deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetGeometriesByBoundWithRow struct {
|
type GetGeometriesByBoundWithRow struct {
|
||||||
@@ -286,6 +300,7 @@ type GetGeometriesByBoundWithRow struct {
|
|||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype.UUID) ([]GetGeometriesByBoundWithRow, error) {
|
func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype.UUID) ([]GetGeometriesByBoundWithRow, error) {
|
||||||
@@ -312,6 +327,7 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype
|
|||||||
&i.IsDeleted,
|
&i.IsDeleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -325,14 +341,20 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype
|
|||||||
|
|
||||||
const getGeometriesByIDs = `-- name: GetGeometriesByIDs :many
|
const getGeometriesByIDs = `-- name: GetGeometriesByIDs :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetGeometriesByIDsRow struct {
|
type GetGeometriesByIDsRow struct {
|
||||||
@@ -350,6 +372,7 @@ type GetGeometriesByIDsRow struct {
|
|||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]GetGeometriesByIDsRow, error) {
|
func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]GetGeometriesByIDsRow, error) {
|
||||||
@@ -376,6 +399,7 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
|
|||||||
&i.IsDeleted,
|
&i.IsDeleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -389,14 +413,20 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
|
|||||||
|
|
||||||
const getGeometriesByProjectId = `-- name: GetGeometriesByProjectId :many
|
const getGeometriesByProjectId = `-- name: GetGeometriesByProjectId :many
|
||||||
SELECT
|
SELECT
|
||||||
id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||||
ST_XMin(bbox)::float8 as min_lng,
|
ST_XMin(geometries.bbox)::float8 as min_lng,
|
||||||
ST_YMin(bbox)::float8 as min_lat,
|
ST_YMin(geometries.bbox)::float8 as min_lat,
|
||||||
ST_XMax(bbox)::float8 as max_lng,
|
ST_XMax(geometries.bbox)::float8 as max_lng,
|
||||||
ST_YMax(bbox)::float8 as max_lat,
|
ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE project_id = $1 AND is_deleted = false
|
WHERE geometries.project_id = $1 AND geometries.is_deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetGeometriesByProjectIdRow struct {
|
type GetGeometriesByProjectIdRow struct {
|
||||||
@@ -414,6 +444,7 @@ type GetGeometriesByProjectIdRow struct {
|
|||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype.UUID) ([]GetGeometriesByProjectIdRow, error) {
|
func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype.UUID) ([]GetGeometriesByProjectIdRow, error) {
|
||||||
@@ -440,6 +471,7 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype
|
|||||||
&i.IsDeleted,
|
&i.IsDeleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -452,11 +484,17 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getGeometryById = `-- name: GetGeometryById :one
|
const getGeometryById = `-- name: GetGeometryById :one
|
||||||
SELECT id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id,
|
SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.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,
|
ST_XMin(geometries.bbox)::float8 as min_lng, ST_YMin(geometries.bbox)::float8 as min_lat, ST_XMax(geometries.bbox)::float8 as max_lng, ST_YMax(geometries.bbox)::float8 as max_lat,
|
||||||
is_deleted, created_at, updated_at
|
geometries.is_deleted, geometries.created_at, geometries.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = geometries.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries
|
FROM geometries
|
||||||
WHERE id = $1 AND is_deleted = false
|
WHERE geometries.id = $1 AND geometries.is_deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetGeometryByIdRow struct {
|
type GetGeometryByIdRow struct {
|
||||||
@@ -474,6 +512,7 @@ type GetGeometryByIdRow struct {
|
|||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeometryByIdRow, error) {
|
func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeometryByIdRow, error) {
|
||||||
@@ -494,6 +533,7 @@ func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeome
|
|||||||
&i.IsDeleted,
|
&i.IsDeleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ReplayIds,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -505,7 +545,13 @@ SELECT
|
|||||||
ST_YMin(g.bbox)::float8 as min_lat,
|
ST_YMin(g.bbox)::float8 as min_lat,
|
||||||
ST_XMax(g.bbox)::float8 as max_lng,
|
ST_XMax(g.bbox)::float8 as max_lng,
|
||||||
ST_YMax(g.bbox)::float8 as max_lat,
|
ST_YMax(g.bbox)::float8 as max_lat,
|
||||||
g.is_deleted, g.created_at, g.updated_at
|
g.is_deleted, g.created_at, g.updated_at,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM geometries g
|
FROM geometries g
|
||||||
WHERE g.is_deleted = false
|
WHERE g.is_deleted = false
|
||||||
AND ($1::uuid IS NULL OR g.project_id = $1::uuid)
|
AND ($1::uuid IS NULL OR g.project_id = $1::uuid)
|
||||||
@@ -576,6 +622,7 @@ type SearchGeometriesRow struct {
|
|||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesParams) ([]SearchGeometriesRow, error) {
|
func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesParams) ([]SearchGeometriesRow, error) {
|
||||||
@@ -613,6 +660,7 @@ func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesPara
|
|||||||
&i.IsDeleted,
|
&i.IsDeleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -646,7 +694,13 @@ SELECT
|
|||||||
g.draw_geometry,
|
g.draw_geometry,
|
||||||
g.bound_with,
|
g.bound_with,
|
||||||
g.time_start,
|
g.time_start,
|
||||||
g.time_end
|
g.time_end,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT ARRAY_AGG(br.id) FROM battle_replays br
|
||||||
|
WHERE br.geometry_id = g.id
|
||||||
|
AND br.is_deleted = false),
|
||||||
|
'{}'::uuid[]
|
||||||
|
)::uuid[] AS replay_ids
|
||||||
FROM matched_entities me
|
FROM matched_entities me
|
||||||
LEFT JOIN entity_geometries eg
|
LEFT JOIN entity_geometries eg
|
||||||
ON eg.entity_id = me.id
|
ON eg.entity_id = me.id
|
||||||
@@ -672,6 +726,7 @@ type SearchGeometriesByEntityNameRow struct {
|
|||||||
BoundWith pgtype.UUID `json:"bound_with"`
|
BoundWith pgtype.UUID `json:"bound_with"`
|
||||||
TimeStart pgtype.Int4 `json:"time_start"`
|
TimeStart pgtype.Int4 `json:"time_start"`
|
||||||
TimeEnd pgtype.Int4 `json:"time_end"`
|
TimeEnd pgtype.Int4 `json:"time_end"`
|
||||||
|
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) SearchGeometriesByEntityName(ctx context.Context, arg SearchGeometriesByEntityNameParams) ([]SearchGeometriesByEntityNameRow, error) {
|
func (q *Queries) SearchGeometriesByEntityName(ctx context.Context, arg SearchGeometriesByEntityNameParams) ([]SearchGeometriesByEntityNameRow, error) {
|
||||||
@@ -693,6 +748,7 @@ func (q *Queries) SearchGeometriesByEntityName(ctx context.Context, arg SearchGe
|
|||||||
&i.BoundWith,
|
&i.BoundWith,
|
||||||
&i.TimeStart,
|
&i.TimeStart,
|
||||||
&i.TimeEnd,
|
&i.TimeEnd,
|
||||||
|
&i.ReplayIds,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type GeometryEntity struct {
|
|||||||
Bbox *response.Bbox `json:"bbox"`
|
Bbox *response.Bbox `json:"bbox"`
|
||||||
ProjectID string `json:"project_id"`
|
ProjectID string `json:"project_id"`
|
||||||
IsDeleted bool `json:"is_deleted"`
|
IsDeleted bool `json:"is_deleted"`
|
||||||
|
ReplayIDs []string `json:"replay_ids"`
|
||||||
CreatedAt *time.Time `json:"created_at"`
|
CreatedAt *time.Time `json:"created_at"`
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ type EntityGeometriesSearchEntity struct {
|
|||||||
BoundWith *string `json:"bound_with,omitempty"`
|
BoundWith *string `json:"bound_with,omitempty"`
|
||||||
TimeStart *int32 `json:"time_start,omitempty"`
|
TimeStart *int32 `json:"time_start,omitempty"`
|
||||||
TimeEnd *int32 `json:"time_end,omitempty"`
|
TimeEnd *int32 `json:"time_end,omitempty"`
|
||||||
|
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GeometryEntity) ToResponse() *response.GeometryResponse {
|
func (g *GeometryEntity) ToResponse() *response.GeometryResponse {
|
||||||
@@ -46,6 +48,7 @@ func (g *GeometryEntity) ToResponse() *response.GeometryResponse {
|
|||||||
Bbox: g.Bbox,
|
Bbox: g.Bbox,
|
||||||
ProjectID: g.ProjectID,
|
ProjectID: g.ProjectID,
|
||||||
IsDeleted: g.IsDeleted,
|
IsDeleted: g.IsDeleted,
|
||||||
|
ReplayIDs: g.ReplayIDs,
|
||||||
CreatedAt: g.CreatedAt,
|
CreatedAt: g.CreatedAt,
|
||||||
UpdatedAt: g.UpdatedAt,
|
UpdatedAt: g.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ func (r *battleReplayRepository) Create(ctx context.Context, params sqlc.CreateB
|
|||||||
|
|
||||||
_ = r.c.Del(ctx, cache.Key("battle_replay:project", entity.ProjectID))
|
_ = r.c.Del(ctx, cache.Key("battle_replay:project", entity.ProjectID))
|
||||||
_ = r.c.Del(ctx, cache.Key("battle_replay:geometry", entity.GeometryID))
|
_ = r.c.Del(ctx, cache.Key("battle_replay:geometry", entity.GeometryID))
|
||||||
|
_ = r.c.Del(ctx, cache.Key("geometry:id", entity.GeometryID))
|
||||||
|
|
||||||
return entity, nil
|
return entity, nil
|
||||||
}
|
}
|
||||||
@@ -265,10 +266,16 @@ func (r *battleReplayRepository) Update(ctx context.Context, params sqlc.UpdateB
|
|||||||
|
|
||||||
entity := r.rowToEntity(row)
|
entity := r.rowToEntity(row)
|
||||||
_ = r.c.Del(ctx, cache.Key("battle_replay:id", entity.ID))
|
_ = r.c.Del(ctx, cache.Key("battle_replay:id", entity.ID))
|
||||||
|
_ = r.c.Del(ctx, cache.Key("battle_replay:geometry", entity.GeometryID))
|
||||||
|
_ = r.c.Del(ctx, cache.Key("geometry:id", entity.GeometryID))
|
||||||
return entity, nil
|
return entity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *battleReplayRepository) Delete(ctx context.Context, id pgtype.UUID) error {
|
func (r *battleReplayRepository) Delete(ctx context.Context, id pgtype.UUID) error {
|
||||||
|
if item, err := r.GetByID(ctx, id); err == nil && item != nil {
|
||||||
|
_ = r.c.Del(ctx, cache.Key("geometry:id", item.GeometryID))
|
||||||
|
_ = r.c.Del(ctx, cache.Key("battle_replay:geometry", item.GeometryID))
|
||||||
|
}
|
||||||
err := r.q.DeleteBattleReplay(ctx, id)
|
err := r.q.DeleteBattleReplay(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -278,6 +285,20 @@ func (r *battleReplayRepository) Delete(ctx context.Context, id pgtype.UUID) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *battleReplayRepository) DeleteByIDs(ctx context.Context, ids []pgtype.UUID) error {
|
func (r *battleReplayRepository) DeleteByIDs(ctx context.Context, ids []pgtype.UUID) error {
|
||||||
|
if len(ids) > 0 {
|
||||||
|
strIDs := make([]string, len(ids))
|
||||||
|
for i, id := range ids {
|
||||||
|
strIDs[i] = convert.UUIDToString(id)
|
||||||
|
}
|
||||||
|
if items, err := r.GetByIDs(ctx, strIDs); err == nil {
|
||||||
|
for _, item := range items {
|
||||||
|
if item != nil {
|
||||||
|
_ = r.c.Del(ctx, cache.Key("geometry:id", item.GeometryID))
|
||||||
|
_ = r.c.Del(ctx, cache.Key("battle_replay:geometry", item.GeometryID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
err := r.q.DeleteBattleReplaysByIDs(ctx, ids)
|
err := r.q.DeleteBattleReplaysByIDs(ctx, ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func (r *geometryRepository) getByIDsWithFallback(ctx context.Context, ids []str
|
|||||||
},
|
},
|
||||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||||
IsDeleted: row.IsDeleted,
|
IsDeleted: row.IsDeleted,
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
}
|
}
|
||||||
@@ -167,6 +168,7 @@ func (r *geometryRepository) GetByID(ctx context.Context, id pgtype.UUID) (*mode
|
|||||||
},
|
},
|
||||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||||
IsDeleted: row.IsDeleted,
|
IsDeleted: row.IsDeleted,
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
}
|
}
|
||||||
@@ -210,6 +212,7 @@ func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeome
|
|||||||
},
|
},
|
||||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||||
IsDeleted: row.IsDeleted,
|
IsDeleted: row.IsDeleted,
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
}
|
}
|
||||||
@@ -342,6 +345,7 @@ func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtyp
|
|||||||
},
|
},
|
||||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||||
IsDeleted: row.IsDeleted,
|
IsDeleted: row.IsDeleted,
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
}
|
}
|
||||||
@@ -394,6 +398,7 @@ func (r *geometryRepository) GetGeometriesByBoundWith(ctx context.Context, bound
|
|||||||
},
|
},
|
||||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||||
IsDeleted: row.IsDeleted,
|
IsDeleted: row.IsDeleted,
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||||
}
|
}
|
||||||
@@ -485,6 +490,7 @@ func (r *geometryRepository) getSearchByIDsWithFallback(ctx context.Context, pai
|
|||||||
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
||||||
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
||||||
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
}
|
}
|
||||||
key := cache.Key(item.EntityID, item.GeometryID)
|
key := cache.Key(item.EntityID, item.GeometryID)
|
||||||
dbMap[key] = item
|
dbMap[key] = item
|
||||||
@@ -544,6 +550,7 @@ func (r *geometryRepository) SearchByEntityName(ctx context.Context, params sqlc
|
|||||||
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
||||||
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
||||||
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
||||||
|
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||||
}
|
}
|
||||||
pair := cache.Key(item.EntityID, item.GeometryID)
|
pair := cache.Key(item.EntityID, item.GeometryID)
|
||||||
geometries = append(geometries, item)
|
geometries = append(geometries, item)
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ func (s *geometryService) SearchGeometriesByEntityName(
|
|||||||
BoundWith: row.BoundWith,
|
BoundWith: row.BoundWith,
|
||||||
TimeStart: row.TimeStart,
|
TimeStart: row.TimeStart,
|
||||||
TimeEnd: row.TimeEnd,
|
TimeEnd: row.TimeEnd,
|
||||||
|
ReplayIDs: row.ReplayIDs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user