2024-01-14 15:53:37 +00:00
|
|
|
package mysqlbenefactor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-15 10:33:24 +00:00
|
|
|
|
2024-01-14 15:53:37 +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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (d DB) CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error) {
|
|
|
|
const op = "mysqlbenefactor.CreateBenefactor"
|
|
|
|
|
2024-01-15 10:33:24 +00:00
|
|
|
res, err := d.conn.Conn().ExecContext(ctx, `insert into benefactors(phone_number, status, role) values(?, ?, ?)`,
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactor.PhoneNumber, benefactor.Status.String(), benefactor.Role.String())
|
|
|
|
if err != nil {
|
|
|
|
return entity.Benefactor{}, richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
2024-01-15 10:33:24 +00:00
|
|
|
//nolint
|
2024-01-14 15:53:37 +00:00
|
|
|
// error is always nil
|
|
|
|
id, _ := res.LastInsertId()
|
|
|
|
benefactor.ID = uint(id)
|
|
|
|
|
|
|
|
return benefactor, nil
|
|
|
|
}
|