From 66d222e0bf56363d5fb627a2f09e6c574e5dd71a Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 24 Nov 2021 13:55:33 +0100 Subject: [PATCH] first significant successgit status Shakagit status --- DbService.cs | 20 +++++++++++++++----- generateAll.sh | 4 ++-- regular.cs.tmpl | 7 ++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/DbService.cs b/DbService.cs index 1e7e5d0..f881231 100644 --- a/DbService.cs +++ b/DbService.cs @@ -1,20 +1,21 @@ using System; using System.Collections.Generic; using System.Runtime.Serialization; +using System.Threading.Tasks; using MySqlConnector; using de.hottis.genericdatabaseapiservice.Models; namespace de.hottis.genericdatabaseapiservice.Services { public interface IDbService { - void JustDoSomething(string msg); + Task> JustDoSomething(string msg); } public class DbService : IDbService { - async public void JustDoSomething(string msg) { + async public Task> JustDoSomething(string msg) { Console.WriteLine(msg); - var item = Activator.CreateInstance(); + var itemList = new List(); using (var conn = new MySqlConnection("Server=172.16.10.18;User ID=apiservicetestdb;Password=geheim123;Database=apiservicetestdb")) { await conn.OpenAsync(); @@ -27,17 +28,26 @@ namespace de.hottis.genericdatabaseapiservice.Services { cmd.CommandText = "SELECT id, txt, nr FROM test1"; using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { + var item = Activator.CreateInstance(); foreach (var propertyInfo in typeof(T).GetProperties()) { - Console.WriteLine("Property name: {0}", propertyInfo); + Console.WriteLine("Property name: {0} {1} ", propertyInfo.Name, propertyInfo.PropertyType); var attributes = propertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), true); var dma = (DataMemberAttribute)attributes[0]; Console.WriteLine("DataMember name: {0} {1} ", dma.Name, dma.TypeId); + if (propertyInfo.PropertyType == typeof(System.String)) { + propertyInfo.SetValue(item, reader.GetString(dma.Name)); + Console.WriteLine("Value:{0}", reader.GetString(dma.Name)); + } else if (propertyInfo.PropertyType == typeof(System.Int32)) { + propertyInfo.SetValue(item, reader.GetInt32(dma.Name)); + Console.WriteLine("Value:{0}", reader.GetInt32(dma.Name)); + } } - Console.WriteLine(reader.GetString("txt")); + itemList.Add(item); } } } } + return itemList; } } } diff --git a/generateAll.sh b/generateAll.sh index 87165bd..c5266dc 100755 --- a/generateAll.sh +++ b/generateAll.sh @@ -42,10 +42,10 @@ fi . ENV echo "generate server code and endpoint stubs from openapi.yaml" -docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator:cli-v5.1.0 \ +docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator-cli:v5.3.0 \ generate -i /work/openapi.yaml -g aspnetcore -o /work/output \ --package-name $PACKAGE_NAME \ - --additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=true,\ + --additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=false,operationResultTask=true,\ generateBody=false,classModifier=abstract,operationModifier=abstract" echo "patch DbService registering into generated startup code" diff --git a/regular.cs.tmpl b/regular.cs.tmpl index 446d468..1882792 100644 --- a/regular.cs.tmpl +++ b/regular.cs.tmpl @@ -3,6 +3,7 @@ $GENERATED_CS_COMMENT using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using Microsoft.AspNetCore.Authorization; @@ -30,7 +31,7 @@ namespace ${env['packagename']}.Implementations /// /// $operation['description'] /// - public override IActionResult ${operation['func']}( #slurp + public override async Task ${operation['func']}( #slurp #if $operation['paramsInputTypes'] #set $sep = "" #for $paramsInputType in $operation['paramsInputTypes'] @@ -45,7 +46,7 @@ $paramsInputType['type'] $paramsInputType['name'] #slurp [FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp #end if ) { - _dbService.JustDoSomething<$operation['resultType']['csName']>("Hello ${operation['func']}"); + List<$operation['resultType']['csName']> res = await _dbService.JustDoSomething<$operation['resultType']['csName']>("Hello ${operation['func']}"); // Statement: #if not $operation['statement'] @@ -73,7 +74,7 @@ $paramsInputType['type'] $paramsInputType['name'] #slurp #if $operation['isList'] // result must be mapped in list #end if - return new ObjectResult(null); + return new ObjectResult(res); } #elif $operation['method'] == 'post'