File tree 3 files changed +17
-2
lines changed
3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ type CreateCategoryDto struct {
27
27
UserId * string `json:"user_id,omitempty" db:"user_id"`
28
28
}
29
29
30
+ type CategoryInfoDto struct {
31
+ Id * string `json:"id,omitempty" db:"id"`
32
+ Name * string `json:"name,omitempty" db:"name"`
33
+ NameRu * string `json:"name_ru,omitempty" db:"name_ru"`
34
+ Slug * string `json:"slug,omitempty" db:"slug"`
35
+ }
36
+
30
37
func registerRoutes (r chi.Router , db * sqlx.DB ) {
31
38
categories := make (map [int ]CategoryDto )
32
39
cnt := 0
@@ -104,7 +111,7 @@ func registerRoutes(r chi.Router, db *sqlx.DB) {
104
111
return
105
112
}
106
113
107
- var result CategoryDto
114
+ var result CategoryInfoDto
108
115
args := map [string ]interface {}{
109
116
"categoryId" : chi .URLParam (r , "categoryId" ),
110
117
}
Original file line number Diff line number Diff line change 56
56
, slug
57
57
FROM categories
58
58
WHERE id = :p.categoryId
59
+ dto :
60
+ name : CategoryInfoDto
59
61
put :
60
62
query : >-
61
63
UPDATE categories
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ function query2dto(parser, method) {
95
95
const name = hasName ? method .dto .name : " Dto" + ++ globalDtoCounter;
96
96
return {
97
97
" name" : name,
98
+ " hasUserProvidedName" : hasName,
98
99
" props" : propsWithTypes,
99
100
// max length is needed for proper formatting
100
101
" maxFieldNameLength" : lengthOfLongestString (props),
@@ -146,6 +147,10 @@ function cacheDto(dto) {
146
147
return dto;
147
148
}
148
149
function dtoInCache (dto ) {
150
+ // always prefer user specified name even when we have a similar DTO in cache
151
+ if (dto .hasUserProvidedName ) {
152
+ return false ;
153
+ }
149
154
return dtoCache .hasOwnProperty (dto .signature );
150
155
}
151
156
@@ -178,7 +183,8 @@ endpoints.forEach(function(endpoint) {
178
183
const dto = query2dto (sqlParser, method);
179
184
// TODO: do we really need signature and cache?
180
185
const cacheKey = dto ? dto .signature : null ;
181
- const dataType = hasGetMany ? ' []' + dtoCache[cacheKey] : dtoCache[cacheKey];
186
+ const dtoName = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name ;
187
+ const dataType = hasGetMany ? ' []' + dtoName : dtoName;
182
188
183
189
const params = extractParams (method .query );
184
190
const formattedParams = formatParamsAsGolangVararg (params);
You can’t perform that action at this time.
0 commit comments