/
verify_user.go
50 lines (41 loc) · 1.1 KB
/
verify_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package reportverifs
import (
"context"
"github.com/pkg/errors"
"exusiai.dev/backend-next/internal/model/types"
"exusiai.dev/backend-next/internal/repo"
"exusiai.dev/gommon/constant"
)
var (
ErrAccountIDEmpty = errors.New("account id is empty")
ErrAccountNotFound = errors.New("account not found with given id")
)
type UserVerifier struct {
AccountRepo *repo.Account
}
// ensure UserVerifier conforms to Verifier
var _ Verifier = (*UserVerifier)(nil)
func NewUserVerifier(accountRepo *repo.Account) *UserVerifier {
return &UserVerifier{
AccountRepo: accountRepo,
}
}
func (u *UserVerifier) Name() string {
return "user"
}
func (u *UserVerifier) Verify(ctx context.Context, report *types.ReportTaskSingleReport, reportTask *types.ReportTask) *Rejection {
id := reportTask.AccountID
if id == 0 {
return &Rejection{
Reliability: constant.ViolationReliabilityUser,
Message: ErrAccountIDEmpty.Error(),
}
}
if !u.AccountRepo.IsAccountExistWithId(ctx, id) {
return &Rejection{
Reliability: constant.ViolationReliabilityUser,
Message: ErrAccountNotFound.Error(),
}
}
return nil
}