niki/repository/mysql/benefactor/update_status.go

31 lines
958 B
Go

package mysqlbenefactor
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"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)
func (d *DB) UpdateStatusBenefactor(ctx context.Context, benefactor entity.Benefactor, status entity.BenefactorStatus) error {
const op = "mysqlbenefactor.UpdateStatusBenefactor"
query := `UPDATE benefactors SET status = ? WHERE id = ?`
//nolint
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyBenefactorUpdateStatus, query)
if err != nil {
return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
}
_, uErr := stmt.ExecContext(ctx, status, benefactor.ID)
if uErr != nil {
return richerror.New(op).WithErr(uErr).WithMessage(errmsg.ErrorMsgCantUpdateRecord).
WithKind(richerror.KindUnexpected)
}
return nil
}