/
app.go
77 lines (57 loc) · 1.63 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package user
import (
"context"
"github.com/m0t0k1ch1/metamask-login-sample/application"
)
type Application interface {
GetUser(ctx context.Context, in *GetUserInput) (*GetUserOutput, error)
UpdateUser(ctx context.Context, in *UpdateUserInput) (*UpdateUserOutput, error)
DeleteUser(ctx context.Context, in *DeleteUserInput) (*DeleteUserOutput, error)
}
type applicationImpl struct {
*application.Core
}
func NewApplication(core *application.Core) Application {
return &applicationImpl{core}
}
func (app *applicationImpl) GetUser(ctx context.Context, in *GetUserInput) (*GetUserOutput, error) {
if err := in.Validate(); err != nil {
return nil, err
}
address := in.Address()
u, err := app.Repositories.User.Get(ctx, address)
if err != nil {
return nil, err
}
return NewGetUserOutput(u), nil
}
func (app *applicationImpl) UpdateUser(ctx context.Context, in *UpdateUserInput) (*UpdateUserOutput, error) {
if err := in.Validate(); err != nil {
return nil, err
}
address := in.Address()
name := in.Name
u, err := app.Repositories.User.Get(ctx, address)
if err != nil {
return nil, err
}
u.Name = name
if err := app.Repositories.User.Update(ctx, u); err != nil {
return nil, err
}
return NewUpdateUserOutput(), nil
}
func (app *applicationImpl) DeleteUser(ctx context.Context, in *DeleteUserInput) (*DeleteUserOutput, error) {
if err := in.Validate(); err != nil {
return nil, err
}
address := in.Address()
u, err := app.Repositories.User.Get(ctx, address)
if err != nil {
return nil, err
}
if err := app.Repositories.User.Delete(ctx, u); err != nil {
return nil, err
}
return NewDeleteUserOutput(), nil
}