This commit is contained in:
@@ -14,8 +14,8 @@ import (
|
||||
)
|
||||
|
||||
type GeometryService interface {
|
||||
GetGeometryByID(ctx context.Context, id string) (*response.GeometryResponse, error)
|
||||
SearchGeometries(ctx context.Context, req *request.SearchGeometryDto) ([]*response.GeometryResponse, error)
|
||||
GetGeometryByID(ctx context.Context, id string) (*response.GeometryResponse, *fiber.Error)
|
||||
SearchGeometries(ctx context.Context, req *request.SearchGeometryDto) ([]*response.GeometryResponse, *fiber.Error)
|
||||
}
|
||||
|
||||
type geometryService struct {
|
||||
@@ -28,10 +28,10 @@ func NewGeometryService(geometryRepo repositories.GeometryRepository) GeometrySe
|
||||
}
|
||||
}
|
||||
|
||||
func (s *geometryService) GetGeometryByID(ctx context.Context, id string) (*response.GeometryResponse, error) {
|
||||
func (s *geometryService) GetGeometryByID(ctx context.Context, id string) (*response.GeometryResponse, *fiber.Error) {
|
||||
geometryId, err := convert.StringToUUID(id)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid geometry ID format")
|
||||
}
|
||||
geometry, err := s.geometryRepo.GetByID(ctx, geometryId)
|
||||
if err != nil {
|
||||
@@ -41,24 +41,24 @@ func (s *geometryService) GetGeometryByID(ctx context.Context, id string) (*resp
|
||||
return geometry.ToResponse(), nil
|
||||
}
|
||||
|
||||
func (s *geometryService) SearchGeometries(ctx context.Context, req *request.SearchGeometryDto) ([]*response.GeometryResponse, error) {
|
||||
func (s *geometryService) SearchGeometries(ctx context.Context, req *request.SearchGeometryDto) ([]*response.GeometryResponse, *fiber.Error) {
|
||||
params := sqlc.SearchGeometriesParams{}
|
||||
|
||||
if req.MinLng != nil && req.MinLat != nil && req.MaxLng != nil && req.MaxLat != nil {
|
||||
if *req.MaxLng < *req.MinLng || *req.MaxLat < *req.MinLat {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid bounding box")
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Invalid bounding box coordinates")
|
||||
}
|
||||
params.SearchMinLng = pgtype.Float8{Float64: *req.MinLng, Valid: true}
|
||||
params.SearchMinLat = pgtype.Float8{Float64: *req.MinLat, Valid: true}
|
||||
params.SearchMaxLng = pgtype.Float8{Float64: *req.MaxLng, Valid: true}
|
||||
params.SearchMaxLat = pgtype.Float8{Float64: *req.MaxLat, Valid: true}
|
||||
} else {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Must provid Bounding box!")
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Bounding box coordinates are required")
|
||||
}
|
||||
|
||||
if req.TimePoint != nil {
|
||||
if *req.TimePoint < 0 {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Time point must be non-negative!")
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Time point must be non-negative")
|
||||
}
|
||||
params.TimePoint = pgtype.Int4{Int32: *req.TimePoint, Valid: true}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func (s *geometryService) SearchGeometries(ctx context.Context, req *request.Sea
|
||||
|
||||
geometries, err := s.geometryRepo.Search(ctx, params)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to search geometries")
|
||||
}
|
||||
|
||||
return models.GeometriesEntityToResponse(geometries), nil
|
||||
|
||||
Reference in New Issue
Block a user