schema.resolvers.go
6.0 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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"
query2 "github.com/tiptok/godevp/pkg/application/clientVersion/query"
"unsafe"
"github.com/tiptok/gocomm/common"
clientVersionService "github.com/tiptok/godevp/pkg/application/clientVersion/service"
"github.com/tiptok/godevp/pkg/application/factory"
"github.com/tiptok/godevp/pkg/application/users/command"
"github.com/tiptok/godevp/pkg/application/users/query"
"github.com/tiptok/godevp/pkg/application/users/service"
domain1 "github.com/tiptok/godevp/pkg/domain"
"github.com/tiptok/godevp/pkg/domain/role"
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/libs"
"github.com/tiptok/godevp/pkg/port/graphql/graph/model"
)
func (r *clientVersionResolver) CreateTime(ctx context.Context, obj *domain1.ClientVersion) (*libs.Datetime, error) {
return libs.NewDatetimeFromTime(obj.CreateTime), nil
}
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) User(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) Users(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 *queryResolver) Menus(ctx context.Context, input *model.MenuAccessInput) ([]*model.Access, error) {
transactionContext, _ := factory.CreateDefaultTransactionContext(nil)
var AccessRepository, _ = factory.CreateAccessRepository(map[string]interface{}{"transactionContext": transactionContext})
_, access, _ := AccessRepository.Find(map[string]interface{}{})
var rsp []*model.Access
for _, item := range access {
rsp = append(rsp, &model.Access{
ID: (*int)(unsafe.Pointer(&item.Id)),
ParentID: (*int)(unsafe.Pointer(&item.ParentId)),
AccessName: &item.AccessName,
AccessCode: &item.AccessCode,
AccessType: &item.AccessType,
Sort: (*int)(unsafe.Pointer(&item.Sort)),
Object: &item.Object,
Action: &item.Action,
Module: &item.Module,
Icon: &item.Icon,
Status: (*int)(unsafe.Pointer(&item.Status)),
})
}
return rsp, nil
}
func (r *queryResolver) ClientVersion(ctx context.Context, id *int) (*domain1.ClientVersion, error) {
svr := clientVersionService.NewClientVersionService(nil)
m, err := svr.GetClientVersion(&query2.GetClientVersionQuery{Id: int64(*id)})
if err != nil || m == nil {
return nil, err
}
return m.(*domain1.ClientVersion), nil
}
func (r *roleResolver) Access(ctx context.Context, obj *model.Role) ([]*model.Access, error) {
return []*model.Access{
&model.Access{},
}, nil
}
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
}
// ClientVersion returns generated.ClientVersionResolver implementation.
func (r *Resolver) ClientVersion() generated.ClientVersionResolver { return &clientVersionResolver{r} }
// 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} }
// Role returns generated.RoleResolver implementation.
func (r *Resolver) Role() generated.RoleResolver { return &roleResolver{r} }
// Users returns generated.UsersResolver implementation.
func (r *Resolver) Users() generated.UsersResolver { return &usersResolver{r} }
type clientVersionResolver struct{ *Resolver }
type mutationResolver struct{ *Resolver }
type queryResolver struct{ *Resolver }
type roleResolver struct{ *Resolver }
type usersResolver struct{ *Resolver }