forked from ebhomengo/niki
1
0
Fork 0
niki/repository/mysql/kind_box_req/accept.go

31 lines
981 B
Go
Raw Normal View History

package mysqlkindboxreq
import (
"context"
2024-06-14 08:41:36 +00:00
"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) AcceptKindBoxReq(ctx context.Context, kindBoxReqID, countAccepted uint) error {
const op = "mysqlkindboxreq.AcceptKindBoxReq"
query := `update kind_box_reqs set count_accepted = ? , status = ? where id = ?`
//nolint
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyKindBoxReqAccept, query)
if err != nil {
return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
}
_, err = stmt.ExecContext(ctx, countAccepted, entity.KindBoxReqAcceptedStatus.String(), kindBoxReqID)
if err != nil {
return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
return nil
}