diff --git a/dto/address_dto.go b/dto/address_dto.go index bcf5400..f33016e 100644 --- a/dto/address_dto.go +++ b/dto/address_dto.go @@ -11,7 +11,8 @@ type AddressResponseDTO struct { Village string `json:"village"` PostalCode string `json:"postalCode"` Detail string `json:"detail"` - Geography string `json:"geography"` + Latitude string `json:"latitude"` + Longitude string `json:"longitude"` CreatedAt string `json:"createdAt"` UpdatedAt string `json:"updatedAt"` } @@ -23,7 +24,8 @@ type CreateAddressDTO struct { Village string `json:"village_id"` PostalCode string `json:"postalCode"` Detail string `json:"detail"` - Geography string `json:"geography"` + Latitude string `json:"latitude"` + Longitude string `json:"longitude"` } func (r *CreateAddressDTO) ValidateAddress() (map[string][]string, bool) { @@ -49,8 +51,11 @@ func (r *CreateAddressDTO) ValidateAddress() (map[string][]string, bool) { if strings.TrimSpace(r.Detail) == "" { errors["detail"] = append(errors["detail"], "Detail address is required") } - if strings.TrimSpace(r.Geography) == "" { - errors["geography"] = append(errors["geography"], "Geographic coordinates are required") + if strings.TrimSpace(r.Latitude) == "" { + errors["latitude"] = append(errors["latitude"], "Geographic coordinates are required") + } + if strings.TrimSpace(r.Longitude) == "" { + errors["longitude"] = append(errors["longitude"], "Geographic coordinates are required") } if len(errors) > 0 { diff --git a/go.mod b/go.mod index 687dde0..86771ff 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( ) require ( + github.com/umahmood/haversine v0.0.0-20151105152445-808ab04add26 // indirect golang.org/x/term v0.30.0 // indirect rsc.io/qr v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index 83b4326..1b59849 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/umahmood/haversine v0.0.0-20151105152445-808ab04add26 h1:UFHFmFfixpmfRBcxuu+LA9l8MdURWVdVNUHxO5n1d2w= +github.com/umahmood/haversine v0.0.0-20151105152445-808ab04add26/go.mod h1:IGhd0qMDsUa9acVjsbsT7bu3ktadtGOHI79+idTew/M= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= diff --git a/internal/services/address_service.go b/internal/services/address_service.go index 0f73781..2fa6315 100644 --- a/internal/services/address_service.go +++ b/internal/services/address_service.go @@ -60,7 +60,8 @@ func (s *addressService) CreateAddress(userID string, addressDTO dto.CreateAddre Village: village.Name, PostalCode: addressDTO.PostalCode, Detail: addressDTO.Detail, - Geography: addressDTO.Geography, + Latitude: addressDTO.Latitude, + Longitude: addressDTO.Longitude, } err = s.AddressRepo.CreateAddress(&address) @@ -83,7 +84,8 @@ func (s *addressService) CreateAddress(userID string, addressDTO dto.CreateAddre Village: address.Village, PostalCode: address.PostalCode, Detail: address.Detail, - Geography: address.Geography, + Latitude: address.Latitude, + Longitude: address.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, } @@ -116,7 +118,8 @@ func (s *addressService) CreateAddress(userID string, addressDTO dto.CreateAddre Village: addr.Village, PostalCode: addr.PostalCode, Detail: addr.Detail, - Geography: addr.Geography, + Latitude: addr.Latitude, + Longitude: addr.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, }) @@ -152,7 +155,8 @@ func (s *addressService) GetAddressByUserID(userID string) ([]dto.AddressRespons Village: addressData["village"].(string), PostalCode: addressData["postalCode"].(string), Detail: addressData["detail"].(string), - Geography: addressData["geography"].(string), + Latitude: addressData["latitude"].(string), + Longitude: addressData["longitude"].(string), CreatedAt: addressData["createdAt"].(string), UpdatedAt: addressData["updatedAt"].(string), }) @@ -181,7 +185,8 @@ func (s *addressService) GetAddressByUserID(userID string) ([]dto.AddressRespons Village: address.Village, PostalCode: address.PostalCode, Detail: address.Detail, - Geography: address.Geography, + Latitude: address.Latitude, + Longitude: address.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, }) @@ -222,7 +227,8 @@ func (s *addressService) GetAddressByID(userID, id string) (*dto.AddressResponse Village: addressData["village"].(string), PostalCode: addressData["postalCode"].(string), Detail: addressData["detail"].(string), - Geography: addressData["geography"].(string), + Latitude: addressData["latitude"].(string), + Longitude: addressData["longitude"].(string), CreatedAt: addressData["createdAt"].(string), UpdatedAt: addressData["updatedAt"].(string), } @@ -242,7 +248,8 @@ func (s *addressService) GetAddressByID(userID, id string) (*dto.AddressResponse Village: address.Village, PostalCode: address.PostalCode, Detail: address.Detail, - Geography: address.Geography, + Latitude: address.Latitude, + Longitude: address.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, } @@ -295,7 +302,8 @@ func (s *addressService) UpdateAddress(userID, id string, addressDTO dto.CreateA address.Village = village.Name address.PostalCode = addressDTO.PostalCode address.Detail = addressDTO.Detail - address.Geography = addressDTO.Geography + address.Latitude = addressDTO.Latitude + address.Longitude = addressDTO.Longitude address.UpdatedAt = time.Now() err = s.AddressRepo.UpdateAddress(address) @@ -321,7 +329,8 @@ func (s *addressService) UpdateAddress(userID, id string, addressDTO dto.CreateA Village: address.Village, PostalCode: address.PostalCode, Detail: address.Detail, - Geography: address.Geography, + Latitude: address.Latitude, + Longitude: address.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, } @@ -353,7 +362,8 @@ func (s *addressService) UpdateAddress(userID, id string, addressDTO dto.CreateA Village: addr.Village, PostalCode: addr.PostalCode, Detail: addr.Detail, - Geography: addr.Geography, + Latitude: addr.Latitude, + Longitude: addr.Longitude, CreatedAt: createdAt, UpdatedAt: updatedAt, }) diff --git a/model/address_model.go b/model/address_model.go index 1da69ec..a381737 100644 --- a/model/address_model.go +++ b/model/address_model.go @@ -12,7 +12,8 @@ type Address struct { Village string `gorm:"not null" json:"village"` PostalCode string `gorm:"not null" json:"postalCode"` Detail string `gorm:"not null" json:"detail"` - Geography string `gorm:"not null" json:"geography"` + Latitude string `gorm:"not null" json:"latitude"` + Longitude string `gorm:"not null" json:"longitude"` CreatedAt time.Time `gorm:"default:current_timestamp" json:"createdAt"` UpdatedAt time.Time `gorm:"default:current_timestamp" json:"updatedAt"` }