2024-06-08 14:25:24 +00:00
|
|
|
package mysqladdress
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
2024-07-30 11:05:41 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
2024-06-08 14:25:24 +00:00
|
|
|
)
|
|
|
|
|
2024-07-24 23:45:04 +00:00
|
|
|
func (d *DB) DeleteBenefactorAddress(ctx context.Context, addressID, benefactorID uint) error {
|
2024-06-08 14:25:24 +00:00
|
|
|
const op = "mysqladdress.DeleteBenefactorAddress"
|
|
|
|
|
2024-07-30 11:05:41 +00:00
|
|
|
query := `UPDATE addresses SET deleted_at = CURRENT_TIMESTAMP WHERE id = ? AND benefactor_id = ? AND deleted_at IS NULL`
|
|
|
|
//nolint
|
|
|
|
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyAddressDeleteForBenefactor, query)
|
|
|
|
if err != nil {
|
|
|
|
return richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = stmt.ExecContext(ctx, addressID, benefactorID)
|
2024-06-08 14:25:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected).WithMessage(errmsg.ErrorMsgCantDeleteAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|