Skip to content

Commit 8c8b91a

Browse files
committed
refactor(python): extract method obtainDtoName()
1 parent 76fffb2 commit 8c8b91a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/templates/routes.py.ejs

+7-4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function dtoInCache(dto) {
166166
return dtoCache.hasOwnProperty(dto.signature)
167167
}
168168
169+
function obtainDtoName(dto) {
170+
const cacheKey = dto ? dto.signature : null
171+
return dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
172+
}
173+
169174
// Generate models
170175
const verbs_with_dto = [ 'post', 'put' ]
171176
endpoints.forEach(function(endpoint) {
@@ -263,8 +268,7 @@ def <%- pythonMethodName %>(<%- methodArgs.join(', ') %>):
263268
if (method.name === 'post') {
264269
const dto = query2dto(sqlParser, method)
265270
// LATER: do we really need signature and cache?
266-
const cacheKey = dto ? dto.signature : null
267-
const model = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
271+
const model = obtainDtoName(dto)
268272
269273
const sql = convertToPsycopgNamedArguments(formatQueryForPython(method.query, 20))
270274
const params = extractParamsFromQuery(method.query)
@@ -288,8 +292,7 @@ def <%- pythonMethodName %>(body: <%- model %>, conn=Depends(db_connection)):
288292
// TODO: reduce duplication with POST
289293
const dto = query2dto(sqlParser, method)
290294
// LATER: do we really need signature and cache?
291-
const cacheKey = dto ? dto.signature : null
292-
const model = dtoInCache(dto) ? dtoCache[cacheKey] : dto.name
295+
const model = obtainDtoName(dto)
293296
294297
const methodArgs = [ `body: ${model}`, ...argsFromPath, 'conn=Depends(db_connection)' ]
295298

0 commit comments

Comments
 (0)