forked from ebhomengo/niki
28 lines
825 B
Go
28 lines
825 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"
|
|
)
|
|
|
|
func (d DB) CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error) {
|
|
const op = "mysqlbenefactor.CreateBenefactor"
|
|
|
|
res, err := d.conn.Conn().ExecContext(ctx, `insert into benefactors(phone_number, status, role) values(?, ?, ?)`,
|
|
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)
|
|
}
|
|
|
|
//nolint
|
|
// error is always nil
|
|
id, _ := res.LastInsertId()
|
|
benefactor.ID = uint(id)
|
|
|
|
return benefactor, nil
|
|
}
|