schema.resolvers.go
3.8 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"fmt"
"github.com/tiptok/godevp/pkg/domain/role"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/godevp/pkg/application/users/command"
"github.com/tiptok/godevp/pkg/application/users/query"
"github.com/tiptok/godevp/pkg/application/users/service"
domain "github.com/tiptok/godevp/pkg/domain/users"
"github.com/tiptok/godevp/pkg/port/graphql/graph/generated"
"github.com/tiptok/godevp/pkg/port/graphql/graph/model"
)
func (r *mutationResolver) CreateUsers(ctx context.Context, input model.CreateUsersInput) (*model.Users, error) {
usersService := service.NewUsersService(nil)
createUsersCommand := &command.CreateUsersCommand{
Name: input.Name,
Phone: input.Phone,
}
data, err := usersService.CreateUsers(createUsersCommand)
if err != nil {
return nil, err
}
if user, ok := data.(*domain.Users); ok {
return &model.Users{
Name: &user.Name,
Phone: &user.Phone,
}, nil
}
return nil, fmt.Errorf("type error except: domain.Users")
}
func (r *mutationResolver) RemoveUsers(ctx context.Context, input model.RemoveUsersInput) (*model.Users, error) {
panic(fmt.Errorf("not implemented"))
}
func (r *mutationResolver) UpdateUsers(ctx context.Context, input model.UpdateUsersInput) (*model.Users, error) {
panic(fmt.Errorf("not implemented"))
}
func (r *queryResolver) GetUsers(ctx context.Context, input model.GetUsersInput) (*model.Users, error) {
usersService := service.NewUsersService(nil)
getUsersCommand := &query.GetUsersQuery{
UsersId: int64(input.ID),
}
data, err := usersService.GetUsers(getUsersCommand)
if err != nil {
return nil, err
}
if user, ok := data.(*domain.Users); ok {
return &model.Users{
Name: &user.Name,
Phone: &user.Phone,
Status: &user.Status,
}, nil
}
return nil, fmt.Errorf("type error except: domain.Users")
}
func (r *queryResolver) FindUsers(ctx context.Context, input model.ListUsersInput) ([]*model.Users, error) {
usersService := service.NewUsersService(nil)
getUsersCommand := &query.ListUsersQuery{
Limit: input.Limit,
Offset: input.Offset,
}
data, err := usersService.ListUsers(getUsersCommand)
if err != nil {
return nil, err
}
if userMap, ok := data.(map[string]interface{}); ok {
users := userMap["users"].([]*domain.Users)
var ret []*model.Users
for _, user := range users {
createTime := common.AssertString(user.CreateTime.Unix())
updateTime := common.AssertString(user.UpdateTime.Unix())
ret = append(ret, &model.Users{
Name: &user.Name,
Phone: &user.Phone,
Status: &user.Status,
AdminType: &user.AdminType,
CreateTime: &createTime,
UpdateTime: &updateTime,
})
}
return ret, nil
}
return nil, fmt.Errorf("type error except: domain.Users")
}
func (r *usersResolver) Roles(ctx context.Context, obj *model.Users) ([]*model.Role, error) {
var ro = &role.Role{
Id: 1,
RoleName: "ccc",
ParentId: 1,
}
var id = int(ro.Id)
return []*model.Role{
&model.Role{
ID: &id,
RoleName: &ro.RoleName,
},
&model.Role{
ID: &id,
RoleName: &ro.RoleName,
},
}, nil
}
// Mutation returns generated.MutationResolver implementation.
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
// Query returns generated.QueryResolver implementation.
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
// Users returns generated.UsersResolver implementation.
func (r *Resolver) Users() generated.UsersResolver { return &usersResolver{r} }
type mutationResolver struct{ *Resolver }
type queryResolver struct{ *Resolver }
type usersResolver struct{ *Resolver }