go-duck-cli 1.4.17 → 1.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -121,11 +121,25 @@ export const generateSwaggerDocs = async (config, entities, outputDir, openEntit
121
121
 
122
122
  regPath(`${basePath}/${name}s`, 'get', {
123
123
  summary: `Get all ${capitalized}s`,
124
+ description: `Retrieves a paginated list of ${capitalized}s. Supports JPA-style dynamic scalar filtering and relationship eager-loading.`,
124
125
  parameters: [
125
126
  ...commonHeaders,
126
127
  { name: 'page', in: 'query', schema: { type: 'integer' }, description: 'Zero-based page index' },
127
128
  { name: 'size', in: 'query', schema: { type: 'integer' }, description: 'Records per page' },
128
- { name: 'eager', in: 'query', schema: { type: 'boolean' }, description: 'If true, performs SQL Join to fetch relations' }
129
+ { name: 'sort', in: 'query', schema: { type: 'string' }, description: 'Sort criteria (e.g., name,desc)' },
130
+ { name: 'eager', in: 'query', schema: { type: 'boolean' }, description: 'If true, performs SQL Join to fetch relations' },
131
+ ...entity.fields.map(f => ({
132
+ name: f.name,
133
+ in: 'query',
134
+ schema: getSwaggerFieldSchema(f.type),
135
+ description: `Filter exactly by ${f.name}`
136
+ })),
137
+ ...entity.relationships.filter(r => r.to.entity === capitalized).map(r => ({
138
+ name: r.to.field + 'Id',
139
+ in: 'query',
140
+ schema: { type: 'integer' },
141
+ description: `Filter by foreign key ${r.to.field}Id`
142
+ }))
129
143
  ],
130
144
  responses: { 200: { description: 'OK', content: { 'application/json': { schema: { type: 'array', items: { $ref: `#/components/schemas/${capitalized}` } } } } } }
131
145
  }, 'read');
@@ -143,12 +157,20 @@ export const generateSwaggerDocs = async (config, entities, outputDir, openEntit
143
157
  regPath(`${basePath}/${name}s/{id}`, 'put', {
144
158
  summary: `Update ${capitalized}`,
145
159
  parameters: [...commonHeaders, { name: 'id', in: 'path', required: true, schema: { type: 'integer' } }],
160
+ requestBody: {
161
+ required: true,
162
+ content: { 'application/json': { schema: { $ref: `#/components/schemas/${capitalized}` } } }
163
+ },
146
164
  responses: { 200: { description: 'Updated', content: { 'application/json': { schema: { $ref: `#/components/schemas/${capitalized}` } } } } }
147
165
  }, 'update');
148
166
 
149
167
  regPath(`${basePath}/${name}s/{id}`, 'patch', {
150
168
  summary: `Patch ${capitalized}`,
151
169
  parameters: [...commonHeaders, { name: 'id', in: 'path', required: true, schema: { type: 'integer' } }],
170
+ requestBody: {
171
+ required: true,
172
+ content: { 'application/json': { schema: { $ref: `#/components/schemas/${capitalized}` } } }
173
+ },
152
174
  responses: { 200: { description: 'Patched' } }
153
175
  }, 'update');
154
176
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-duck-cli",
3
- "version": "1.4.17",
3
+ "version": "1.4.19",
4
4
  "description": "The Ultimate Evolutionary Go Microservice Scaffolder.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -34,7 +34,6 @@
34
34
  "generator",
35
35
  "go-duck"
36
36
  ],
37
-
38
37
  "repository": {
39
38
  "type": "git",
40
39
  "url": "git+https://github.com/heavenscode/go-duck.git"
@@ -4,6 +4,7 @@ import (
4
4
  "net/http"
5
5
  "strconv"
6
6
  "strings"
7
+ "regexp"
7
8
  {{#if isSearchable}}
8
9
  "context"
9
10
  {{/if}}
@@ -215,10 +216,10 @@ func (ctrl *{{capitalize name}}Controller) GetAll(c *gin.Context) {
215
216
  db, _ := c.Get("tenantMongoDB")
216
217
  tenantDB := db.(*mongo.Database)
217
218
 
218
- // PostgREST-lite Filter Translation (Simple eq check for now)
219
+ // PostgREST-lite Filter Translation
219
220
  filter := bson.M{}
220
221
  for k, v := range c.Request.URL.Query() {
221
- if k != "page" && k != "size" && k != "federated" {
222
+ if k != "page" && k != "size" && k != "federated" && k != "sort" && k != "eager" {
222
223
  filter[k] = v[0]
223
224
  }
224
225
  }
@@ -298,6 +299,30 @@ func (ctrl *{{capitalize name}}Controller) GetAll(c *gin.Context) {
298
299
 
299
300
  var entities []models.{{capitalize name}}
300
301
  query := tenantDB.WithContext(ctx)
302
+
303
+ // Dynamic Eager Loading
304
+ if c.DefaultQuery("eager", "false") == "true" {
305
+ {{#each relationships}}
306
+ {{#if (eq from.entity ../name)}}
307
+ query = query.Preload("{{capitalize to.entity}}")
308
+ {{else}}
309
+ query = query.Preload("{{capitalize from.entity}}")
310
+ {{/if}}
311
+ {{/each}}
312
+ }
313
+
314
+ // Dynamic Filtering (JPA-style)
315
+ for k, v := range c.Request.URL.Query() {
316
+ if k != "page" && k != "size" && k != "federated" && k != "sort" && k != "eager" {
317
+ // Convert camelCase to snake_case for PostgreSQL
318
+ var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
319
+ var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
320
+ snake := matchFirstCap.ReplaceAllString(k, "${1}_${2}")
321
+ snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}")
322
+ query = query.Where(strings.ToLower(snake)+" = ?", v[0])
323
+ }
324
+ }
325
+
301
326
  if sortParam != "" {
302
327
  query = query.Order(strings.ReplaceAll(sortParam, ",", " "))
303
328
  }