2024-07-23 21:37:27 +00:00
|
|
|
package mysqlkindbox
|
|
|
|
|
|
|
|
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-07-30 11:05:41 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
2024-07-23 21:37:27 +00:00
|
|
|
)
|
|
|
|
|
2024-07-30 11:05:41 +00:00
|
|
|
func (d *DB) EnumerateKindBox(ctx context.Context, kindBoxID, amount uint) error {
|
2024-07-23 21:37:27 +00:00
|
|
|
const op = "mysqlkindbox.EnumerateKindBox"
|
|
|
|
|
|
|
|
query := `UPDATE kind_boxes SET amount = ?, status = ? WHERE id = ?`
|
2024-07-30 11:05:41 +00:00
|
|
|
//nolint
|
|
|
|
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyKindBoxEnumerate, query)
|
|
|
|
if err != nil {
|
|
|
|
return richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
_, err = stmt.ExecContext(ctx, amount, entity.KindBoxEnumeratedStatus, kindBoxID)
|
2024-07-23 21:37:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|