2024-06-06 17:54:56 +00:00
|
|
|
package benefactoraddressservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func (s Service) Update(ctx context.Context, req param.UpdateAddressRequest) (param.UpdateAddressResponse, error) {
|
2024-06-06 17:54:56 +00:00
|
|
|
const op = "benefactoraddressservice.Update"
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateUpdateAddress(ctx, req); vErr != nil {
|
|
|
|
return param.UpdateAddressResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
|
|
|
address, gErr := s.repo.GetAddressByID(ctx, req.ID)
|
|
|
|
if gErr != nil {
|
|
|
|
return param.UpdateAddressResponse{}, richerror.New(op).WithErr(gErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
address.ID = req.ID
|
|
|
|
address.PostalCode = req.PostalCode
|
|
|
|
address.Address = req.Address
|
|
|
|
address.Name = req.Name
|
|
|
|
address.Lat = req.Lat
|
|
|
|
address.Lon = req.Lon
|
|
|
|
address.CityID = req.CityID
|
|
|
|
address.BenefactorID = req.BenefactorID
|
2024-06-06 17:54:56 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
uErr := s.repo.UpdateAddress(ctx, address)
|
|
|
|
if uErr != nil {
|
|
|
|
return param.UpdateAddressResponse{}, richerror.New(op).WithErr(uErr)
|
2024-06-06 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
return param.UpdateAddressResponse{}, nil
|
2024-06-06 17:54:56 +00:00
|
|
|
}
|