2024-01-14 15:53:37 +00:00
|
|
|
package mysqlbenefactor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-15 10:33:24 +00:00
|
|
|
"errors"
|
2024-01-14 15:53:37 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
2024-07-30 11:05:41 +00:00
|
|
|
func (d *DB) IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error) {
|
2024-01-14 15:53:37 +00:00
|
|
|
const op = "mysqlbenefactor.IsExistBenefactorByPhoneNumber"
|
|
|
|
|
2024-09-09 08:17:30 +00:00
|
|
|
bnf, err := d.GetByPhoneNumber(ctx, phoneNumber)
|
2024-07-30 11:05:41 +00:00
|
|
|
if err != nil {
|
2024-09-09 08:17:30 +00:00
|
|
|
var richErr richerror.RichError
|
|
|
|
if errors.As(err, &richErr) && richErr.Kind() == richerror.KindNotFound {
|
2024-01-15 10:33:24 +00:00
|
|
|
return false, entity.Benefactor{}, nil
|
2024-01-14 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
2024-09-09 08:17:30 +00:00
|
|
|
return false, entity.Benefactor{}, richerror.New(op).WithErr(err)
|
2024-01-14 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
2024-09-09 08:17:30 +00:00
|
|
|
return true, bnf, nil
|
2024-01-14 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 16:13:06 +00:00
|
|
|
func (d *DB) IsExistBenefactorByID(ctx context.Context, id uint) (bool, error) {
|
|
|
|
const op = "mysqlbenefactor.IsExistBenefactorByID"
|
|
|
|
|
2024-09-09 08:17:30 +00:00
|
|
|
_, err := d.GetByID(ctx, id)
|
2024-07-30 11:05:41 +00:00
|
|
|
if err != nil {
|
2024-09-09 08:17:30 +00:00
|
|
|
var richErr richerror.RichError
|
|
|
|
if errors.As(err, &richErr) && richErr.Kind() == richerror.KindNotFound {
|
2024-01-16 16:13:06 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2024-09-09 08:17:30 +00:00
|
|
|
return false, richerror.New(op).WithErr(err)
|
2024-01-16 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|