first significant successgit status Shakagit status
This commit is contained in:
20
DbService.cs
20
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<T>(string msg);
|
||||
Task<List<T>> JustDoSomething<T>(string msg);
|
||||
|
||||
}
|
||||
|
||||
public class DbService : IDbService {
|
||||
async public void JustDoSomething<T>(string msg) {
|
||||
async public Task<List<T>> JustDoSomething<T>(string msg) {
|
||||
Console.WriteLine(msg);
|
||||
|
||||
var item = Activator.CreateInstance<T>();
|
||||
var itemList = new List<T>();
|
||||
|
||||
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<T>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// $operation['description']
|
||||
/// </summary>
|
||||
public override IActionResult ${operation['func']}( #slurp
|
||||
public override async Task<IActionResult> ${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'
|
||||
|
Reference in New Issue
Block a user