From 1a9d04a2d95cbc5dc9b8a8e1422a6087ac163f60 Mon Sep 17 00:00:00 2001 From: "aditya.siregar" Date: Wed, 14 Aug 2024 23:44:34 +0700 Subject: [PATCH] Lat Long --- internal/handlers/http/sites/sites.go | 4 ++-- internal/handlers/request/site.go | 21 ++++----------------- internal/handlers/response/site.go | 3 ++- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/internal/handlers/http/sites/sites.go b/internal/handlers/http/sites/sites.go index 67b4f51..3045001 100644 --- a/internal/handlers/http/sites/sites.go +++ b/internal/handlers/http/sites/sites.go @@ -1,7 +1,6 @@ package site import ( - "fmt" "furtuna-be/internal/common/errors" "furtuna-be/internal/entity" "furtuna-be/internal/handlers/request" @@ -288,7 +287,8 @@ func (h *Handler) toSiteResponse(resp *entity.Site) response.Site { CreatedAt: resp.CreatedAt.Format(time.RFC3339), UpdatedAt: resp.UpdatedAt.Format(time.RFC3339), Products: h.toProductResponseList(resp.Products), - LatLong: fmt.Sprintf("%f,%f", resp.Lat, resp.Long), + Lat: resp.Lat, + Long: resp.Long, } } diff --git a/internal/handlers/request/site.go b/internal/handlers/request/site.go index 1611f77..59d0470 100644 --- a/internal/handlers/request/site.go +++ b/internal/handlers/request/site.go @@ -3,9 +3,6 @@ package request import ( "furtuna-be/internal/common/mycontext" "furtuna-be/internal/entity" - "log" - "strconv" - "strings" ) type Site struct { @@ -26,7 +23,8 @@ type Site struct { Products []Product `json:"products"` Region string `json:"region"` Regency string `json:"regency"` - LatLong string `json:"lat_long"` + Lat float64 `json:"lat"` + Long float64 `json:"long"` } func (r *Site) ToEntity(createdBy int64) *entity.Site { @@ -45,17 +43,6 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site { CreatedBy: createdBy, }) } - latLong := strings.Split(r.LatLong, ".") - - lat, err := strconv.ParseFloat(latLong[0], 64) - if err != nil { - log.Fatalf("Error converting latitude: %v", err) - } - - long, err := strconv.ParseFloat(latLong[1], 64) - if err != nil { - log.Fatalf("Error converting longitude: %v", err) - } return &entity.Site{ ID: r.ID, @@ -75,8 +62,8 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site { Products: products, Region: r.Region, Regency: r.Regency, - Lat: lat, - Long: long, + Lat: r.Lat, + Long: r.Long, } } diff --git a/internal/handlers/response/site.go b/internal/handlers/response/site.go index c0d0d35..7af14d7 100644 --- a/internal/handlers/response/site.go +++ b/internal/handlers/response/site.go @@ -18,7 +18,8 @@ type Site struct { CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` Products []Product `json:"products"` - LatLong string `json:"lat_long"` + Lat float64 `json:"lat"` + Long float64 `json:"long"` } type SiteName struct {