forked from ebhomengo/niki
26 lines
802 B
Go
26 lines
802 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().Exec(`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)
|
||
|
}
|
||
|
|
||
|
// error is always nil
|
||
|
id, _ := res.LastInsertId()
|
||
|
benefactor.ID = uint(id)
|
||
|
|
||
|
return benefactor, nil
|
||
|
}
|