genericdatabaseapiservice/regular.cs.tmpl

97 lines
3.3 KiB
Cheetah
Raw Normal View History

2021-11-18 19:27:39 +01:00
$GENERATED_CS_COMMENT
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
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;
using ${env['packagename']}.Services;
2021-11-18 19:27:39 +01:00
namespace ${env['packagename']}.Implementations
{
/// <summary>
/// </summary>
2021-11-18 19:27:39 +01:00
public class RegularApiImplementation : RegularApiController
{
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'
/// <summary>
/// $operation['description']
/// </summary>
public override async Task<IActionResult> ${operation['func']}( #slurp
#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
) {
List<$operation['resultType']['csName']> res = await _dbService.JustDoSomething<$operation['resultType']['csName']>("Hello ${operation['func']}");
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
#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
return new ObjectResult(res);
2021-11-18 19:27:39 +01:00
}
2021-11-19 12:39:46 +01:00
#elif $operation['method'] == 'post'
// 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
}
}