2021-11-18 19:27:39 +01:00
|
|
|
$GENERATED_CS_COMMENT
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-11-24 13:55:33 +01:00
|
|
|
using System.Threading.Tasks;
|
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-22 19:07:46 +01:00
|
|
|
/// <summary>
|
|
|
|
/// </summary>
|
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-22 19:07:46 +01:00
|
|
|
/// <summary>
|
|
|
|
/// $operation['description']
|
|
|
|
/// </summary>
|
2021-11-24 13:55:33 +01:00
|
|
|
public override async Task<IActionResult> ${operation['func']}( #slurp
|
2021-11-22 19:07:46 +01:00
|
|
|
#if $operation['paramsInputTypes']
|
|
|
|
#set $sep = ""
|
|
|
|
#for $paramsInputType in $operation['paramsInputTypes']
|
|
|
|
$sep [FromRoute (Name = "$paramsInputType['name']")] #slurp
|
|
|
|
#if $paramsInputType['required']
|
|
|
|
[Required] #slurp
|
|
|
|
#end if
|
|
|
|
$paramsInputType['type'] $paramsInputType['name'] #slurp
|
|
|
|
#set $sep = ","
|
|
|
|
#end for
|
|
|
|
#elif $operation['bodyInputType']
|
|
|
|
[FromBody]$operation['bodyInputType']['csName'] $operation['bodyInputType']['apiName'] #slurp
|
2021-11-19 12:39:46 +01:00
|
|
|
#end if
|
2021-11-22 19:07:46 +01:00
|
|
|
) {
|
2021-11-24 13:55:33 +01:00
|
|
|
List<$operation['resultType']['csName']> res = await _dbService.JustDoSomething<$operation['resultType']['csName']>("Hello ${operation['func']}");
|
2021-11-22 19:07:46 +01:00
|
|
|
|
2021-11-19 12:39:46 +01:00
|
|
|
// 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
|
2021-11-22 19:07:46 +01:00
|
|
|
#if $operation['bodyInputType']
|
|
|
|
// Input type mapping: $operation['bodyInputType']['apiName'] -> $operation['bodyInputType']['csName']
|
|
|
|
#for $property in $types[$operation['bodyInputType']['apiName']]['properties']
|
2021-11-19 12:39:46 +01:00
|
|
|
// $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
|
2021-11-24 13:55:33 +01:00
|
|
|
return new ObjectResult(res);
|
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
|
|
|
|
|
|
|
}
|
|
|
|
}
|