isList handling
This commit is contained in:
20
DbService.cs
20
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<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input) {
|
||||
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, bool justOne, TIN input) {
|
||||
var itemList = new List<TOUT>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
30
openapi.yaml
30
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:
|
||||
|
@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user