forked from ebhomengo/niki
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package mysqlbenefactor
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
)
|
|
|
|
func (d *DB) IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error) {
|
|
const op = "mysqlbenefactor.IsExistBenefactorByPhoneNumber"
|
|
|
|
bnf, err := d.GetByPhoneNumber(ctx, phoneNumber)
|
|
if err != nil {
|
|
var richErr richerror.RichError
|
|
if errors.As(err, &richErr) && richErr.Kind() == richerror.KindNotFound {
|
|
return false, entity.Benefactor{}, nil
|
|
}
|
|
|
|
return false, entity.Benefactor{}, richerror.New(op).WithErr(err)
|
|
}
|
|
|
|
return true, bnf, nil
|
|
}
|
|
|
|
func (d *DB) IsExistBenefactorByID(ctx context.Context, id uint) (bool, error) {
|
|
const op = "mysqlbenefactor.IsExistBenefactorByID"
|
|
|
|
_, err := d.GetByID(ctx, id)
|
|
if err != nil {
|
|
var richErr richerror.RichError
|
|
if errors.As(err, &richErr) && richErr.Kind() == richerror.KindNotFound {
|
|
return false, nil
|
|
}
|
|
|
|
return false, richerror.New(op).WithErr(err)
|
|
}
|
|
|
|
return true, nil
|
|
}
|