2024-01-16 16:13:06 +00:00
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"
)
2024-01-19 16:37:15 +00:00
func ( d * DB ) CreateBenefactorAddress ( ctx context . Context , address entity . Address ) ( entity . Address , error ) {
2024-01-16 16:13:06 +00:00
const op = "mysqlbenefactor.createBenefactorAddress"
res , err := d . conn . Conn ( ) . ExecContext ( ctx , ` insert into addresses(postal_code, address, lat, lon,province_id,city_id,benefactor_id) values(?, ?, ?,?,?,?,?) ` ,
address . PostalCode , address . Address , address . Lat , address . Lon , address . ProvinceID , address . CityID , address . BenefactorID )
if err != nil {
return entity . Address { } , richerror . New ( op ) . WithErr ( err ) .
WithMessage ( errmsg . ErrorMsgNotFound ) . WithKind ( richerror . KindUnexpected )
}
//nolint
// error is always nil
id , _ := res . LastInsertId ( )
address . ID = uint ( id )
return address , nil
}