正在显示
7 个修改的文件
包含
139 行增加
和
28 行删除
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "github.com/tiptok/godevp/pkg/application/clientVersion/query" | 8 | "github.com/tiptok/godevp/pkg/application/clientVersion/query" |
9 | "github.com/tiptok/godevp/pkg/application/factory" | 9 | "github.com/tiptok/godevp/pkg/application/factory" |
10 | "github.com/tiptok/godevp/pkg/domain" | 10 | "github.com/tiptok/godevp/pkg/domain" |
11 | + "time" | ||
11 | ) | 12 | ) |
12 | 13 | ||
13 | // 客户端版本服务 | 14 | // 客户端版本服务 |
@@ -36,6 +37,7 @@ func (clientVersionService *ClientVersionService) CreateClientVersion(createClie | @@ -36,6 +37,7 @@ func (clientVersionService *ClientVersionService) CreateClientVersion(createClie | ||
36 | Title: createClientVersionCommand.Title, | 37 | Title: createClientVersionCommand.Title, |
37 | Remark: createClientVersionCommand.Remark, | 38 | Remark: createClientVersionCommand.Remark, |
38 | ClientPackageInfo: createClientVersionCommand.ClientPackageInfo, | 39 | ClientPackageInfo: createClientVersionCommand.ClientPackageInfo, |
40 | + CreateTime: time.Now(), | ||
39 | } | 41 | } |
40 | var clientVersionRepository domain.ClientVersionRepository | 42 | var clientVersionRepository domain.ClientVersionRepository |
41 | if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ | 43 | if value, err := factory.CreateClientVersionRepository(map[string]interface{}{ |
@@ -12,7 +12,7 @@ type UpdateUsersCommand struct { | @@ -12,7 +12,7 @@ type UpdateUsersCommand struct { | ||
12 | } | 12 | } |
13 | 13 | ||
14 | func (updateUsersCommand *UpdateUsersCommand) Valid(validation *validation.Validation) { | 14 | func (updateUsersCommand *UpdateUsersCommand) Valid(validation *validation.Validation) { |
15 | - validation.SetError("CustomValid", "未实现的自定义认证") | 15 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
16 | } | 16 | } |
17 | 17 | ||
18 | func (updateUsersCommand *UpdateUsersCommand) ValidateCommand() error { | 18 | func (updateUsersCommand *UpdateUsersCommand) ValidateCommand() error { |
@@ -2,6 +2,8 @@ package repository | @@ -2,6 +2,8 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/linmadan/egglib-go/persistent/pg/ormx" | ||
6 | + "strings" | ||
5 | 7 | ||
6 | "github.com/go-pg/pg/v10" | 8 | "github.com/go-pg/pg/v10" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 9 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
@@ -10,6 +12,15 @@ import ( | @@ -10,6 +12,15 @@ import ( | ||
10 | "github.com/tiptok/godevp/pkg/infrastructure/pg/models" | 12 | "github.com/tiptok/godevp/pkg/infrastructure/pg/models" |
11 | ) | 13 | ) |
12 | 14 | ||
15 | +var ( | ||
16 | + usersFields = ormx.FieldNames((*models.Users)(nil)) | ||
17 | + usersRowString = strings.Join(usersFields, ",") | ||
18 | + usersRowInsertFields = ormx.Remove(usersFields, "id") | ||
19 | + usersRowInsertString = strings.Join(usersRowInsertFields, ",") | ||
20 | + usersRowsInsertPlaceHolder = ormx.ParamPlaceHolder(len(usersRowInsertFields)) | ||
21 | + usersRowsUpdate = strings.Join(ormx.Remove(usersFields, "id"), "=?,") + "=?" | ||
22 | +) | ||
23 | + | ||
13 | type UsersRepository struct { | 24 | type UsersRepository struct { |
14 | transactionContext *pgTransaction.TransactionContext | 25 | transactionContext *pgTransaction.TransactionContext |
15 | } | 26 | } |
@@ -26,14 +37,14 @@ func (repository *UsersRepository) Save(users *users.Users) (*users.Users, error | @@ -26,14 +37,14 @@ func (repository *UsersRepository) Save(users *users.Users) (*users.Users, error | ||
26 | } | 37 | } |
27 | if _, err := tx.QueryOne( | 38 | if _, err := tx.QueryOne( |
28 | pg.Scan(&users.Id, &users.Name, &users.Phone, &users.Passwd, pg.Array(&users.Roles), &users.Status, &users.AdminType, &users.CreateTime, &users.UpdateTime), | 39 | pg.Scan(&users.Id, &users.Name, &users.Phone, &users.Passwd, pg.Array(&users.Roles), &users.Status, &users.AdminType, &users.CreateTime, &users.UpdateTime), |
29 | - "INSERT INTO users (name, phone, passwd, roles, status, admin_type, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, name, phone, passwd, roles, status, admin_type, create_time, update_time", | 40 | + "INSERT INTO users ("+usersRowInsertString+") VALUES ("+usersRowsInsertPlaceHolder+") RETURNING "+usersRowString, |
30 | users.Name, users.Phone, users.Passwd, pg.Array(users.Roles), users.Status, users.AdminType, users.CreateTime, users.UpdateTime); err != nil { | 41 | users.Name, users.Phone, users.Passwd, pg.Array(users.Roles), users.Status, users.AdminType, users.CreateTime, users.UpdateTime); err != nil { |
31 | return users, err | 42 | return users, err |
32 | } | 43 | } |
33 | } else { | 44 | } else { |
34 | if _, err := tx.QueryOne( | 45 | if _, err := tx.QueryOne( |
35 | pg.Scan(&users.Id, &users.Name, &users.Phone, &users.Passwd, pg.Array(&users.Roles), &users.Status, &users.AdminType, &users.CreateTime, &users.UpdateTime), | 46 | pg.Scan(&users.Id, &users.Name, &users.Phone, &users.Passwd, pg.Array(&users.Roles), &users.Status, &users.AdminType, &users.CreateTime, &users.UpdateTime), |
36 | - "UPDATE users SET name=?, phone=?, passwd=?, roles=?, status=?, admin_type=?, create_time=?, update_time=? WHERE id=? RETURNING id, name, phone, passwd, roles, status, admin_type, create_time, update_time", | 47 | + "UPDATE users SET "+usersRowsUpdate+" WHERE id=? RETURNING "+usersRowString, |
37 | users.Name, users.Phone, users.Passwd, pg.Array(users.Roles), users.Status, users.AdminType, users.CreateTime, users.UpdateTime, users.Identify()); err != nil { | 48 | users.Name, users.Phone, users.Passwd, pg.Array(users.Roles), users.Status, users.AdminType, users.CreateTime, users.UpdateTime, users.Identify()); err != nil { |
38 | return users, err | 49 | return users, err |
39 | } | 50 | } |
@@ -52,12 +63,12 @@ func (repository *UsersRepository) Remove(users *users.Users) (*users.Users, err | @@ -52,12 +63,12 @@ func (repository *UsersRepository) Remove(users *users.Users) (*users.Users, err | ||
52 | func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*users.Users, error) { | 63 | func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) (*users.Users, error) { |
53 | tx := repository.transactionContext.PgTx | 64 | tx := repository.transactionContext.PgTx |
54 | usersModel := new(models.Users) | 65 | usersModel := new(models.Users) |
55 | - query := tx.Model(usersModel) | 66 | + query := ormx.NewQuery(tx.Model(usersModel), queryOptions) |
56 | if usersId, ok := queryOptions["usersId"]; ok { | 67 | if usersId, ok := queryOptions["usersId"]; ok { |
57 | - query = query.Where("users.id = ?", usersId) | 68 | + query.Where("users.id = ?", usersId) |
58 | } | 69 | } |
59 | if phone, ok := queryOptions["phone"]; ok { | 70 | if phone, ok := queryOptions["phone"]; ok { |
60 | - query = query.Where("users.phone = ?", phone) | 71 | + query.Where("users.phone = ?", phone) |
61 | } | 72 | } |
62 | if err := query.First(); err != nil { | 73 | if err := query.First(); err != nil { |
63 | if err.Error() == "pg: no rows in result set" { | 74 | if err.Error() == "pg: no rows in result set" { |
@@ -76,23 +87,8 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in | @@ -76,23 +87,8 @@ func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (in | ||
76 | tx := repository.transactionContext.PgTx | 87 | tx := repository.transactionContext.PgTx |
77 | var usersModels []*models.Users | 88 | var usersModels []*models.Users |
78 | userss := make([]*users.Users, 0) | 89 | userss := make([]*users.Users, 0) |
79 | - query := tx.Model(&usersModels) | ||
80 | - if offset, ok := queryOptions["offset"]; ok { | ||
81 | - offset := offset.(int) | ||
82 | - if offset > -1 { | ||
83 | - query = query.Offset(offset) | ||
84 | - } | ||
85 | - } else { | ||
86 | - query = query.Offset(0) | ||
87 | - } | ||
88 | - if limit, ok := queryOptions["limit"]; ok { | ||
89 | - limit := limit.(int) | ||
90 | - if limit > -1 { | ||
91 | - query = query.Limit(limit) | ||
92 | - } | ||
93 | - } else { | ||
94 | - query = query.Limit(20) | ||
95 | - } | 90 | + query := ormx.NewQuery(tx.Model(&usersModels), queryOptions) |
91 | + query.SetLimit() | ||
96 | if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | 92 | if count, err := query.Order("id DESC").SelectAndCount(); err != nil { |
97 | return 0, userss, err | 93 | return 0, userss, err |
98 | } else { | 94 | } else { |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | schema: | 2 | schema: |
3 | - graph/*.graphqls | 3 | - graph/*.graphqls |
4 | - graph/access/*.graphqls | 4 | - graph/access/*.graphqls |
5 | + - graph/schema/*.graphqls | ||
5 | 6 | ||
6 | # Where should the generated server code go? | 7 | # Where should the generated server code go? |
7 | exec: | 8 | exec: |
@@ -19,13 +20,14 @@ model: | @@ -19,13 +20,14 @@ model: | ||
19 | package: model | 20 | package: model |
20 | 21 | ||
21 | # Where should the resolver implementations go? | 22 | # Where should the resolver implementations go? |
23 | +#resolver: | ||
24 | +# layout: follow-schema | ||
25 | +# dir: graph | ||
26 | +# package: graph | ||
22 | resolver: | 27 | resolver: |
23 | layout: follow-schema | 28 | layout: follow-schema |
24 | - dir: graph | ||
25 | - package: graph | ||
26 | -#resolver: | ||
27 | -# filename: resolver.go | ||
28 | -# type: Resolver | 29 | + dir: graph/resolvers |
30 | + package: resolvers | ||
29 | 31 | ||
30 | # Optional: turn on use `gqlgen:"fieldName"` tags in your models | 32 | # Optional: turn on use `gqlgen:"fieldName"` tags in your models |
31 | # struct_tag: json | 33 | # struct_tag: json |
1 | +package resolvers | ||
2 | + | ||
3 | +// This file will be automatically regenerated based on the schema, any resolver implementations | ||
4 | +// will be copied through when generating and any unknown code will be moved to the end. | ||
5 | + | ||
6 | +import ( | ||
7 | + "context" | ||
8 | + "fmt" | ||
9 | + | ||
10 | + "github.com/tiptok/godevp/pkg/port/graphql/graph/generated" | ||
11 | + "github.com/tiptok/godevp/pkg/port/graphql/graph/model" | ||
12 | +) | ||
13 | + | ||
14 | +func (r *accessResolver) User(ctx context.Context, obj *model.Access) (*model.Users, error) { | ||
15 | + panic(fmt.Errorf("not implemented")) | ||
16 | +} | ||
17 | + | ||
18 | +func (r *mutationResolver) CreateMenu(ctx context.Context, input *model.MenuAccessInput) ([]*model.Access, error) { | ||
19 | + panic(fmt.Errorf("not implemented")) | ||
20 | +} | ||
21 | + | ||
22 | +func (r *queryResolver) Menu(ctx context.Context, input *model.MenuAccessInput) ([]*model.Access, error) { | ||
23 | + panic(fmt.Errorf("not implemented")) | ||
24 | +} | ||
25 | + | ||
26 | +// Access returns generated.AccessResolver implementation. | ||
27 | +func (r *Resolver) Access() generated.AccessResolver { return &accessResolver{r} } | ||
28 | + | ||
29 | +type accessResolver struct{ *Resolver } |
pkg/port/graphql/graph/resolvers/resolver.go
0 → 100644
1 | +package resolvers | ||
2 | + | ||
3 | +// This file will be automatically regenerated based on the schema, any resolver implementations | ||
4 | +// will be copied through when generating and any unknown code will be moved to the end. | ||
5 | + | ||
6 | +import ( | ||
7 | + "context" | ||
8 | + "fmt" | ||
9 | + | ||
10 | + "github.com/tiptok/godevp/pkg/domain" | ||
11 | + "github.com/tiptok/godevp/pkg/port/graphql/graph/generated" | ||
12 | + "github.com/tiptok/godevp/pkg/port/graphql/graph/libs" | ||
13 | + "github.com/tiptok/godevp/pkg/port/graphql/graph/model" | ||
14 | +) | ||
15 | + | ||
16 | +func (r *clientVersionResolver) CreateTime(ctx context.Context, obj *domain.ClientVersion) (*libs.Datetime, error) { | ||
17 | + panic(fmt.Errorf("not implemented")) | ||
18 | +} | ||
19 | + | ||
20 | +func (r *mutationResolver) CreateUsers(ctx context.Context, input model.CreateUsersInput) (*model.Users, error) { | ||
21 | + panic(fmt.Errorf("not implemented")) | ||
22 | +} | ||
23 | + | ||
24 | +func (r *mutationResolver) RemoveUsers(ctx context.Context, input model.RemoveUsersInput) (*model.Users, error) { | ||
25 | + panic(fmt.Errorf("not implemented")) | ||
26 | +} | ||
27 | + | ||
28 | +func (r *mutationResolver) UpdateUsers(ctx context.Context, input model.UpdateUsersInput) (*model.Users, error) { | ||
29 | + panic(fmt.Errorf("not implemented")) | ||
30 | +} | ||
31 | + | ||
32 | +func (r *queryResolver) User(ctx context.Context, input model.GetUsersInput) (*model.Users, error) { | ||
33 | + panic(fmt.Errorf("not implemented")) | ||
34 | +} | ||
35 | + | ||
36 | +func (r *queryResolver) Users(ctx context.Context, input model.ListUsersInput) ([]*model.Users, error) { | ||
37 | + panic(fmt.Errorf("not implemented")) | ||
38 | +} | ||
39 | + | ||
40 | +func (r *queryResolver) Menus(ctx context.Context, input *model.MenuAccessInput) ([]*model.Access, error) { | ||
41 | + panic(fmt.Errorf("not implemented")) | ||
42 | +} | ||
43 | + | ||
44 | +func (r *queryResolver) ClientVersion(ctx context.Context, id *int) (*domain.ClientVersion, error) { | ||
45 | + panic(fmt.Errorf("not implemented")) | ||
46 | +} | ||
47 | + | ||
48 | +func (r *roleResolver) Access(ctx context.Context, obj *model.Role) ([]*model.Access, error) { | ||
49 | + panic(fmt.Errorf("not implemented")) | ||
50 | +} | ||
51 | + | ||
52 | +func (r *usersResolver) Roles(ctx context.Context, obj *model.Users) ([]*model.Role, error) { | ||
53 | + panic(fmt.Errorf("not implemented")) | ||
54 | +} | ||
55 | + | ||
56 | +// ClientVersion returns generated.ClientVersionResolver implementation. | ||
57 | +func (r *Resolver) ClientVersion() generated.ClientVersionResolver { return &clientVersionResolver{r} } | ||
58 | + | ||
59 | +// Mutation returns generated.MutationResolver implementation. | ||
60 | +func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} } | ||
61 | + | ||
62 | +// Query returns generated.QueryResolver implementation. | ||
63 | +func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } | ||
64 | + | ||
65 | +// Role returns generated.RoleResolver implementation. | ||
66 | +func (r *Resolver) Role() generated.RoleResolver { return &roleResolver{r} } | ||
67 | + | ||
68 | +// Users returns generated.UsersResolver implementation. | ||
69 | +func (r *Resolver) Users() generated.UsersResolver { return &usersResolver{r} } | ||
70 | + | ||
71 | +type clientVersionResolver struct{ *Resolver } | ||
72 | +type mutationResolver struct{ *Resolver } | ||
73 | +type queryResolver struct{ *Resolver } | ||
74 | +type roleResolver struct{ *Resolver } | ||
75 | +type usersResolver struct{ *Resolver } |
-
请 注册 或 登录 后发表评论