File tree 3 files changed +13
-5
lines changed
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import "github.com/go-chi/chi"
10
10
import "github.com/jmoiron/sqlx"
11
11
12
12
type CounterDto struct {
13
- Counter * string `json:"counter,omitempty" db:"counter"`
13
+ Counter * integer `json:"counter,omitempty" db:"counter"`
14
14
}
15
15
16
16
type CategoryDto struct {
Original file line number Diff line number Diff line change 3
3
query : SELECT COUNT(*) AS counter FROM categories
4
4
dto :
5
5
name : CounterDto
6
+ fields :
7
+ counter :
8
+ type : integer
6
9
7
10
- path : /v1/collections/:collectionId/categories/count
8
11
get :
12
15
JOIN series s
13
16
ON s.id = cs.series_id
14
17
WHERE cs.collection_id = :p.collectionId
18
+ dto :
19
+ fields :
20
+ counter :
21
+ type : integer
15
22
16
23
- path : /v1/categories
17
24
get_list :
Original file line number Diff line number Diff line change @@ -70,12 +70,12 @@ function extractProperties(queryAst) {
70
70
return [];
71
71
}
72
72
73
- function addTypes (props ) {
73
+ function addTypes (props , fieldsInfo ) {
74
74
return props .map (prop => {
75
+ const hasTypeInfo = fieldsInfo .hasOwnProperty (prop) && fieldsInfo[prop].hasOwnProperty (' type' );
75
76
return {
76
77
" name" : prop,
77
- // TODO: resolve/autoguess types
78
- " type" : " *string"
78
+ " type" : hasTypeInfo ? ' *' + fieldsInfo[prop].type : ' *string'
79
79
}
80
80
});
81
81
}
@@ -90,7 +90,8 @@ function query2dto(parser, method) {
90
90
console .debug (queryAst);
91
91
return null ;
92
92
}
93
- const propsWithTypes = addTypes (props);
93
+ const fieldsInfo = method .dto && method .dto .fields ? method .dto .fields : {};
94
+ const propsWithTypes = addTypes (props, fieldsInfo);
94
95
const hasName = method .dto && method .dto .name && method .dto .name .length > 0 ;
95
96
const name = hasName ? method .dto .name : " Dto" + ++ globalDtoCounter;
96
97
return {
You can’t perform that action at this time.
0 commit comments