forked from ebhomengo/niki
1
0
Fork 0
niki/repository/mysql/address/update.go

32 lines
958 B
Go

package mysqladdress
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (d *DB) UpdateAddress(ctx context.Context, address entity.Address) error {
const op = "mysqladdress.UpdateAddress"
provinceID, err := d.getProvinceIDByCityID(ctx, address.CityID)
if err != nil {
return err
}
query := `UPDATE addresses
SET postal_code = ?, address = ?, lat = ?, lon = ?, name = ?, city_id = ?, province_id = ?
WHERE id = ? AND benefactor_id = ? AND deleted_at IS NULL`
_, uErr := d.conn.Conn().ExecContext(ctx, query, address.PostalCode, address.Address, address.Lat, address.Lon, address.Name, address.CityID, provinceID, address.ID, address.BenefactorID)
if err != nil {
return richerror.New(op).WithErr(uErr).WithMessage(errmsg.ErrorMsgCantUpdateRecord).
WithKind(richerror.KindUnexpected)
}
return nil
}