-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_challenge.go
40 lines (30 loc) · 996 Bytes
/
get_challenge.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
package usecases
import (
"context"
"github.com/etheralley/etheralley-backend/common"
"github.com/etheralley/etheralley-backend/core/entities"
"github.com/etheralley/etheralley-backend/core/gateways"
)
func NewGetChallenge(cacheGateway gateways.ICacheGateway) IGetChallengeUseCase {
return &getChallengeUseCase{
cacheGateway,
}
}
type getChallengeUseCase struct {
cacheGateway gateways.ICacheGateway
}
type IGetChallengeUseCase interface {
// Get a new challenge message for the provided address
Do(ctx context.Context, input *GetChallengeInput) (*entities.Challenge, error)
}
type GetChallengeInput struct {
Address string `validate:"required,eth_addr"`
}
func (uc *getChallengeUseCase) Do(ctx context.Context, input *GetChallengeInput) (*entities.Challenge, error) {
if err := common.ValidateStruct(input); err != nil {
return nil, err
}
challenge := entities.NewChallenge(input.Address)
err := uc.cacheGateway.SaveChallenge(ctx, challenge)
return challenge, err
}