$GENERATED_CS_COMMENT
\#pragma warning disable 1591
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;
using ${env['packagename']}.Attributes;
using ${env['packagename']}.Models;
using ${env['packagename']}.Controllers;
using ${env['packagename']}.Services;
namespace ${env['packagename']}.Implementations
{
#for $operation in $operations
#if $operation['paramInputTypes']
// $operation['func']
[DataContract]
public class ${operation['func']}InputType
{
#for $inputType in $operation['paramInputTypes']
// $inputType['in']
// $inputType['name']
// $inputType['required']
// $inputType['type']
#if $inputType['required']
[Required]
#end if
[DataMember(Name="$inputType['name']")]
public int $inputType['csName'] { get; set; }
#end for
}
#end if
#end for
///
///
public class RegularApiImplementation : RegularApiController
{
private readonly IDbService _dbService;
public RegularApiImplementation(IDbService dbService) {
_dbService = dbService;
}
#for $operation in $operations
#if $operation['method'] == 'get'
///
/// $operation['description']
///
public override async Task ${operation['func']}(#slurp
#if $operation['bodyInputType']
[FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp
#end if
#if $operation['paramInputTypes']
#set sep = ''
#for $inputType in $operation['paramInputTypes']
$sep#slurp
#if $inputType['in'] == 'query'
[FromQuery #slurp
#elif $inputType['in'] == 'path'
[FromRoute #slurp
#else
#raise Exception('Invalid in for paramInput')
#end if
(Name = "$inputType['name']")]#slurp
#if $inputType['required']
[Required()]#slurp
#end if
$inputType['type'] $inputType['name']#slurp
#set sep = ', '
#end for
#end if
) {
#if $operation['paramInputTypes']
${operation['func']}InputType paramInput = new ${operation['func']}InputType();
#for $inputType in $operation['paramInputTypes']
paramInput.$inputType['csName'] = $inputType['name'];
#end for
#end if
List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp
#if $operation['bodyInputType']
$operation['bodyInputType']['csName'], #slurp
#elif $operation['paramInputTypes']
${operation['func']}InputType, #slurp
#else
Object, #slurp
#end if
$operation['resultType']['csName']>("#slurp
#if not $operation['statement']
SELECT #slurp
#set $sep = ""
#for $property in $types[$operation['resultType']['apiName']]['properties']
$sep$property['sqlName'] #slurp
#set $sep = ","
#end for
FROM $types[$operation['resultType']['apiName']]['sqlName']#slurp
#else
$operation['statement']#slurp
#end if
", #slurp
#if $operation['bodyInputType']
$operation['bodyInputType']['apiName']#slurp
#elif $operation['paramInputTypes']
paramInput#slurp
#else
null#slurp
#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);
}
#elif $operation['method'] == 'post'
// INSERT
#elif $operation['method'] == 'put'
// UPDATE
#elif $operation['method'] == 'delete'
// DELETE
#else
#raise Exception('invalid method')
#end if
#end for
}
}
\#pragma warning restore 1591