Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet templates webapi #1621

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<templatesConfiguration xmlns="http://capgemini.com/devonfw/cobigen/TemplatesConfiguration"
version="2.1">

<templateScans>
<templateScan templatePath="templates" destinationPath=""/>
</templateScans>

<increments>
<increment name="server" description="CRUD devon4net Server">
<incrementRef ref="application"/>
<incrementRef ref="controllers"/>
<incrementRef ref="converter"/>
<incrementRef ref="dtos"/>
<incrementRef ref="exceptions"/>
<incrementRef ref="services"/>
<incrementRef ref="domain"/>
<incrementRef ref="application" />
<incrementRef ref="controllers" />
<incrementRef ref="converter" />
<incrementRef ref="dtos" />
<incrementRef ref="exceptions" />
<incrementRef ref="services" />
<incrementRef ref="domain" />
</increment>
<increment name="application" description="Application">
<templateRef ref="Startup.cs"/>
<templateRef ref="DevonConfiguration.cs"/>
<templateRef ref="appsettings.Development.json"/>
</increment>
<increment name="controllers" description="Controllers">
<templateRef ref= "${variables.component#cap_first}Controller.cs"/>
<increment name="controllers" description="Controllers">
<templateRef ref="${variables.component#cap_first}Controller.cs" />
</increment>
<increment name="converter" description="Converter">
<templateRef ref="${variables.component#cap_first}Converter.cs"/>
<templateRef ref="${variables.component#cap_first}Converter.cs" />
</increment>
<increment name="dtos" description="DTO's">
<templateRef ref="${variables.entityName#replace('Dto', '')#cap_first}Dto.cs"/>
<templateRef ref="${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs"/>
<templateRef ref="${variables.entityName#replace('Dto', '')#cap_first}Dto.cs" />
</increment>
<increment name="exceptions" description="Exceptions">
<templateRef ref="${variables.entityName#cap_first}NotFoundException.cs"/>
<templateRef ref="${variables.entityName#cap_first}NotCreatedException.cs"/>
<templateRef ref="${variables.entityName#cap_first}NotDeletedException.cs"/>
<templateRef ref="${variables.entityName#cap_first}NotFoundException.cs" />
<templateRef ref="${variables.entityName#cap_first}NotCreatedException.cs" />
<templateRef ref="${variables.entityName#cap_first}NotDeletedException.cs" />
</increment>
<increment name="services" description="Services">
<templateRef ref="I${variables.component#cap_first}Service.cs"/>
<templateRef ref="${variables.component#cap_first}Service.cs"/>
<templateRef ref="I${variables.component#cap_first}Service.cs" />
<templateRef ref="${variables.component#cap_first}Service.cs" />
</increment>
<increment name="domain" description="Domain">
<templateRef ref="CobigenContext.cs"/>
<templateRef ref="${variables.entityName#cap_first}.cs"/>
<templateRef ref="I${variables.entityName#cap_first}Repository.cs"/>
<templateRef ref="${variables.entityName#cap_first}Repository.cs"/>
<templateRef ref="CobigenContext.cs" />
<templateRef ref="${variables.entityName#cap_first}.cs" />
<templateRef ref="I${variables.entityName#cap_first}Repository.cs" />
<templateRef ref="${variables.entityName#cap_first}Repository.cs" />
</increment>
</increments>
</templatesConfiguration>
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Devon4Net.Infrastructure.Log;
using Devon4Net.Application.WebAPI.Business.${variables.component?cap_first}Management.Service;
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto;
using Devon4Net.Infrastructure.Common;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_first}Management.Service;
using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto;

namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_first}Management.Controller
namespace Devon4Net.Application.WebAPI.Business.${variables.component?cap_first}Management.Controller
{
/// <summary>
/// ${variables.component?cap_first} controller
Expand Down Expand Up @@ -100,7 +98,7 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir
[ProducesResponseType(500)]
public async Task<IActionResult> FindAll${variables.entityName?cap_first}s()
{
Devon4NetLogger.Debug("Executing FindAll${variables.entityName?cap_first} from controller ${variables.component?cap_first}Controller");
Devon4NetLogger.Debug("Executing FindAll${variables.entityName?cap_first} from controller ${variables.component?cap_first}Controller");
return Ok(await _${variables.component?cap_first}Service.FindAll${variables.entityName?cap_first}s().ConfigureAwait(false));
}
<#assign pathInUse = "/" + variables.entityName?lower_case + "/{id}/,/" + variables.entityName?lower_case + "/search/">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto;
using Devon4Net.Application.WebAPI.Domain.Entities;
<#list model.properties as property>
<#if property.type != "string" && property.type != "number" && property.type != "boolean">
using Devon4Net.Application.WebAPI.Business.${property.name?cap_first}Management.Converter;
</#if>
</#list>

namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Converter
{
/// <summary>
/// ${variables.entityName?cap_first}Converter
/// </summary>
public static class ${variables.entityName?cap_first}Converter
{
/// <summary>
/// EntityToDto ${variables.entityName?cap_first} transformation
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static ${variables.entityName?cap_first}Dto EntityToDto(${variables.entityName?cap_first} item)
{
if(item == null) return new ${variables.entityName?cap_first}Dto();

return new ${variables.entityName?cap_first}Dto
{
${variables.entityName}Id = item.${variables.entityName}Id,
<#list model.properties as property>
<#if property.type != "string" && property.type != "number" && property.type != "boolean">
${property.name?cap_first} = item.${property.name?cap_first}.Select(x => ${property.name?cap_first}Converter.EntityToDto(x)).ToArray()<#if property?is_last><#else>,</#if>
<#else>
${property.name?cap_first} = item.${property.name?cap_first}<#if property?is_last><#else>,</#if>
</#if>
</#list>
};
}

/// <summary>
/// DtoToEntity ${variables.entityName?cap_first} transformation
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static ${variables.entityName?cap_first} DtoToEntity(${variables.entityName?cap_first}Dto item)
{
if (item == null) return new ${variables.entityName?cap_first}();

return new ${variables.entityName?cap_first}
{
${variables.entityName}Id = item.${variables.entityName}Id,
<#list model.properties as property>
<#if property.type != "string" && property.type != "number" && property.type != "boolean">
${property.name?cap_first} = item.${property.name?cap_first}.Select(x => ${property.name?cap_first}Converter.DtoToEntity(x)).ToArray()<#if property?is_last><#else>,</#if>
<#else>
${property.name?cap_first} = item.${property.name?cap_first}<#if property?is_last><#else>,</#if>
</#if>
</#list>
};
}


}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
using System;
<#list model.properties as property>
<#if property.type != "string" && property.type != "number" && property.type != "boolean">
using Devon4Net.Application.WebAPI.Business.${property.name?cap_first}Management.Dto;
</#if>
</#list>

namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto
namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto
{
/// <summary>
/// ${variables.entityName?cap_first}Dto definition
/// </summary>
public class ${variables.entityName?cap_first}Dto
{
/// <summary>
/// the ${variables.entityName?cap_first}Id
/// </summary>
public long ${variables.entityName?cap_first}Id { get; set; }

<#list model.properties as property>
<#if property.isCollection>
/// <summary>
/// the ${property.name?cap_first}
/// </summary>
public <#if property.type == "number">long<#elseif property.type == "integer">int<#elseif property.isEntity>${property.type}Dto<#else>${property.type}</#if>[] <#if property.type?contains("Dto")>${property.name?cap_first}Dto<#else>${property.name?cap_first}</#if> { get; set; }
<#if property?has_next>

</#if>
<#else>
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Text;

namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Exceptions
namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Exceptions
{
/// <summary>
/// Custom exception ${variables.entityName?cap_first}NotCreatedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Text;

namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Exceptions
namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Exceptions
{
/// <summary>
/// Custom exception ${variables.entityName?cap_first}NotDeletedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Text;

namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Exceptions
namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Exceptions
{
/// <summary>
/// Custom exception ${variables.entityName?cap_first}NotFoundException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Exceptions;
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto;
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Converter;
<#list model.properties as property>
<#if property.type != "string" && property.type != "number" && property.type != "boolean">
using Devon4Net.Application.WebAPI.Business.${property.name?cap_first}Management.Converter;
</#if>
</#list>
using Devon4Net.Application.WebAPI.Domain.Database;
using Devon4Net.Application.WebAPI.Domain.Entities;
using Devon4Net.Application.WebAPI.Domain.RepositoryInterfaces;
using Devon4Net.Domain.UnitOfWork.Service;
using Devon4Net.Domain.UnitOfWork.UnitOfWork;
using Devon4Net.Infrastructure.Log;
using Devon4Net.WebAPI.Implementation.Domain.Entities;
using Devon4Net.WebAPI.Implementation.Domain.Database;
using Devon4Net.WebAPI.Implementation.Domain.RepositoryInterfaces;
using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Exceptions;
using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto;
using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Converter;
using Devon4Net.Infrastructure.Common;
using System.Linq.Expressions;

namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_first}Management.Service
namespace Devon4Net.Application.WebAPI.Business.${variables.component?cap_first}Management.Service
{
/// <summary>
/// ${variables.component?cap_first} service implementation
Expand All @@ -35,8 +36,8 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir
/// Get${variables.entityName?cap_first}ById
/// </summary>
/// <param name="id"></param>
/// <returns>${variables.entityName?cap_first}ResponseDto</returns>
public async Task<${variables.entityName?cap_first}ResponseDto> Get${variables.entityName?cap_first}ById(long id)
/// <returns>${variables.entityName?cap_first}Dto</returns>
public async Task<${variables.entityName?cap_first}Dto> Get${variables.entityName?cap_first}ById(long id)
{
Devon4NetLogger.Debug($"Get${variables.entityName?cap_first}ById method from service ${variables.entityName?cap_first}Service with value : {id}");
var ${variables.entityName?uncap_first} = await _${variables.entityName}Repository.Get${variables.entityName?cap_first}ById(id).ConfigureAwait(false);
Expand All @@ -46,20 +47,20 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir
throw new ${variables.entityName?cap_first}NotFoundException($"the ${variables.entityName?cap_first} with id:{id} does not exist");
}

return ${variables.entityName?cap_first}Converter.ModelToDto(${variables.entityName?uncap_first});
return ${variables.entityName?cap_first}Converter.EntityToDto(${variables.entityName?uncap_first});
}

/// <summary>
/// Create${variables.entityName?cap_first}
/// </summary>
/// <param name="${variables.entityName?uncap_first}Dto"></param>
/// <returns>${variables.entityName?cap_first}ResponseDto</returns>
public async Task<${variables.entityName?cap_first}ResponseDto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto)
/// <returns>${variables.entityName?cap_first}Dto</returns>
public async Task<${variables.entityName?cap_first}Dto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto)
{
Devon4NetLogger.Debug($"Set${variables.entityName?cap_first} method from service ${variables.entityName?cap_first}Service");
var created${variables.entityName?cap_first} = await _${variables.entityName}Repository.Set${variables.entityName?cap_first}(<#list model.properties as property>${variables.entityName?uncap_first}Dto.${property.name?cap_first}<#if property?has_next>, </#if></#list>).ConfigureAwait(false);
Devon4NetLogger.Debug("Set${variables.entityName?cap_first} method from service ${variables.entityName?cap_first}Service");
var created${variables.entityName?cap_first} = await _${variables.entityName}Repository.Set${variables.entityName?cap_first}(<#list model.properties as property>${variables.entityName?uncap_first}Dto.${property.name?cap_first}<#if property.type != "string" && property.type != "number" && property.type != "boolean">.Select(x => ${property.name?cap_first}Converter.DtoToEntity(x)).ToArray()</#if><#if property?is_last><#else>,</#if></#list>).ConfigureAwait(false);

return ${variables.entityName?cap_first}Converter.ModelToDto(created${variables.entityName?cap_first});
return ${variables.entityName?cap_first}Converter.EntityToDto(created${variables.entityName?cap_first});
}

/// <summary>
Expand All @@ -84,12 +85,12 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir
/// FindAll${variables.entityName?cap_first}s
/// </summary>
/// <param name="predicate"></param>
/// <returns>List of ${variables.entityName?cap_first}ResponseDto</returns>
public async Task<IEnumerable<${variables.entityName?cap_first}ResponseDto>> FindAll${variables.entityName?cap_first}s(Expression<Func<${variables.entityName?cap_first}, bool>> predicate = null)
/// <returns>List of ${variables.entityName?cap_first}Dto</returns>
public async Task<IEnumerable<${variables.entityName?cap_first}Dto>> FindAll${variables.entityName?cap_first}s(Expression<Func<${variables.entityName?cap_first}, bool>> predicate = null)
{
Devon4NetLogger.Debug("Get${variables.entityName?cap_first} method from service ${variables.entityName?cap_first}Service");
var ${variables.entityName?uncap_first}s = await _${variables.entityName}Repository.Get${variables.entityName?cap_first}s().ConfigureAwait(false);
return ${variables.entityName?uncap_first}s.Select(${variables.entityName?cap_first}Converter.ModelToDto);
return ${variables.entityName?uncap_first}s.Select(${variables.entityName?cap_first}Converter.EntityToDto);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto;
using Devon4Net.Application.WebAPI.Domain.Entities;
using System.Linq.Expressions;

namespace Devon4Net.Application.WebAPI.Business.${variables.component?cap_first}Management.Service
{
/// <summary>
/// I${variables.component?cap_first}Service
/// </summary>
public interface I${variables.component?cap_first}Service
{
/// <summary>
/// Get${variables.entityName?cap_first}ById
/// </summary>
/// <param name="id"></param>
/// <returns>${variables.entityName?cap_first}Dto</returns>
Task<${variables.entityName?cap_first}Dto> Get${variables.entityName?cap_first}ById(long id);

/// <summary>
/// Create${variables.entityName?cap_first}
/// </summary>
/// <param name="${variables.entityName?uncap_first}Dto"></param>
/// <returns>${variables.entityName?cap_first}Dto</returns>
Task<${variables.entityName?cap_first}Dto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto);

/// <summary>
/// Delete${variables.entityName?cap_first}ById
/// </summary>
/// <param name="id"></param>
/// <returns>deleted id</returns>
Task<long> Delete${variables.entityName?cap_first}ById(long id);

/// <summary>
/// FindAll${variables.entityName?cap_first}s
/// </summary>
/// <param name="predicate"></param>
/// <returns>List of ${variables.entityName?cap_first}Dto</returns>
Task<IEnumerable<${variables.entityName?cap_first}Dto>> FindAll${variables.entityName?cap_first}s(Expression<Func<${variables.entityName?cap_first}, bool>> predicate = null);
}
}
Loading