2021-11-18 19:27:39 +01:00
|
|
|
$GENERATED_CS_COMMENT
|
|
|
|
|
2021-11-25 14:49:08 +01:00
|
|
|
|
2021-11-18 19:27:39 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-11-24 13:55:33 +01:00
|
|
|
using System.Threading.Tasks;
|
2021-11-25 14:49:08 +01:00
|
|
|
using System.Runtime.Serialization;
|
2021-11-18 19:27:39 +01:00
|
|
|
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;
|
2021-11-22 19:07:46 +01:00
|
|
|
using ${env['packagename']}.Services;
|
2021-11-18 19:27:39 +01:00
|
|
|
|
|
|
|
namespace ${env['packagename']}.Implementations
|
|
|
|
{
|
2021-11-25 14:49:08 +01:00
|
|
|
|
|
|
|
#for $operation in $operations
|
|
|
|
#if $operation['paramInputTypes']
|
|
|
|
[DataContract]
|
|
|
|
public class ${operation['func']}InputType
|
|
|
|
{
|
|
|
|
#for $inputType in $operation['paramInputTypes']
|
|
|
|
#if $inputType['required']
|
|
|
|
[Required]
|
|
|
|
#end if
|
|
|
|
[DataMember(Name="$inputType['name']")]
|
2021-11-25 15:44:16 +01:00
|
|
|
public $inputType['type'] $inputType['csName'] { get; set; }
|
2021-11-25 14:49:08 +01:00
|
|
|
|
|
|
|
#end for
|
|
|
|
}
|
|
|
|
#end if
|
|
|
|
#end for
|
|
|
|
|
2021-11-18 19:27:39 +01:00
|
|
|
public class RegularApiImplementation : RegularApiController
|
|
|
|
{
|
2021-11-22 19:07:46 +01:00
|
|
|
|
|
|
|
private readonly IDbService _dbService;
|
|
|
|
public RegularApiImplementation(IDbService dbService) {
|
|
|
|
_dbService = dbService;
|
|
|
|
}
|
|
|
|
|
2021-11-18 19:27:39 +01:00
|
|
|
#for $operation in $operations
|
2021-11-19 12:39:46 +01:00
|
|
|
#if $operation['method'] == 'get'
|
2021-11-25 14:49:08 +01:00
|
|
|
public override async Task<IActionResult> ${operation['func']}(#slurp
|
|
|
|
#if $operation['bodyInputType']
|
2021-11-22 19:07:46 +01:00
|
|
|
[FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp
|
2021-11-19 12:39:46 +01:00
|
|
|
#end if
|
2021-11-25 14:49:08 +01:00
|
|
|
#if $operation['paramInputTypes']
|
|
|
|
#set sep = ''
|
|
|
|
#for $inputType in $operation['paramInputTypes']
|
|
|
|
$sep#slurp
|
|
|
|
#if $inputType['in'] == 'query'
|
|
|
|
[FromQuery #slurp
|
|
|
|
#elif $inputType['in'] == 'path'
|
2021-11-25 14:54:18 +01:00
|
|
|
[FromRoute #slurp
|
2021-11-25 14:49:08 +01:00
|
|
|
#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
|
2021-11-22 19:07:46 +01:00
|
|
|
) {
|
2021-11-25 14:49:08 +01:00
|
|
|
#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
|
|
|
|
|
2021-11-25 15:33:55 +01:00
|
|
|
try {
|
|
|
|
List<$operation['resultType']['csName']> res = await _dbService.ReadBySelect<#slurp
|
|
|
|
#if $operation['bodyInputType']
|
2021-11-25 14:49:08 +01:00
|
|
|
$operation['bodyInputType']['csName'], #slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#elif $operation['paramInputTypes']
|
2021-11-25 14:49:08 +01:00
|
|
|
${operation['func']}InputType, #slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#else
|
2021-11-25 14:49:08 +01:00
|
|
|
Object, #slurp
|
|
|
|
#end if
|
|
|
|
$operation['resultType']['csName']>("#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#if not $operation['statement']
|
2021-11-25 14:49:08 +01:00
|
|
|
SELECT #slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#set $sep = ""
|
|
|
|
#for $property in $types[$operation['resultType']['apiName']]['properties']
|
2021-11-25 14:49:08 +01:00
|
|
|
$sep$property['sqlName'] #slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#set $sep = ","
|
|
|
|
#end for
|
2021-11-25 14:49:08 +01:00
|
|
|
FROM $types[$operation['resultType']['apiName']]['sqlName']#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#else
|
2021-11-25 14:49:08 +01:00
|
|
|
$operation['statement']#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#end if
|
2021-11-25 14:49:08 +01:00
|
|
|
", #slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#if $operation['bodyInputType']
|
2021-11-25 14:49:08 +01:00
|
|
|
$operation['bodyInputType']['apiName']#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#elif $operation['paramInputTypes']
|
2021-11-25 14:49:08 +01:00
|
|
|
paramInput#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#else
|
2021-11-25 14:49:08 +01:00
|
|
|
null#slurp
|
2021-11-25 15:33:55 +01:00
|
|
|
#end if
|
2021-11-25 14:49:08 +01:00
|
|
|
);
|
2021-11-25 15:33:55 +01:00
|
|
|
return new ObjectResult(res);
|
|
|
|
} catch (NotDataFoundException) {
|
|
|
|
return StatusCode(404, "No $operation['resultType']['apiName'] element found");
|
|
|
|
}
|
2021-11-22 19:07:46 +01:00
|
|
|
|
2021-11-18 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
2021-11-19 12:39:46 +01:00
|
|
|
#elif $operation['method'] == 'post'
|
2021-11-22 19:07:46 +01:00
|
|
|
// INSERT
|
|
|
|
|
|
|
|
#elif $operation['method'] == 'put'
|
|
|
|
// UPDATE
|
|
|
|
|
|
|
|
#elif $operation['method'] == 'delete'
|
|
|
|
// DELETE
|
2021-11-18 19:27:39 +01:00
|
|
|
|
2021-11-19 12:39:46 +01:00
|
|
|
#else
|
|
|
|
#raise Exception('invalid method')
|
|
|
|
#end if
|
|
|
|
#end for
|
2021-11-18 19:27:39 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|