diff --git a/internal/dtos/response/geometry.go b/internal/dtos/response/geometry.go index c640147..cabdc2c 100644 --- a/internal/dtos/response/geometry.go +++ b/internal/dtos/response/geometry.go @@ -14,7 +14,7 @@ type Bbox struct { type GeometryResponse struct { ID string `json:"id"` - GeoType string `json:"geo_type"` + GeoType int16 `json:"geo_type"` DrawGeometry json.RawMessage `json:"draw_geometry"` Binding json.RawMessage `json:"binding,omitempty"` TimeStart int32 `json:"time_start,omitempty"` diff --git a/internal/models/geometry.go b/internal/models/geometry.go index 8f9c9d5..7587dc8 100644 --- a/internal/models/geometry.go +++ b/internal/models/geometry.go @@ -3,13 +3,12 @@ package models import ( "encoding/json" "history-api/internal/dtos/response" - "history-api/pkg/constants" "time" ) type GeometryEntity struct { ID string `json:"id"` - GeoType constants.GeoType `json:"geo_type"` + GeoType int16 `json:"geo_type"` DrawGeometry json.RawMessage `json:"draw_geometry"` Binding json.RawMessage `json:"binding"` TimeStart int32 `json:"time_start"` @@ -27,7 +26,7 @@ func (g *GeometryEntity) ToResponse() *response.GeometryResponse { } return &response.GeometryResponse{ ID: g.ID, - GeoType: g.GeoType.String(), + GeoType: g.GeoType, DrawGeometry: g.DrawGeometry, Binding: g.Binding, TimeStart: g.TimeStart, diff --git a/internal/repositories/geometryRepository.go b/internal/repositories/geometryRepository.go index 75315a0..2ca279c 100644 --- a/internal/repositories/geometryRepository.go +++ b/internal/repositories/geometryRepository.go @@ -90,7 +90,7 @@ func (r *geometryRepository) getByIDsWithFallback(ctx context.Context, ids []str for _, row := range dbRows { item := models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), @@ -152,7 +152,7 @@ func (r *geometryRepository) GetByID(ctx context.Context, id pgtype.UUID) (*mode geometry = models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), @@ -191,7 +191,7 @@ func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeome for _, row := range rows { geometry := &models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), @@ -230,7 +230,7 @@ func (r *geometryRepository) Create(ctx context.Context, params sqlc.CreateGeome geometry := models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), @@ -257,7 +257,7 @@ func (r *geometryRepository) Update(ctx context.Context, params sqlc.UpdateGeome } geometry := models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), @@ -321,7 +321,7 @@ func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtyp for _, row := range rows { geometry := &models.GeometryEntity{ ID: convert.UUIDToString(row.ID), - GeoType: constants.ParseGeoType(row.GeoType), + GeoType: row.GeoType, DrawGeometry: row.DrawGeometry, Binding: row.Binding, TimeStart: convert.Int4ToInt32(row.TimeStart), diff --git a/internal/services/submissionService.go b/internal/services/submissionService.go index 6df7028..0a3b666 100644 --- a/internal/services/submissionService.go +++ b/internal/services/submissionService.go @@ -15,6 +15,7 @@ import ( "history-api/pkg/cache" "history-api/pkg/constants" "history-api/pkg/convert" + "strconv" "slices" "github.com/gofiber/fiber/v3" @@ -399,11 +400,17 @@ func (s *submissionService) UpdateSubmissionStatus(ctx context.Context, reviewer } binding, _ := json.Marshal(geo.Binding) + geoTypeCode := int16(0) + if geo.Type != "" { + if n, err := strconv.ParseInt(geo.Type, 10, 16); err == nil { + geoTypeCode = int16(n) + } + } if _, ok := persistCurrentItemIDs[geo.ID]; ok { params := sqlc.UpdateGeometryParams{ ID: geometryUUID, - GeoType: pgtype.Int2{Int16: constants.ParseGeoTypeText(geo.Type).Int16(), Valid: true}, + GeoType: pgtype.Int2{Int16: geoTypeCode, Valid: true}, DrawGeometry: geo.DrawGeometry, Binding: binding, TimeStart: convert.PtrFloat64ToInt4(geo.TimeStart), @@ -428,7 +435,7 @@ func (s *submissionService) UpdateSubmissionStatus(ctx context.Context, reviewer } else if geo.Source == "inline" { params := sqlc.CreateGeometryParams{ ID: geometryUUID, - GeoType: constants.ParseGeoTypeText(geo.Type).Int16(), + GeoType: geoTypeCode, DrawGeometry: geo.DrawGeometry, Binding: binding, TimeStart: convert.PtrFloat64ToInt4(geo.TimeStart),