Skip to content

Commit f49fdda

Browse files
committed
fix: remove configs layer #4
1 parent 9877119 commit f49fdda

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

generator.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ type generator struct {
4949
}
5050

5151
func (g *generator) setting() {
52-
g.ImportName = ImportName
5352
g.GoGenerate = "go:generate"
5453
g.RepositoryInterfaceName = g.StructName + "Repository"
5554
g.setRepositoryStructName()
@@ -120,7 +119,7 @@ func (g *generator) generateConstant(writer io.Writer) {
120119
}
121120

122121
const tmplConst = `// THIS FILE IS A GENERATED CODE. DO NOT EDIT
123-
package configs
122+
package {{ .PackageName }}
124123
125124
import "strconv"
126125
@@ -160,7 +159,7 @@ func (str IntegerCriteria) Int64() int64 {
160159
`
161160

162161
const tmplLabel = `// THIS FILE IS A GENERATED CODE. EDIT OK
163-
package configs
162+
package {{ .PackageName }}
164163
165164
const (
166165
{{- range $fi := .FieldInfos }}
@@ -183,7 +182,6 @@ import (
183182
{{- end }}
184183
185184
"cloud.google.com/go/datastore"
186-
"{{ .ImportName }}/configs"
187185
{{- if eq .EnableIndexes true }}
188186
"github.com/knightso/xian"
189187
{{- end }}
@@ -256,21 +254,21 @@ func (repo *{{ .RepositoryStructName }}) getKeys(subjects ...*{{ .StructName }})
256254
// saveIndexes 拡張フィルタを保存する
257255
func (repo *{{ .RepositoryStructName }}) saveIndexes(subjects ...*{{ .StructName }}) error {
258256
for _, subject := range subjects {
259-
idx := xian.NewIndexes({{ .LowerStructName }}IndexesConfig)
257+
idx := xian.NewIndexes({{ .StructName }}IndexesConfig)
260258
{{- range $fi := .FieldInfos }}
261259
{{- range $idx := $fi.Indexes }}
262260
{{- if eq $fi.FieldType "bool" }}
263-
idx.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, subject.{{ $fi.Field }})
261+
idx.{{ $idx.Method }}({{ $idx.ConstName }}, subject.{{ $fi.Field }})
264262
{{- else if eq $fi.FieldType "string" }}
265263
{{- if eq $idx.Method "AddPrefix" }}
266-
idx.{{ $idx.Method }}es(configs.{{ $idx.ConstName }}, subject.{{ $fi.Field }})
264+
idx.{{ $idx.Method }}es({{ $idx.ConstName }}, subject.{{ $fi.Field }})
267265
{{- else }}
268-
idx.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, subject.{{ $fi.Field }})
266+
idx.{{ $idx.Method }}({{ $idx.ConstName }}, subject.{{ $fi.Field }})
269267
{{- end }}
270268
{{- else if eq $fi.FieldType "int" }}
271-
idx.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, subject.{{ $fi.Field }})
269+
idx.{{ $idx.Method }}({{ $idx.ConstName }}, subject.{{ $fi.Field }})
272270
{{- else if eq $fi.FieldType "time.Time" }}
273-
idx.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, subject.{{ $fi.Field }}.Unix())
271+
idx.{{ $idx.Method }}({{ $idx.ConstName }}, subject.{{ $fi.Field }}.Unix())
274272
{{- end }}
275273
{{- end }}
276274
{{- end }}
@@ -291,13 +289,13 @@ var {{ .LowerStructName }}IndexesConfig = &xian.Config{
291289
{{- end }}
292290
293291
// {{ .StructName }}ListReq List取得時に渡すリクエスト
294-
// └─ bool/int(64) は stringで渡す(configs.BoolCriteria | configs.IntegerCriteria)
292+
// └─ bool/int(64) は stringで渡す(BoolCriteria | IntegerCriteria)
295293
type {{ .StructName }}ListReq struct {
296294
{{- range .FieldInfos }}
297295
{{- if eq .FieldType "bool" }}
298-
{{ .Field }} configs.BoolCriteria
296+
{{ .Field }} BoolCriteria
299297
{{- else if or (eq .FieldType "int") (eq .FieldType "int64") }}
300-
{{ .Field }} configs.IntegerCriteria
298+
{{ .Field }} IntegerCriteria
301299
{{- else }}
302300
{{ .Field }} {{ .FieldType }}
303301
{{- end }}
@@ -321,7 +319,7 @@ func (repo *{{ .RepositoryStructName }}) List(ctx context.Context, req *{{ .Stru
321319
if req.{{ $fi.Field }} != "" {
322320
{{- if eq $Enable true }}
323321
{{- range $idx := $fi.Indexes }}
324-
filters.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, req.{{ $fi.Field }})
322+
filters.{{ $idx.Method }}({{ $idx.ConstName }}, req.{{ $fi.Field }})
325323
{{- end }}
326324
{{- else }}
327325
q = q.Filter("{{ $fi.DsTag }} =", req.{{ $fi.Field }}.Bool())
@@ -331,17 +329,17 @@ func (repo *{{ .RepositoryStructName }}) List(ctx context.Context, req *{{ .Stru
331329
if req.{{ $fi.Field }} != "" {
332330
{{- if eq $Enable true }}
333331
{{- range $idx := $fi.Indexes }}
334-
filters.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, req.{{ $fi.Field }})
332+
filters.{{ $idx.Method }}({{ $idx.ConstName }}, req.{{ $fi.Field }})
335333
{{- end }}
336334
{{- else }}
337335
q = q.Filter("{{ $fi.DsTag }} =", req.{{ $fi.Field }})
338336
{{- end }}
339337
}
340338
{{- else if or (eq $fi.FieldType "int") (eq $fi.FieldType "int64") }}
341-
if req.{{ $fi.Field }} != configs.IntegerCriteriaEmpty {
339+
if req.{{ $fi.Field }} != IntegerCriteriaEmpty {
342340
{{- if eq $Enable true }}
343341
{{- range $idx := $fi.Indexes }}
344-
filters.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, req.{{ Parse $fi.Field $fi.FieldType }})
342+
filters.{{ $idx.Method }}({{ $idx.ConstName }}, req.{{ Parse $fi.Field $fi.FieldType }})
345343
{{- end }}
346344
{{- else }}
347345
q = q.Filter("{{ $fi.DsTag }} =", req.{{ Parse $fi.Field $fi.FieldType }})
@@ -351,7 +349,7 @@ func (repo *{{ .RepositoryStructName }}) List(ctx context.Context, req *{{ .Stru
351349
if !req.{{ $fi.Field }}.IsZero() {
352350
{{- if eq $Enable true }}
353351
{{- range $idx := $fi.Indexes }}
354-
filters.{{ $idx.Method }}(configs.{{ $idx.ConstName }}, req.{{ $fi.Field }}.Unix())
352+
filters.{{ $idx.Method }}({{ $idx.ConstName }}, req.{{ $fi.Field }}.Unix())
355353
{{- end }}
356354
{{- else }}
357355
q = q.Filter("{{ $fi.DsTag }} =", req.{{ $fi.Field }})

testfiles/a/configs/constant.go renamed to testfiles/a/constant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// THIS FILE IS A GENERATED CODE. DO NOT EDIT
2-
package configs
2+
package task
33

44
import "strconv"
55

testfiles/a/tests/task_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"cloud.google.com/go/datastore"
1313
task "github.com/go-generalize/repo_generator/testfiles/a"
14-
"github.com/go-generalize/repo_generator/testfiles/a/configs"
1514
)
1615

1716
func initDatastoreClient(t *testing.T) *datastore.Client {
@@ -90,7 +89,7 @@ func TestDatastoreListTask(t *testing.T) {
9089

9190
t.Run("int(1件)", func(t *testing.T) {
9291
req := &task.TaskListReq{
93-
Count: configs.IntegerCriteria("1"), // FIXME 2 この実装をどうにかしたい
92+
Count: task.IntegerCriteria("1"), // FIXME 2 この実装をどうにかしたい
9493
}
9594

9695
tasks, err := taskRepo.List(ctx, req, nil)
@@ -105,7 +104,7 @@ func TestDatastoreListTask(t *testing.T) {
105104

106105
t.Run("bool(10件)", func(t *testing.T) {
107106
req := &task.TaskListReq{
108-
Done: configs.BoolCriteriaTrue,
107+
Done: task.BoolCriteriaTrue,
109108
}
110109

111110
tasks, err := taskRepo.List(ctx, req, nil)
@@ -171,7 +170,7 @@ func TestDatastoreListNameWithIndexes(t *testing.T) {
171170

172171
t.Run("int(1件)", func(t *testing.T) {
173172
req := &task.NameListReq{
174-
Count: configs.IntegerCriteria("1"), // FIXME 2 この実装をどうにかしたい
173+
Count: task.IntegerCriteria("1"), // FIXME 2 この実装をどうにかしたい
175174
}
176175

177176
tasks, err := nameRepo.List(ctx, req, nil)
@@ -186,7 +185,7 @@ func TestDatastoreListNameWithIndexes(t *testing.T) {
186185

187186
t.Run("bool(10件)", func(t *testing.T) {
188187
req := &task.NameListReq{
189-
Done: configs.BoolCriteriaTrue,
188+
Done: task.BoolCriteriaTrue,
190189
}
191190

192191
tasks, err := nameRepo.List(ctx, req, nil)

0 commit comments

Comments
 (0)