From 8519da26a8bf9ae319f915747ebfb6c7a2cd14b5 Mon Sep 17 00:00:00 2001 From: Wolfgang Ludger Hottgenroth Date: Tue, 30 Nov 2021 19:09:22 +0100 Subject: [PATCH] isList handling --- DbService.cs | 20 +++++++++++--------- openapi.yaml | 30 ++++++++++++++++++++++++++++++ regular.cs.tmpl | 8 ++++++-- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/DbService.cs b/DbService.cs index d35a9eb..b0936e1 100644 --- a/DbService.cs +++ b/DbService.cs @@ -15,6 +15,7 @@ namespace de.hottis.genericdatabaseapiservice.Services { public class DbServiceException : Exception {} public class NotDataFoundException : DbServiceException {} + public class TooMuchDataFoundException : DbServiceException {} public class DbService : IDbService { private readonly IConfiguration Configuration; @@ -30,7 +31,7 @@ namespace de.hottis.genericdatabaseapiservice.Services { Configuration["Database:Name"]); } - async public Task> ReadBySelect(string selectStatement, TIN input) { + async public Task> ReadBySelect(string selectStatement, bool justOne, TIN input) { var itemList = new List(); Console.WriteLine("ConnInfo: {0}", databaseConnInfo); @@ -63,14 +64,12 @@ namespace de.hottis.genericdatabaseapiservice.Services { var dma = (DataMemberAttribute)attributes[0]; int ordinal = reader.GetOrdinal(dma.Name); Console.WriteLine("Output DataMember name: {0} {1} {2} ", dma.Name, dma.TypeId, ordinal); - if (propertyInfo.PropertyType == typeof(System.String)) { - if (reader.IsDBNull(ordinal)) { - propertyInfo.SetValue(item, null); - Console.WriteLine("Output Value: null"); - } else { - propertyInfo.SetValue(item, reader.GetString(ordinal)); - Console.WriteLine("Output Value:{0}", reader.GetString(ordinal)); - } + if (reader.IsDBNull(ordinal)) { + propertyInfo.SetValue(item, null); + Console.WriteLine("Output Value: null"); + } else if (propertyInfo.PropertyType == typeof(System.String)) { + propertyInfo.SetValue(item, reader.GetString(ordinal)); + Console.WriteLine("Output Value:{0}", reader.GetString(ordinal)); } else if (propertyInfo.PropertyType == typeof(System.Int32)) { propertyInfo.SetValue(item, reader.GetInt32(ordinal)); Console.WriteLine("Output Value:{0}", reader.GetInt32(ordinal)); @@ -85,6 +84,9 @@ namespace de.hottis.genericdatabaseapiservice.Services { if (itemList.Count == 0) { throw new NotDataFoundException(); } + if (justOne && itemList.Count > 1) { + throw new TooMuchDataFoundException(); + } return itemList; } diff --git a/openapi.yaml b/openapi.yaml index fa31a14..27360cc 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -95,6 +95,36 @@ paths: $ref: "#/components/schemas/productionOrder" 404: description: No such productionOrder entries available + /pdb/v2/baseData/{articleNumber}: + get: + tags: [ "Regular" ] + operationId: Regular.baseData + summary: Returns baseData entries + description: + STATEMENTBEGIN + SELECT Artikelcode, + Art, + bezeichnung + FROM stammdaten + WHERE Artikelcode = @articleNumber + STATEMENTEND + parameters: + - name: articleNumber + in: path + required: true + schema: + type: string + responses: + 200: + description: Here are your productionOrder items + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/productionOrder" + 404: + description: No such productionOrder entries available components: schemas: diff --git a/regular.cs.tmpl b/regular.cs.tmpl index 396d48a..369526f 100644 --- a/regular.cs.tmpl +++ b/regular.cs.tmpl @@ -98,7 +98,7 @@ FROM $types[$operation['resultType']['apiName']]['sqlName']#slurp #else $operation['statement']#slurp #end if -", #slurp +", $operation['isList'], #slurp #if $operation['bodyInputType'] $operation['bodyInputType']['apiName']#slurp #elif $operation['paramInputTypes'] @@ -107,7 +107,11 @@ paramInput#slurp null#slurp #end if ); - return new ObjectResult(res); + return new ObjectResult(res#slurp + #if $operation['isList'] +[0]#slurp + #end if +); } catch (NotDataFoundException) { return StatusCode(404, "No $operation['resultType']['apiName'] element found"); }