File tree 2 files changed +8
-6
lines changed
2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -14,19 +14,19 @@ type CounterDto struct {
14
14
}
15
15
16
16
type CategoryDto struct {
17
- Id * int `json:"id" db:"id"`
17
+ Id * int `json:"id" db:"id"`
18
18
Name * string `json:"name" db:"name"`
19
19
NameRu * string `json:"name_ru" db:"name_ru"`
20
20
Slug * string `json:"slug" db:"slug"`
21
- Hidden * bool `json:"hidden" db:"hidden"`
21
+ Hidden * bool `json:"hidden" db:"hidden"`
22
22
}
23
23
24
24
type CreateCategoryDto struct {
25
25
Name * string `json:"name" db:"name"`
26
26
NameRu * string `json:"name_ru" db:"name_ru"`
27
27
Slug * string `json:"slug" db:"slug"`
28
- Hidden * bool `json:"hidden" db:"hidden"`
29
- UserId * int `json:"user_id" db:"user_id"`
28
+ Hidden * bool `json:"hidden" db:"hidden"`
29
+ UserId * int `json:"user_id" db:"user_id"`
30
30
}
31
31
32
32
func registerRoutes (r chi.Router , db * sqlx.DB ) {
Original file line number Diff line number Diff line change @@ -112,8 +112,9 @@ function query2dto(parser, method) {
112
112
" name" : name,
113
113
" hasUserProvidedName" : hasName,
114
114
" props" : propsWithTypes,
115
- // max length is needed for proper formatting
115
+ // max lengths are needed for proper formatting
116
116
" maxFieldNameLength" : lengthOfLongestString (props .map (el => el .indexOf (' _' ) < 0 ? el : el .replace (/ _/ g , ' ' ))),
117
+ " maxFieldTypeLength" : lengthOfLongestString (propsWithTypes .map (el => el .type )),
117
118
// required for de-duplication
118
119
// [ {name:foo, type:int}, {name:bar, type:string} ] => "foo=int bar=string"
119
120
// LATER: sort before join
@@ -125,7 +126,8 @@ function dto2struct(dto) {
125
126
let result = ` type ${ dto .name } struct {\n `
126
127
dto .props .forEach (prop => {
127
128
const fieldName = capitalize (snake2camelCase (prop .name )).padEnd (dto .maxFieldNameLength )
128
- result += ` \t ${ fieldName} ${ prop .type } \` json:"${ prop .name } " db:"${ prop .name } "\`\n `
129
+ const fieldType = prop .type .padEnd (dto .maxFieldTypeLength )
130
+ result += ` \t ${ fieldName} ${ fieldType} \` json:"${ prop .name } " db:"${ prop .name } "\`\n `
129
131
})
130
132
result += ' }\n '
131
133
You can’t perform that action at this time.
0 commit comments