no data exception and no documentation warnings in generated code

This commit is contained in:
2021-11-25 15:33:55 +01:00
parent 26334719de
commit 39528bc248
4 changed files with 32 additions and 63 deletions

View File

@ -12,9 +12,10 @@ namespace de.hottis.genericdatabaseapiservice.Services {
Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input);
}
public class DbServiceException : Exception {}
public class NotDataFoundException : DbServiceException {}
public class DbService : IDbService {
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input) {
var itemList = new List<TOUT>();
@ -57,6 +58,11 @@ namespace de.hottis.genericdatabaseapiservice.Services {
}
}
}
if (itemList.Count == 0) {
throw new NotDataFoundException();
}
return itemList;
}
}

View File

@ -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<IDbService, DbService>();\n\n\1\2#'
echo "disable documentation warnings in generated code"
sed -i output/src/$PACKAGE_NAME/$PACKAGE_NAME.csproj \
-e 's#\(</PropertyGroup>\)#<NoWarn>1591</NoWarn>\n\1#'
echo "create directories for manually developed code"
mkdir output/src/$PACKAGE_NAME/Implementations
mkdir output/src/$PACKAGE_NAME/Services

View File

@ -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

View File

@ -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
/// <summary>
/// </summary>
public class RegularApiImplementation : RegularApiController
{
@ -54,9 +47,6 @@ namespace ${env['packagename']}.Implementations
#for $operation in $operations
#if $operation['method'] == 'get'
/// <summary>
/// $operation['description']
/// </summary>
public override async Task<IActionResult> ${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