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;
|
||||
|
||||
-- name: GetGeometryById :one
|
||||
SELECT id, geo_type, draw_geometry, bound_with, 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
|
||||
SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE id = $1 AND is_deleted = false;
|
||||
WHERE geometries.id = $1 AND geometries.is_deleted = false;
|
||||
|
||||
-- name: UpdateGeometry :one
|
||||
UPDATE geometries
|
||||
@@ -52,7 +58,13 @@ SELECT
|
||||
ST_YMin(g.bbox)::float8 as min_lat,
|
||||
ST_XMax(g.bbox)::float8 as max_lng,
|
||||
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
|
||||
WHERE g.is_deleted = false
|
||||
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.bound_with,
|
||||
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
|
||||
LEFT JOIN entity_geometries eg
|
||||
ON eg.entity_id = me.id
|
||||
@@ -143,25 +161,37 @@ WHERE project_id = $1;
|
||||
|
||||
-- name: GetGeometriesByIDs :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE id = ANY($1::uuid[]) AND is_deleted = false;
|
||||
WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false;
|
||||
|
||||
-- name: GetGeometriesByProjectId :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE project_id = $1 AND is_deleted = false;
|
||||
WHERE geometries.project_id = $1 AND geometries.is_deleted = false;
|
||||
|
||||
-- name: DeleteGeometriesByIDs :exec
|
||||
UPDATE geometries
|
||||
@@ -186,7 +216,13 @@ SELECT
|
||||
g.draw_geometry,
|
||||
g.bound_with,
|
||||
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 (
|
||||
SELECT unnest(@entity_ids::uuid[]) as eid, unnest(@geometry_ids::uuid[]) as gid
|
||||
) as pairs
|
||||
@@ -198,11 +234,17 @@ AND g.is_deleted = false;
|
||||
|
||||
-- name: GetGeometriesByBoundWith :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
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"`
|
||||
ProjectID string `json:"project_id"`
|
||||
IsDeleted bool `json:"is_deleted,omitempty"`
|
||||
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ type EntityGeometrySearchGeo struct {
|
||||
BoundWith *string `json:"bound_with,omitempty"`
|
||||
TimeStart *int32 `json:"time_start,omitempty"`
|
||||
TimeEnd *int32 `json:"time_end,omitempty"`
|
||||
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||
}
|
||||
|
||||
@@ -201,7 +201,13 @@ SELECT
|
||||
g.draw_geometry,
|
||||
g.bound_with,
|
||||
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 (
|
||||
SELECT unnest($1::uuid[]) as eid, unnest($2::uuid[]) as gid
|
||||
) as pairs
|
||||
@@ -227,6 +233,7 @@ type GetEntityGeometriesByPairsRow struct {
|
||||
BoundWith pgtype.UUID `json:"bound_with"`
|
||||
TimeStart pgtype.Int4 `json:"time_start"`
|
||||
TimeEnd pgtype.Int4 `json:"time_end"`
|
||||
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||
}
|
||||
|
||||
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.TimeStart,
|
||||
&i.TimeEnd,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -261,14 +269,20 @@ func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityG
|
||||
|
||||
const getGeometriesByBoundWith = `-- name: GetGeometriesByBoundWith :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE bound_with = $1 AND is_deleted = false
|
||||
WHERE geometries.bound_with = $1 AND geometries.is_deleted = false
|
||||
`
|
||||
|
||||
type GetGeometriesByBoundWithRow struct {
|
||||
@@ -286,6 +300,7 @@ type GetGeometriesByBoundWithRow struct {
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_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) {
|
||||
@@ -312,6 +327,7 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -325,14 +341,20 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype
|
||||
|
||||
const getGeometriesByIDs = `-- name: GetGeometriesByIDs :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
||||
WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false
|
||||
`
|
||||
|
||||
type GetGeometriesByIDsRow struct {
|
||||
@@ -350,6 +372,7 @@ type GetGeometriesByIDsRow struct {
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_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) {
|
||||
@@ -376,6 +399,7 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -389,14 +413,20 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID
|
||||
|
||||
const getGeometriesByProjectId = `-- name: GetGeometriesByProjectId :many
|
||||
SELECT
|
||||
id, geo_type, draw_geometry, bound_with, 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
|
||||
geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE project_id = $1 AND is_deleted = false
|
||||
WHERE geometries.project_id = $1 AND geometries.is_deleted = false
|
||||
`
|
||||
|
||||
type GetGeometriesByProjectIdRow struct {
|
||||
@@ -414,6 +444,7 @@ type GetGeometriesByProjectIdRow struct {
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_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) {
|
||||
@@ -440,6 +471,7 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -452,11 +484,17 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype
|
||||
}
|
||||
|
||||
const getGeometryById = `-- name: GetGeometryById :one
|
||||
SELECT id, geo_type, draw_geometry, bound_with, 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
|
||||
SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id,
|
||||
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,
|
||||
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
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
WHERE geometries.id = $1 AND geometries.is_deleted = false
|
||||
`
|
||||
|
||||
type GetGeometryByIdRow struct {
|
||||
@@ -474,6 +512,7 @@ type GetGeometryByIdRow struct {
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_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) {
|
||||
@@ -494,6 +533,7 @@ func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeome
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ReplayIds,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -505,7 +545,13 @@ SELECT
|
||||
ST_YMin(g.bbox)::float8 as min_lat,
|
||||
ST_XMax(g.bbox)::float8 as max_lng,
|
||||
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
|
||||
WHERE g.is_deleted = false
|
||||
AND ($1::uuid IS NULL OR g.project_id = $1::uuid)
|
||||
@@ -576,6 +622,7 @@ type SearchGeometriesRow struct {
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||
}
|
||||
|
||||
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.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -646,7 +694,13 @@ SELECT
|
||||
g.draw_geometry,
|
||||
g.bound_with,
|
||||
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
|
||||
LEFT JOIN entity_geometries eg
|
||||
ON eg.entity_id = me.id
|
||||
@@ -663,15 +717,16 @@ type SearchGeometriesByEntityNameParams struct {
|
||||
}
|
||||
|
||||
type SearchGeometriesByEntityNameRow struct {
|
||||
EntityID pgtype.UUID `json:"entity_id"`
|
||||
EntityName string `json:"entity_name"`
|
||||
EntityDescription pgtype.Text `json:"entity_description"`
|
||||
GeometryID pgtype.UUID `json:"geometry_id"`
|
||||
GeoType pgtype.Int2 `json:"geo_type"`
|
||||
DrawGeometry []byte `json:"draw_geometry"`
|
||||
BoundWith pgtype.UUID `json:"bound_with"`
|
||||
TimeStart pgtype.Int4 `json:"time_start"`
|
||||
TimeEnd pgtype.Int4 `json:"time_end"`
|
||||
EntityID pgtype.UUID `json:"entity_id"`
|
||||
EntityName string `json:"entity_name"`
|
||||
EntityDescription pgtype.Text `json:"entity_description"`
|
||||
GeometryID pgtype.UUID `json:"geometry_id"`
|
||||
GeoType pgtype.Int2 `json:"geo_type"`
|
||||
DrawGeometry []byte `json:"draw_geometry"`
|
||||
BoundWith pgtype.UUID `json:"bound_with"`
|
||||
TimeStart pgtype.Int4 `json:"time_start"`
|
||||
TimeEnd pgtype.Int4 `json:"time_end"`
|
||||
ReplayIds []pgtype.UUID `json:"replay_ids"`
|
||||
}
|
||||
|
||||
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.TimeStart,
|
||||
&i.TimeEnd,
|
||||
&i.ReplayIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ type GeometryEntity struct {
|
||||
Bbox *response.Bbox `json:"bbox"`
|
||||
ProjectID string `json:"project_id"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
ReplayIDs []string `json:"replay_ids"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -30,6 +31,7 @@ type EntityGeometriesSearchEntity struct {
|
||||
BoundWith *string `json:"bound_with,omitempty"`
|
||||
TimeStart *int32 `json:"time_start,omitempty"`
|
||||
TimeEnd *int32 `json:"time_end,omitempty"`
|
||||
ReplayIDs []string `json:"replay_ids,omitempty"`
|
||||
}
|
||||
|
||||
func (g *GeometryEntity) ToResponse() *response.GeometryResponse {
|
||||
@@ -46,6 +48,7 @@ func (g *GeometryEntity) ToResponse() *response.GeometryResponse {
|
||||
Bbox: g.Bbox,
|
||||
ProjectID: g.ProjectID,
|
||||
IsDeleted: g.IsDeleted,
|
||||
ReplayIDs: g.ReplayIDs,
|
||||
CreatedAt: g.CreatedAt,
|
||||
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:geometry", entity.GeometryID))
|
||||
_ = r.c.Del(ctx, cache.Key("geometry:id", entity.GeometryID))
|
||||
|
||||
return entity, nil
|
||||
}
|
||||
@@ -265,10 +266,16 @@ func (r *battleReplayRepository) Update(ctx context.Context, params sqlc.UpdateB
|
||||
|
||||
entity := r.rowToEntity(row)
|
||||
_ = 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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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 {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -105,6 +105,7 @@ func (r *geometryRepository) getByIDsWithFallback(ctx context.Context, ids []str
|
||||
},
|
||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||
IsDeleted: row.IsDeleted,
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
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),
|
||||
IsDeleted: row.IsDeleted,
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||
}
|
||||
@@ -210,6 +212,7 @@ func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeome
|
||||
},
|
||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||
IsDeleted: row.IsDeleted,
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||
}
|
||||
@@ -342,6 +345,7 @@ func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtyp
|
||||
},
|
||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||
IsDeleted: row.IsDeleted,
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||
}
|
||||
@@ -394,6 +398,7 @@ func (r *geometryRepository) GetGeometriesByBoundWith(ctx context.Context, bound
|
||||
},
|
||||
ProjectID: convert.UUIDToString(row.ProjectID),
|
||||
IsDeleted: row.IsDeleted,
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
|
||||
}
|
||||
@@ -485,6 +490,7 @@ func (r *geometryRepository) getSearchByIDsWithFallback(ctx context.Context, pai
|
||||
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
||||
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
||||
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
}
|
||||
key := cache.Key(item.EntityID, item.GeometryID)
|
||||
dbMap[key] = item
|
||||
@@ -544,6 +550,7 @@ func (r *geometryRepository) SearchByEntityName(ctx context.Context, params sqlc
|
||||
BoundWith: convert.UUIDToStringPtr(row.BoundWith),
|
||||
TimeStart: convert.Int4ToPtr(row.TimeStart),
|
||||
TimeEnd: convert.Int4ToPtr(row.TimeEnd),
|
||||
ReplayIDs: convert.ListUUIDToString(row.ReplayIds),
|
||||
}
|
||||
pair := cache.Key(item.EntityID, item.GeometryID)
|
||||
geometries = append(geometries, item)
|
||||
|
||||
@@ -163,6 +163,7 @@ func (s *geometryService) SearchGeometriesByEntityName(
|
||||
BoundWith: row.BoundWith,
|
||||
TimeStart: row.TimeStart,
|
||||
TimeEnd: row.TimeEnd,
|
||||
ReplayIDs: row.ReplayIDs,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user