diff --git a/DbService.cs b/DbService.cs index 91fac96..d6ff763 100644 --- a/DbService.cs +++ b/DbService.cs @@ -12,9 +12,10 @@ namespace de.hottis.genericdatabaseapiservice.Services { Task> ReadBySelect(string selectStatement, TIN input); } + public class DbServiceException : Exception {} + public class NotDataFoundException : DbServiceException {} + public class DbService : IDbService { - - async public Task> ReadBySelect(string selectStatement, TIN input) { var itemList = new List(); @@ -57,6 +58,11 @@ namespace de.hottis.genericdatabaseapiservice.Services { } } } + + if (itemList.Count == 0) { + throw new NotDataFoundException(); + } + return itemList; } } diff --git a/generateAll.sh b/generateAll.sh index 0c3e471..e6bd3ce 100755 --- a/generateAll.sh +++ b/generateAll.sh @@ -70,6 +70,10 @@ if [ "$STAGE2" = "1" ]; then -e 's#\(using '$PACKAGE_NAME'.OpenApi;\)#\1\n\n// added by post-processor\nusing '$PACKAGE_NAME'.Services;\n#' \ -e 's#^\([[:space:]]*\)\(// Add framework services.\)#\1// added by post-processor\n\1services.AddTransient();\n\n\1\2#' + echo "disable documentation warnings in generated code" + sed -i output/src/$PACKAGE_NAME/$PACKAGE_NAME.csproj \ + -e 's#\(\)#1591\n\1#' + echo "create directories for manually developed code" mkdir output/src/$PACKAGE_NAME/Implementations mkdir output/src/$PACKAGE_NAME/Services diff --git a/openapi.yaml b/openapi.yaml index 6a04d4b..7eb4cd5 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -48,14 +48,6 @@ paths: INPUTMAPPINGBEGIN nr = Nummer INPUTMAPPINGEND - Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod - tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At - vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, - no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, - consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et - dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo - dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem - ipsum dolor sit amet. parameters: - name: nr in: path diff --git a/regular.cs.tmpl b/regular.cs.tmpl index 0cfdd1b..7f98d87 100644 --- a/regular.cs.tmpl +++ b/regular.cs.tmpl @@ -1,6 +1,5 @@ $GENERATED_CS_COMMENT -\#pragma warning disable 1591 using System; using System.Collections.Generic; @@ -27,10 +26,6 @@ namespace ${env['packagename']}.Implementations public class ${operation['func']}InputType { #for $inputType in $operation['paramInputTypes'] - // $inputType['in'] - // $inputType['name'] - // $inputType['required'] - // $inputType['type'] #if $inputType['required'] [Required] #end if @@ -42,8 +37,6 @@ namespace ${env['packagename']}.Implementations #end if #end for - /// - /// public class RegularApiImplementation : RegularApiController { @@ -54,9 +47,6 @@ namespace ${env['packagename']}.Implementations #for $operation in $operations #if $operation['method'] == 'get' - /// - /// $operation['description'] - /// public override async Task ${operation['func']}(#slurp #if $operation['bodyInputType'] [FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp @@ -88,63 +78,41 @@ $inputType['type'] $inputType['name']#slurp #end for #end if - List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp - #if $operation['bodyInputType'] + try { + List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp + #if $operation['bodyInputType'] $operation['bodyInputType']['csName'], #slurp - #elif $operation['paramInputTypes'] + #elif $operation['paramInputTypes'] ${operation['func']}InputType, #slurp - #else + #else Object, #slurp #end if $operation['resultType']['csName']>("#slurp - #if not $operation['statement'] + #if not $operation['statement'] SELECT #slurp - #set $sep = "" - #for $property in $types[$operation['resultType']['apiName']]['properties'] + #set $sep = "" + #for $property in $types[$operation['resultType']['apiName']]['properties'] $sep$property['sqlName'] #slurp - #set $sep = "," - #end for + #set $sep = "," + #end for FROM $types[$operation['resultType']['apiName']]['sqlName']#slurp - #else + #else $operation['statement']#slurp - #end if + #end if ", #slurp - #if $operation['bodyInputType'] + #if $operation['bodyInputType'] $operation['bodyInputType']['apiName']#slurp - #elif $operation['paramInputTypes'] + #elif $operation['paramInputTypes'] paramInput#slurp - #else + #else null#slurp - #end if + #end if ); + return new ObjectResult(res); + } catch (NotDataFoundException) { + return StatusCode(404, "No $operation['resultType']['apiName'] element found"); + } - // Statement: - #if not $operation['statement'] - // SELECT - #set $sep = "" - #for $property in $types[$operation['resultType']['apiName']]['properties'] - // $sep$property['sqlName'] - #set $sep = "," - #end for - // FROM $types[$operation['resultType']['apiName']]['sqlName']; - #else - // $operation['statement'] - #end if - #if $operation['bodyInputType'] - // Input type mapping: $operation['bodyInputType']['apiName'] -> $operation['bodyInputType']['csName'] - #for $property in $types[$operation['bodyInputType']['apiName']]['properties'] - // $property['sqlName'] -> $property['csName'] - #end for - #end if - // Model object to use: $operation['resultType']['apiName'] -> $operation['resultType']['csName'] - // Properties to map result: - #for $property in $types[$operation['resultType']['apiName']]['properties'] - // $property['sqlName'] -> $property['csName'] - #end for - #if $operation['isList'] - // result must be mapped in list - #end if - return new ObjectResult(res); } #elif $operation['method'] == 'post' @@ -164,4 +132,3 @@ null#slurp } } -\#pragma warning restore 1591