no data exception and no documentation warnings in generated code
This commit is contained in:
10
DbService.cs
10
DbService.cs
@ -12,9 +12,10 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
|||||||
Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input);
|
Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DbServiceException : Exception {}
|
||||||
|
public class NotDataFoundException : DbServiceException {}
|
||||||
|
|
||||||
public class DbService : IDbService {
|
public class DbService : IDbService {
|
||||||
|
|
||||||
|
|
||||||
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input) {
|
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input) {
|
||||||
var itemList = new List<TOUT>();
|
var itemList = new List<TOUT>();
|
||||||
|
|
||||||
@ -57,6 +58,11 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itemList.Count == 0) {
|
||||||
|
throw new NotDataFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
return itemList;
|
return itemList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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#\(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#'
|
-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"
|
echo "create directories for manually developed code"
|
||||||
mkdir output/src/$PACKAGE_NAME/Implementations
|
mkdir output/src/$PACKAGE_NAME/Implementations
|
||||||
mkdir output/src/$PACKAGE_NAME/Services
|
mkdir output/src/$PACKAGE_NAME/Services
|
||||||
|
@ -48,14 +48,6 @@ paths:
|
|||||||
INPUTMAPPINGBEGIN
|
INPUTMAPPINGBEGIN
|
||||||
nr = Nummer
|
nr = Nummer
|
||||||
INPUTMAPPINGEND
|
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:
|
parameters:
|
||||||
- name: nr
|
- name: nr
|
||||||
in: path
|
in: path
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
$GENERATED_CS_COMMENT
|
$GENERATED_CS_COMMENT
|
||||||
|
|
||||||
\#pragma warning disable 1591
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -27,10 +26,6 @@ namespace ${env['packagename']}.Implementations
|
|||||||
public class ${operation['func']}InputType
|
public class ${operation['func']}InputType
|
||||||
{
|
{
|
||||||
#for $inputType in $operation['paramInputTypes']
|
#for $inputType in $operation['paramInputTypes']
|
||||||
// $inputType['in']
|
|
||||||
// $inputType['name']
|
|
||||||
// $inputType['required']
|
|
||||||
// $inputType['type']
|
|
||||||
#if $inputType['required']
|
#if $inputType['required']
|
||||||
[Required]
|
[Required]
|
||||||
#end if
|
#end if
|
||||||
@ -42,8 +37,6 @@ namespace ${env['packagename']}.Implementations
|
|||||||
#end if
|
#end if
|
||||||
#end for
|
#end for
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
public class RegularApiImplementation : RegularApiController
|
public class RegularApiImplementation : RegularApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -54,9 +47,6 @@ namespace ${env['packagename']}.Implementations
|
|||||||
|
|
||||||
#for $operation in $operations
|
#for $operation in $operations
|
||||||
#if $operation['method'] == 'get'
|
#if $operation['method'] == 'get'
|
||||||
/// <summary>
|
|
||||||
/// $operation['description']
|
|
||||||
/// </summary>
|
|
||||||
public override async Task<IActionResult> ${operation['func']}(#slurp
|
public override async Task<IActionResult> ${operation['func']}(#slurp
|
||||||
#if $operation['bodyInputType']
|
#if $operation['bodyInputType']
|
||||||
[FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp
|
[FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp
|
||||||
@ -88,6 +78,7 @@ $inputType['type'] $inputType['name']#slurp
|
|||||||
#end for
|
#end for
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
|
try {
|
||||||
List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp
|
List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp
|
||||||
#if $operation['bodyInputType']
|
#if $operation['bodyInputType']
|
||||||
$operation['bodyInputType']['csName'], #slurp
|
$operation['bodyInputType']['csName'], #slurp
|
||||||
@ -117,34 +108,11 @@ paramInput#slurp
|
|||||||
null#slurp
|
null#slurp
|
||||||
#end if
|
#end if
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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);
|
return new ObjectResult(res);
|
||||||
|
} catch (NotDataFoundException) {
|
||||||
|
return StatusCode(404, "No $operation['resultType']['apiName'] element found");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif $operation['method'] == 'post'
|
#elif $operation['method'] == 'post'
|
||||||
@ -164,4 +132,3 @@ null#slurp
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\#pragma warning restore 1591
|
|
||||||
|
Reference in New Issue
Block a user