Skip to content

Commit a5d8ba7

Browse files
committed
feat: ent list req support base time fields
1 parent 97d9cf2 commit a5d8ba7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

api/gogen/ent/gen.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
323323
predicateData.WriteString(fmt.Sprintf("\tvar predicates []predicate.%s\n", schema.Name))
324324
count := 0
325325
for _, v := range schema.Fields {
326-
if entx.IsBaseProperty(v.Name) || count >= g.SearchKeyNum {
326+
if v.Name == "id" || count >= g.SearchKeyNum {
327327
continue
328328
}
329329

@@ -339,7 +339,7 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
339339
camelName, strings.ToLower(schema.Name), entx.ConvertSpecificNounToUpper(v.Name), camelName))
340340
count++
341341
} else if entx.IsTimeProperty(v.Info.Type.String()) {
342-
predicateData.WriteString(fmt.Sprintf("\tif req.%s != nil {\n\t\tpredicates = append(predicates, %s.%sGT(time.UnixMilli(*req.%s)))\n\t}\n",
342+
predicateData.WriteString(fmt.Sprintf("\tif req.%s != nil {\n\t\tpredicates = append(predicates, %s.%sGTE(time.UnixMilli(*req.%s)))\n\t}\n",
343343
camelName, strings.ToLower(schema.Name), entFieldName, camelName))
344344
count++
345345
} else {
@@ -411,8 +411,8 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
411411
"IdType": g.IdType,
412412
"HasCreated": g.HasCreated,
413413
"HasPointy": hasPointy,
414-
"hasTime": hasTime,
415-
"hasUUID": strings.Contains("uuidx.", predicateData.String()),
414+
"hasTime": strings.Contains(predicateData.String(), "time."),
415+
"hasUUID": strings.Contains(predicateData.String(), "uuidx."),
416416
})
417417

418418
data = append(data, &ApiLogicData{
@@ -476,7 +476,7 @@ func GenApiData(schema *load.Schema, ctx GenEntLogicContext) (string, error) {
476476
}
477477

478478
for _, v := range schema.Fields {
479-
if entx.IsBaseProperty(v.Name) {
479+
if v.Name == "id" {
480480
continue
481481
}
482482

@@ -507,7 +507,9 @@ func GenApiData(schema *load.Schema, ctx GenEntLogicContext) (string, error) {
507507
entx.ConvertEntTypeToGotypeInSingleApi(v.Info.Type.String()),
508508
jsonTag, optionalStr)
509509

510-
infoData.WriteString(structData)
510+
if !entx.IsBaseProperty(v.Name) {
511+
infoData.WriteString(structData)
512+
}
511513

512514
if searchKeyNum > 0 {
513515
listData.WriteString(structData)

rpc/generator/ent/gen.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
390390
predicateData.WriteString(fmt.Sprintf("\tvar predicates []predicate.%s\n", schema.Name))
391391
count := 0
392392
for _, v := range schema.Fields {
393-
if entx.IsBaseProperty(v.Name) || count >= g.SearchKeyNum {
393+
if v.Name == "id" || count >= g.SearchKeyNum {
394394
continue
395395
}
396396

@@ -406,7 +406,7 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
406406
camelName, strings.ToLower(schema.Name), entFieldName, camelName))
407407
count++
408408
} else if entx.IsTimeProperty(v.Info.Type.String()) {
409-
predicateData.WriteString(fmt.Sprintf("\tif in.%s != nil {\n\t\tpredicates = append(predicates, %s.%sGT(time.UnixMilli(*in.%s)))\n\t}\n",
409+
predicateData.WriteString(fmt.Sprintf("\tif in.%s != nil {\n\t\tpredicates = append(predicates, %s.%sGTE(time.UnixMilli(*in.%s)))\n\t}\n",
410410
camelName, strings.ToLower(schema.Name), entFieldName, camelName))
411411
count++
412412
} else {
@@ -492,8 +492,8 @@ func GenCRUDData(g *GenEntLogicContext, projectCtx *ctx.ProjectContext, schema *
492492
"importPrefix": g.ImportPrefix,
493493
"IdType": g.IdType,
494494
"HasCreated": g.HasCreated,
495-
"hasTime": hasTime,
496-
"hasUUID": strings.Contains("uuidx.", predicateData.String()),
495+
"hasTime": strings.Contains(predicateData.String(), "time."),
496+
"hasUUID": strings.Contains(predicateData.String(), "uuidx."),
497497
})
498498

499499
data = append(data, &RpcLogicData{
@@ -621,7 +621,7 @@ func GenProtoData(schema *load.Schema, g GenEntLogicContext) (string, string, er
621621
index = 3
622622

623623
for _, v := range schema.Fields {
624-
if entx.IsBaseProperty(v.Name) || count >= g.SearchKeyNum {
624+
if v.Name == "id" || count >= g.SearchKeyNum {
625625
continue
626626
}
627627

0 commit comments

Comments
 (0)