diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates.xml b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates.xml index a40e0890c1..fb0566ce7c 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates.xml +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates.xml @@ -1,49 +1,48 @@ - + - + - - - - - - - + + + + + + + - + - - + + - + - - + - - - + + + - - + + - - - - + + + + diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl similarity index 94% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl index a2741d23c0..9e360e6be6 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl @@ -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 { /// /// ${variables.component?cap_first} controller @@ -100,7 +98,7 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir [ProducesResponseType(500)] public async Task 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/"> diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl new file mode 100644 index 0000000000..4c96615894 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl @@ -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; + + + +namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Converter +{ + /// + /// ${variables.entityName?cap_first}Converter + /// + public static class ${variables.entityName?cap_first}Converter + { + /// + /// EntityToDto ${variables.entityName?cap_first} transformation + /// + /// + /// + 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>, + <#else> + ${property.name?cap_first} = item.${property.name?cap_first}<#if property?is_last><#else>, + + + }; + } + + /// + /// DtoToEntity ${variables.entityName?cap_first} transformation + /// + /// + /// + 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>, + <#else> + ${property.name?cap_first} = item.${property.name?cap_first}<#if property?is_last><#else>, + + + }; + } + + + } +} \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl similarity index 69% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl index 2c81ffebed..51221e5a19 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl @@ -1,12 +1,21 @@ -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; + + -namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto +namespace Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Dto { /// /// ${variables.entityName?cap_first}Dto definition /// public class ${variables.entityName?cap_first}Dto { + /// + /// the ${variables.entityName?cap_first}Id + /// + public long ${variables.entityName?cap_first}Id { get; set; } + <#list model.properties as property> <#if property.isCollection> /// @@ -14,7 +23,7 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_fi /// public <#if property.type == "number">long<#elseif property.type == "integer">int<#elseif property.isEntity>${property.type}Dto<#else>${property.type}[] <#if property.type?contains("Dto")>${property.name?cap_first}Dto<#else>${property.name?cap_first} { get; set; } <#if property?has_next> - + <#else> /// diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl similarity index 92% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl index 900ae42072..beb942c173 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl @@ -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 { /// /// Custom exception ${variables.entityName?cap_first}NotCreatedException diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl similarity index 92% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl index 81ea7089a2..8c0613555a 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl @@ -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 { /// /// Custom exception ${variables.entityName?cap_first}NotDeletedException diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl similarity index 92% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl index a7a8ddc5fc..d9d27022eb 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl @@ -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 { /// /// Custom exception ${variables.entityName?cap_first}NotFoundException diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl similarity index 61% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl index 34f5d4f85e..8a5d9ec87e 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl @@ -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; + + +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 { /// /// ${variables.component?cap_first} service implementation @@ -35,8 +36,8 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir /// Get${variables.entityName?cap_first}ById /// /// - /// ${variables.entityName?cap_first}ResponseDto - public async Task<${variables.entityName?cap_first}ResponseDto> Get${variables.entityName?cap_first}ById(long id) + /// ${variables.entityName?cap_first}Dto + 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); @@ -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}); } /// /// Create${variables.entityName?cap_first} /// /// - /// ${variables.entityName?cap_first}ResponseDto - public async Task<${variables.entityName?cap_first}ResponseDto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto) + /// ${variables.entityName?cap_first}Dto + 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>, ).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 property?is_last><#else>,).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}); } /// @@ -84,12 +85,12 @@ namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_fir /// FindAll${variables.entityName?cap_first}s /// /// - /// List of ${variables.entityName?cap_first}ResponseDto - public async Task> FindAll${variables.entityName?cap_first}s(Expression> predicate = null) + /// List of ${variables.entityName?cap_first}Dto + public async Task> FindAll${variables.entityName?cap_first}s(Expression> 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); } } } \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl new file mode 100644 index 0000000000..8030db4934 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl @@ -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 +{ + /// + /// I${variables.component?cap_first}Service + /// + public interface I${variables.component?cap_first}Service + { + /// + /// Get${variables.entityName?cap_first}ById + /// + /// + /// ${variables.entityName?cap_first}Dto + Task<${variables.entityName?cap_first}Dto> Get${variables.entityName?cap_first}ById(long id); + + /// + /// Create${variables.entityName?cap_first} + /// + /// + /// ${variables.entityName?cap_first}Dto + Task<${variables.entityName?cap_first}Dto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto); + + /// + /// Delete${variables.entityName?cap_first}ById + /// + /// + /// deleted id + Task Delete${variables.entityName?cap_first}ById(long id); + + /// + /// FindAll${variables.entityName?cap_first}s + /// + /// + /// List of ${variables.entityName?cap_first}Dto + Task> FindAll${variables.entityName?cap_first}s(Expression> predicate = null); + } +} \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Configuration/DevonConfiguration.cs b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Configuration/DevonConfiguration.cs new file mode 100644 index 0000000000..14b53e9312 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Configuration/DevonConfiguration.cs @@ -0,0 +1,105 @@ +using Devon4Net.Application.WebAPI.Business.EmployeeManagement.Dto; +using Devon4Net.Application.WebAPI.Business.EmployeeManagement.Validators; +using Devon4Net.Application.WebAPI.Business.MediatRManagement.Commands; +using Devon4Net.Application.WebAPI.Business.MediatRManagement.Dto; +using Devon4Net.Application.WebAPI.Business.MediatRManagement.Handlers; +using Devon4Net.Application.WebAPI.Business.MediatRManagement.Queries; +using Devon4Net.Application.WebAPI.Business.RabbitMqManagement.Handlers; +using Devon4Net.Application.WebAPI.Business.TodoManagement.Dto; +using Devon4Net.Application.WebAPI.Business.TodoManagement.Validators; +using Devon4Net.Application.WebAPI.Domain.Database; +using Devon4Net.Domain.UnitOfWork.Common; +using Devon4Net.Domain.UnitOfWork.Enums; +using Devon4Net.Infrastructure.Common.Constants; +using Devon4Net.Infrastructure.FluentValidation; +using Devon4Net.Infrastructure.JWT.Common; +using Devon4Net.Infrastructure.MediatR.Options; +using Devon4Net.Infrastructure.MediatR.Samples.Handler; +using Devon4Net.Infrastructure.MediatR.Samples.Model; +using Devon4Net.Infrastructure.MediatR.Samples.Query; +using Devon4Net.Infrastructure.RabbitMQ; +using Devon4Net.Infrastructure.RabbitMQ.Options; +using Devon4Net.Infrastructure.RabbitMQ.Samples.Handllers; +using FluentValidation; +using MediatR; +using Microsoft.Extensions.Options; +using System.Security.Claims; + +namespace Devon4Net.Application.WebAPI.Configuration +{ + /// + /// DevonConfiguration class + /// + public static class DevonConfiguration + { + /// + /// Sets up the service dependency injection + /// For example: + /// services.AddTransient"ITodoService, TodoService"(); + /// services.AddTransient"ITodoRepository, TodoRepository"(); + /// Put your DI declarations here + /// + /// + /// + public static void SetupCustomDependencyInjection(this IServiceCollection services, IConfiguration configuration) + { + SetupDatabase(services, configuration); + SetupJwtPolicies(services); + SetupFluentValidators(services); + + using var serviceProvider = services.BuildServiceProvider(); + + var mediatR = serviceProvider.GetService>(); + var rabbitMq = serviceProvider.GetService>(); + + if (rabbitMq?.Value != null && rabbitMq.Value.EnableRabbitMq) + { + SetupRabbitHandlers(services); + } + + if (mediatR?.Value != null && mediatR.Value.EnableMediatR) + { + SetupMediatRHandlers(services); + } + } + + private static void SetupRabbitHandlers(IServiceCollection services) + { + services.AddRabbitMqHandler(true); + services.AddRabbitMqHandler(true); + } + + private static void SetupMediatRHandlers(IServiceCollection services) + { + services.AddTransient(typeof(IRequestHandler), typeof(GetUserhandler)); + services.AddTransient(typeof(IRequestHandler), typeof(GetTodoHandler)); + services.AddTransient(typeof(IRequestHandler), typeof(CreateTodoHandler)); + } + + private static void SetupFluentValidators(IServiceCollection services) + { + services.AddFluentValidation< IValidator, TodosFluentValidator>(); + services.AddFluentValidation, EmployeeFluentValidator>(); + } + + /// + /// Setup here your database connections. + /// To use RabbitMq message backup declare the 'RabbitMqBackupContext' database setup + /// PE: services.SetupDatabase<RabbitMqBackupContext>($"Data Source={FileOperations.GetFileFullPath("RabbitMqBackupSqLite.db")}", DatabaseType.Sqlite); + /// Please add the connection strings to enable the backup messaging for MediatR abd RabbitMq using MediatRBackupContext and RabbitMqBackupContext + /// + /// + /// + private static void SetupDatabase(IServiceCollection services, IConfiguration configuration) + { + services.SetupDatabase(configuration, "Default", DatabaseType.InMemory).ConfigureAwait(false); + services.SetupDatabase(configuration, "Employee", DatabaseType.InMemory).ConfigureAwait(false); + services.SetupDatabase(configuration, "Cobigen", DatabaseType.InMemory); + } + + private static void SetupJwtPolicies(IServiceCollection services) + { + services.AddJwtPolicy(AuthConst.DevonSamplePolicy, ClaimTypes.Role, AuthConst.DevonSampleUserRole); + } + } +} diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl similarity index 89% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl index f22caf68f8..d5194e31ce 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl @@ -1,15 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading.Tasks; +using Devon4Net.Application.WebAPI.Business.${variables.entityName?cap_first}Management.Exceptions; +using Devon4Net.Application.WebAPI.Domain.Database; +using Devon4Net.Application.WebAPI.Domain.Entities; +using Devon4Net.Application.WebAPI.Domain.RepositoryInterfaces; using Devon4Net.Domain.UnitOfWork.Repository; -using Devon4Net.Infrastructure.Log; -using Devon4Net.WebAPI.Implementation.Domain.Database; -using Devon4Net.WebAPI.Implementation.Domain.Entities; -using Devon4Net.WebAPI.Implementation.Domain.RepositoryInterfaces; -using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Exceptions; +using Devon4Net.Infrastructure.Common; +using System.Linq.Expressions; -namespace Devon4Net.WebAPI.Implementation.Data.Repositories +namespace Devon4Net.Application.WebAPI.Data.Repositories { /// /// ${variables.entityName?cap_first} Repository diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Database/CobigenContext.cs similarity index 90% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Database/CobigenContext.cs index ee6924c048..2e905e8305 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Database/CobigenContext.cs @@ -1,7 +1,7 @@ -using Devon4Net.WebAPI.Implementation.Domain.Entities; +using Devon4Net.Application.WebAPI.Domain.Entities; using Microsoft.EntityFrameworkCore; -namespace Devon4Net.WebAPI.Implementation.Domain.Database +namespace Devon4Net.Application.WebAPI.Domain.Database { /// /// Cobigen database context definition diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Entities/${variables.entityName#cap_first}.cs.ftl similarity index 94% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Entities/${variables.entityName#cap_first}.cs.ftl index 2e1f422fb0..1a09a48be4 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/Entities/${variables.entityName#cap_first}.cs.ftl @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Devon4Net.WebAPI.Implementation.Domain.Entities +namespace Devon4Net.Application.WebAPI.Domain.Entities { /// /// Entity class for ${variables.entityName} diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl similarity index 90% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl rename to cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl index 2968e288fe..dadd3efc52 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading.Tasks; using Devon4Net.Domain.UnitOfWork.Repository; -using Devon4Net.WebAPI.Implementation.Domain.Entities; +using Devon4Net.Application.WebAPI.Domain.Entities; +using System.Linq.Expressions; -namespace Devon4Net.WebAPI.Implementation.Domain.RepositoryInterfaces +namespace Devon4Net.Application.WebAPI.Domain.RepositoryInterfaces { /// /// ${variables.entityName?cap_first}Repository interface diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Startup.cs b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Startup.cs deleted file mode 100644 index 0bbf7cd4bc..0000000000 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Startup.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Devon4Net.Application.WebAPI.Configuration; -using Devon4Net.Domain.UnitOfWork.Common; -using Devon4Net.Domain.UnitOfWork.Enums; -using Devon4Net.WebAPI.Implementation.Configure; -using Devon4Net.WebAPI.Implementation.Domain.Database; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Devon4Net.Application.WebAPI -{ - /// - /// devonfw startup - /// - public class Startup - { - private IConfiguration Configuration { get; } - - /// - /// Configuration variable with all settings file loaded - /// - /// - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - /// - /// This method gets called by the runtime. Use this method to add services to the container. - /// - /// - public void ConfigureServices(IServiceCollection services) - { - - services.ConfigureDevonFw(Configuration); - SetupDatabase(services); - services.SetupDevonDependencyInjection(); - services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0); - services.AddControllers(); - services.AddOptions(); - } - - private void SetupDatabase(IServiceCollection services) - { - services.SetupDatabase(Configuration, "Default", DatabaseType.InMemory); - services.SetupDatabase(Configuration, "Employee", DatabaseType.InMemory); - services.SetupDatabase(Configuration, "Cobigen", DatabaseType.InMemory); - } - - /// - /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - /// - /// app net param - /// environment param - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseHsts(); - } - - app.ConfigureDevonFw(); - app.UseMvc(); - app.UseHttpsRedirection(); - app.UseStaticFiles(); - app.UseRouting(); - app.UseAuthorization(); - app.UseAuthentication(); - app.UseEndpoints(endpoints => endpoints.MapControllers()); - } - } -} \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json index 75381f06f4..0615819b58 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json +++ b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json @@ -1,16 +1,97 @@ { + "devonfw": { + "UseDetailedErrorsKey": true, + "UseIIS": false, + "UseSwagger": true, + "UseXsrf": true, + "UseModelStateValidation": true, + "Environment": "Development", + "ForceUseHttpsRedirection": false, + "Kestrel": { + "UseHttps": false, + "HttpProtocol": "Http1AndHttp2", + "ApplicationPort": 8085, + "SslProtocol": "none", + "ExtraSettings": { + "KeepAliveTimeout": 120, + "MaxConcurrentConnections": 100, + "MaxConcurrentUpgradedConnections": 100, + "MaxRequestBodySize": 28.6, + "Http2MaxStreamsPerConnection": 100, + "Http2InitialConnectionWindowSize": 131072, + "Http2InitialStreamWindowSize": 98304, + "AllowSynchronousIO": true + } + } + }, "ConnectionStrings": { "Default": "Todos", "Employee": "Employee", - "Cobigen": "Cobigen" + "Cobigen": "Cobigen", + "RabbitMqBackup": "", + "MediatRBackup": "" + }, + "JWT": { + "Audience": "devon4Net", + "Issuer": "devon4Net", + "TokenExpirationTime": 60, + "ValidateIssuer": true, + "ValidateIssuerSigningKey": true, + "ValidateLifetime": true, + "RequireSignedTokens": true, + "RequireExpirationTime": true, + "RequireAudience": true, + "ClockSkew": 5, + "Security": { + "SecretKeyEncryptionAlgorithm": "", + "SecretKey": "", + "Certificate": "", + "CertificatePassword": "", + "CertificateEncryptionAlgorithm": "", + "RefreshTokenEncryptionAlgorithm": "" + } + }, + "Certificates": { + "ServerCertificate": { + "Certificate": "", + "CertificatePassword": "" + }, + "ClientCertificate": { + "DisableClientCertificateCheck": true, + "RequireClientCertificate": false, + "CheckCertificateRevocation": true, + "ClientCertificates": { + "Whitelist": [] + } + } + }, + "ExtraSettingsFiles": [], + + "KillSwitch": { + "UseKillSwitch": false, + "EnableRequests": false, + "HttpStatusCode": 403 }, "Logging": { + "UseLogFile": true, + "UseSQLiteDb": true, + "UseGraylog": false, + "UseAOPTrace": false, "LogLevel": { "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Microsoft.AspNetCore": "Debug" + }, + "SqliteDatabase": "", + "LogFile": "", + "SeqLogServerHost": "", + "GrayLog": { + "GrayLogHost": "", + "GrayLogPort": "12201", + "GrayLogProtocol": "UDP", + "MaxUdpMessageSize": 8192 } }, + "Cors": [], "Swagger": { "Version": "v1", "Title": "devon4net API", @@ -18,7 +99,7 @@ "Terms": "https://www.devonfw.com/terms-of-use/", "Contact": { "Name": "devonfw", - "Email": "icsddevonfwsupport.apps2@capgemini.com", + "Email": "sample@mail.com", "Url": "https://www.devonfw.com" }, "License": { @@ -32,46 +113,30 @@ "RouteTemplate": "swagger/v1/{documentName}/swagger.json" } }, - "JWT": { - "Audience": "devon4Net", - "Issuer": "devon4Net", - "TokenExpirationTime": 60, - "ValidateIssuerSigningKey": true, - "ValidateLifetime": true, - "ClockSkew": 5, - "Security": { - "SecretKeyLengthAlgorithm": "A256KW", - "SecretKeyEncryptionAlgorithm": "A128CBC-HS256", - "SecretKey": "tMFjgSOahNU5Cm4WV7ncY6EeARwqpb1x", - "Certificate": "localhost.pfx", - "CertificatePassword": "localhost", - "CertificateEncryptionAlgorithm": "RS256" - } - }, - "Cors": [] - //[ - // { - // "CorsPolicy": "CorsPolicy1", - // "Origins": "http://example.com,http://www.contoso.com", - // "Headers": "accept,content-type,origin,x-custom-header", - // "Methods": "GET,POST,HEAD", - // "AllowCredentials": true - // }, - // { - // "CorsPolicy": "CorsPolicy2", - // "Origins": "http://example.com,http://www.contoso.com", - // "Headers": "accept,content-type,origin,x-custom-header", - // "Methods": "GET,POST,HEAD", - // "AllowCredentials": true - // } - //] - , "CircuitBreaker": { - "CheckCertificate": true, + "CheckCertificate": false, "Endpoints": [ { - "Name": "SampleService", - "BaseAddress": "https://localhost:5001/", + "Name": "DestinationA", + "BaseAddress": "PUT THE IP ADDRESS HERE", + "Headers": { + }, + "WaitAndRetrySeconds": [ + 0.0001, + 0.0005, + 0.001 + ], + "DurationOfBreak": 0.0005, + "UseCertificate": false, + "Certificate": "", + "CertificatePassword": "", + "SslProtocol": "Tls13", + "CompressionSupport": true, + "AllowAutoRedirect": true + }, + { + "Name": "DestinationB", + "BaseAddress": "PUT THE IP ADDRESS HERE", "Headers": { }, "WaitAndRetrySeconds": [ @@ -80,38 +145,52 @@ 0.001 ], "DurationOfBreak": 0.0005, - "UseCertificate": true, - "Certificate": "localhost.pfx", - "CertificatePassword": "localhost", - "SslProtocol": "3072" //TLS12 + "UseCertificate": false, + "Certificate": "", + "CertificatePassword": "", + "SslProtocol": "Tls13", + "CompressionSupport": true, + "AllowAutoRedirect": true } ] }, - "Headers": { - "AccessControlExposeHeader": "Authorization", - "StrictTransportSecurityHeader": "", - "XFrameOptionsHeader": "DENY", - "XssProtectionHeader": "1;mode=block", - "XContentTypeOptionsHeader": "nosniff", - "ContentSecurityPolicyHeader": "", - "PermittedCrossDomainPoliciesHeader": "", - "ReferrerPolicyHeader": "" + "LiteDb": { + "EnableLiteDb": true, + "DatabaseLocation": "devon4net.db" }, - "Log": { - "UseAOPTrace": false, - "LogLevel": "Debug", - "SqliteDatabase": "logs/log.db", - "LogFile": "logs/{0}_devonfw.log", - "SeqLogServerHost": "http://127.0.0.1:5341", - "GrayLog": { - "GrayLogHost": "127.0.0.1", - "GrayLogPort": "12201", - "GrayLogProtocol": "UDP", - "UseSecureConnection": true, - "UseAsyncLogging": true, - "RetryCount": 5, - "RetryIntervalMs": 15, - "MaxUdpMessageSize": 8192 + "MediatR": { + "EnableMediatR": true, + "Backup": { + "UseLocalBackup": true, + "DatabaseName": "devon4netMessageBackup.db" + } + }, + "RabbitMq": { + "EnableRabbitMq": true, + "Hosts": [ + { + "Host": "", + "Port": 5672, + "Ssl": false, + "SslServerName": "", + "SslCertPath": "", + "SslCertPassPhrase": "", + "SslPolicyErrors": "RemoteCertificateNotAvailable" + } + ], + "VirtualHost": "/", + "UserName": "", + "Password": "", + "Product": "", + "RequestedHeartbeat": 10, + "PrefetchCount": 50, + "PublisherConfirms": false, + "PersistentMessages": true, + "Platform": "localhost", + "Timeout": 10, + "Backup": { + "UseLocalBackup": false, + "DatabaseName": "devon4netMessageBackup.db" } } } diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl deleted file mode 100644 index 235760c964..0000000000 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Devon4Net.WebAPI.Implementation.Domain.Entities; -using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto; - -namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Converter -{ - /// - /// ${variables.entityName?cap_first}Converter - /// - public static class ${variables.entityName?cap_first}Converter - { - /// - /// ModelToDto ${variables.entityName?cap_first} transformation - /// - /// - /// - public static ${variables.entityName?cap_first}ResponseDto ModelToDto(${variables.entityName?cap_first} item) - { - if(item == null) return new ${variables.entityName?cap_first}ResponseDto(); - - return new ${variables.entityName?cap_first}ResponseDto - { - ${variables.entityName}Id = item.${variables.entityName}Id, - <#list model.properties as property> - ${property.name?cap_first} = item.${property.name?cap_first}<#if property?is_last><#else>, - - }; - } - } -} \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl deleted file mode 100644 index 14c884b4e9..0000000000 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto -{ - /// - /// ${variables.entityName?cap_first}ResponseDto definition - /// - public class ${variables.entityName?replace("Dto", "")?cap_first}ResponseDto - { - /// - /// the ${variables.entityName?cap_first}Id - /// - public long ${variables.entityName?cap_first}Id { get; set; } - <#list model.properties as property> - <#if property.isCollection> - - /// - /// the ${property.name?cap_first} - /// - public <#if property.type == "number">long<#elseif property.type == "integer">int<#elseif property.isEntity>${property.type}Dto<#else>${property.type}[] <#if property.type?contains("Dto")>${property.name?cap_first}Dto<#else>${property.name?cap_first} { get; set; } - <#else> - - /// - /// the ${property.name?cap_first} - /// - public <#if property.type == "number">long<#elseif property.type == "integer">int<#elseif property.isEntity>${property.type}Dto<#else>${property.type} <#if property.type?contains("Dto")>${property.name?cap_first}Dto<#else>${property.name?cap_first} { get; set; } - - - } -} \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl b/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl deleted file mode 100644 index 634d814824..0000000000 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Devon4Net.WebAPI.Implementation.Domain.Entities; -using Devon4Net.WebAPI.Implementation.Business.${variables.entityName?cap_first}Management.Dto; - -namespace Devon4Net.WebAPI.Implementation.Business.${variables.component?cap_first}Management.Service -{ - /// - /// I${variables.component?cap_first}Service - /// - public interface I${variables.component?cap_first}Service - { - /// - /// Get${variables.entityName?cap_first}ById - /// - /// - /// ${variables.entityName?cap_first}ResponseDto - Task<${variables.entityName?cap_first}ResponseDto> Get${variables.entityName?cap_first}ById(long id); - - /// - /// Create${variables.entityName?cap_first} - /// - /// - /// ${variables.entityName?cap_first}ResponseDto - Task<${variables.entityName?cap_first}ResponseDto> Create${variables.entityName?cap_first}(${variables.entityName?cap_first}Dto ${variables.entityName?uncap_first}Dto); - - /// - /// Delete${variables.entityName?cap_first}ById - /// - /// - /// deleted id - Task Delete${variables.entityName?cap_first}ById(long id); - - /// - /// FindAll${variables.entityName?cap_first}s - /// - /// - /// List of ${variables.entityName?cap_first}ResponseDto - Task> FindAll${variables.entityName?cap_first}s(Expression> predicate = null); - } -} \ No newline at end of file diff --git a/documentation/howto_devon4net.asciidoc b/documentation/howto_devon4net.asciidoc index 396f06bb48..53b2911059 100644 --- a/documentation/howto_devon4net.asciidoc +++ b/documentation/howto_devon4net.asciidoc @@ -1,97 +1,140 @@ -:toc: macro -toc::[] -:icons: font -:iconfont-remote!: -:iconfont-name: font-awesome -:stylesdir: css - -== [navy]#devon4net CobiGen Guide# - -=== [navy]#Overview# - -In this guide we will explain how to generate a new `WebAPI` project from an OpenAPI 3.0.0 specification. This means that we are going to use a “contract first” strategy. This is going to be possible due to these type of files that contain all the information about entities, operations, etc… - -In order to make it work we are using https://github.com/devonfw/cobigen[CobiGen], a powerful tool for generating source code. CobiGen allows users to generate all the structure and code of the components, helping to save a lot of time otherwise wasted on repetitive tasks. - -=== [navy]#Getting things ready# - -==== [navy]#devonfw-IDE# - -First, we will install the devonfw-IDE. It is a tool that will setup your IDE within minutes. Please follow the install guide https://github.com/devonfw/ide/blob/master/documentation/setup.asciidoc[here]. - -==== [navy]#devon4net Templates# - -We are going to use the template of devon4net as a base to generate all the code, so what we have to do now is to download said template using the following steps. - -First of all you have to set up all the environment for .NET, you can do this using https://devon4net.github.io/environment.html[the following tutorial]. Next we are going to create a new folder where we want to have the `WebAPI` project, lastly we are going to open the terminal there. - -Type the following: - - `dotnet new -i Devon4Net.WebAPI.Template` - -and then: - - `dotnet new Devon4NetAPI` - -==== [navy]#OpenAPI File# - -In order to let CobiGen generate all the files, we first have to make some modifications to our OpenAPI file. - -It is obligatory to put the _“x-rootpackage”_ tag to indicate where CobiGen will place the generated files as well as the _"x-component"_ tags for each component, keep in mind that due to CobiGen's limitations each component *_must_* have its own entity. - -You can read more information about how to configure your OpenAPI file and a working example https://github.com/devonfw/cobigen/wiki/cobigen-openapiplugin#full-example[here]. - -=== [navy]#Generating files# - -CobiGen allow us to generate the files in two different ways. One of them is using Eclipse which it can be done by using the its graphical interface. The other way to generate the code is using the CobiGen CLI tool. - -==== [navy]#Generating files through Eclipse# -In order to generate the files using Eclipse we need to follow some simple steps. - -First we are going to import our basic devon4net `WebAPI` Project into Eclipse. to do so open Eclipse with the “eclipse-main.bat” file that can be found in the devon distribution root folder. Once we are inside of Eclipse we go to *File > Open projects from file system...* and, under "Directory", search for your project. - -image::images/howtos/devon4net/Project_selection.png["CobiGen", width=="600", link=="images/howtos/devon4net/Project_selection.png"] - -Next we copy our OpenAPI file into the root folder of the project. - -image::images/howtos/devon4net/OpenAPI_file_root_folder.png["CobiGen", width=="300", link=="images/howtos/devon4net/OpenAPI_file_root_folder.png"] - -And then we right click on OpenAPI file and then select *CobiGen > Generate...* It will display a window like this: - -image::images/howtos/devon4net/cobigen_generate0.png["CobiGen", width=="800", link=="images/howtos/devon4net/cobigen_generate0.png"] - -To select all .NET features choose *CRUD devon4net Server* otherwise you can select only those that interest you. - -image::images/howtos/devon4net/cobigen_generate1.png["CobiGen", width=="800", link=="images/howtos/devon4net/cobigen_generate1.png] - -Ones you select all the files that you want to generate, click on the _“Finish”_ button to generate all the source code. - -==== [navy]#Generating files through CobiGen CLI# - -In order to generate the files using the CobiGen CLI it is needed to do the following steps: - -1. Go to devonfw distribution folder -2. Run *console.bat*, this will open a console. -3. Go to the folder you downloaded the *devon4net template* and your *yml* file. -4. Run the command: - - `cobigen generate {yourOpenAPIFile}.yml` - -5. A list of increments will be printed so that you can start the generation. It has to be selected *CRUD devon4net Server* increment. - -=== [navy]#Configuration# - -==== [navy]#Data base# - - -CobiGen is generating an empty context that has to be filled with manually in order to be able to work with the database. The context can be found in `*[Project_Name]/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs*`. - -image::images/howtos/devon4net/CobigenContextLocation.png["CobiGen", width=="350", link=="images/howtos/devon4net/CobigenContextLocation.png] - -==== [navy]#Run the application# - -After the configuration of the database, open a terminal in path: `*[Project_Name]/Devon4Net.Application.WebAPI*` and then type: - - `dotnet run` - -This will deploy our application in our localhost with the port 8082, so when you click https://localhost:8082/swagger/index.html[here] (https://localhost:8082/swagger) you can see, in swagger, all the services and the data model. +:toc: macro +toc::[] +:icons: font +:iconfont-remote!: +:iconfont-name: font-awesome +:stylesdir: css + +== [navy]#devon4net CobiGen Guide# + +=== [navy]#Overview# + +In this guide we will explain how to generate a new `WebAPI` project from an OpenAPI 3.0.0 specification. This means that we are going to use a “contract first” strategy. This is going to be possible due to these type of files that contain all the information about entities, operations, etc. + +In order to make it work we are using https://github.com/devonfw/cobigen[CobiGen], a powerful tool for generating source code. CobiGen allows users to generate all the structure and code of the components, helping to save a lot of time otherwise wasted on repetitive tasks. + +=== [navy]#Getting things ready# + +==== [navy]#devonfw-IDE# + +First, we will install the devonfw-IDE. It is a tool that will setup your IDE within minutes. Please follow the install guide https://github.com/devonfw/ide/blob/master/documentation/setup.asciidoc[here]. + +==== [navy]#devon4net Templates# + +We are going to use the template of devon4net as a base to generate all the code, so what we have to do now is to download said template using the following steps. + +First of all you have to set up all the environment for .NET, you can do this using https://devon4net.github.io/environment.html[the following tutorial]. Next we are going to create a new folder where we want to have the `WebAPI` project, lastly we are going to open the terminal there. + +Type the following: + + dotnet new -i Devon4Net.WebAPI.Template + +and then: + + dotnet new Devon4NetAPI + +==== [navy]#OpenAPI File# + +In order to let CobiGen generate all the files, we first have to make some modifications to our OpenAPI file. + +It is obligatory to put the _“x-rootpackage”_ tag to indicate where CobiGen will place the generated files as well as the _"x-component"_ tags for each component, keep in mind that due to CobiGen's limitations each component *_must_* have its own entity. + +You can read more information about how to configure your OpenAPI file and a working example https://github.com/devonfw/cobigen/wiki/cobigen-openapiplugin#full-example[here]. + +==== [navy]#Restrictions in the OpenApi file# + +In the **components/schema** section, whenever reference is made to another entity, it must be written in the singular. + +Below are two examples, one valid and one invalid, of how collections of other entities should be referenced.For this example, look at the _Sale_ property in the _Shop_ component. + +**Valid Example** + + components: + schemas: + Shop: + x-component: shopmanagement + description: Entity definition of Shop + type: object + properties: + shopExample: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + sale: + type: array # Many to One relationship + items: + $ref: '#/components/schemas/Sale' + +**Invalid example** + + components: + schemas: + Shop: + x-component: shopmanagement + description: Entity definition of Shop + type: object + properties: + shopExample: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + sales: + type: array # Many to One relationship + items: + $ref: '#/components/schemas/Sale' + +=== [navy]#Generating files# + +CobiGen allow us to generate the files in two different ways. One of them is using Eclipse which it can be done by using the its graphical interface. The other way to generate the code is using the CobiGen CLI tool. + +==== [navy]#Generating files through Eclipse# +In order to generate the files using Eclipse we need to follow some simple steps. + +First we are going to import our basic devon4net `WebAPI` Project into Eclipse. to do so open Eclipse with the “eclipse-main.bat” file that can be found in the devon distribution root folder. Once we are inside of Eclipse we go to *File > Open projects from file system...* and, under "Directory", search for your project. + +image::images/howtos/devon4net/Project_selection.png["CobiGen", width=="600", link=="images/howtos/devon4net/Project_selection.png"] + +Next we copy our OpenAPI file into the root folder of the project. + +image::images/howtos/devon4net/OpenAPI_file_root_folder.png["CobiGen", width=="300", link=="images/howtos/devon4net/OpenAPI_file_root_folder.png"] + +And then we right click on OpenAPI file and then select *CobiGen > Generate...* It will display a window like this: + +image::images/howtos/devon4net/cobigen_generate0.png["CobiGen", width=="800", link=="images/howtos/devon4net/cobigen_generate0.png"] + +To select all .NET features choose *CRUD devon4net Server* otherwise you can select only those that interest you. + +image::images/howtos/devon4net/cobigen_generate1.png["CobiGen", width=="800", link=="images/howtos/devon4net/cobigen_generate1.png] + +Ones you select all the files that you want to generate, click on the _“Finish”_ button to generate all the source code. + +==== [navy]#Generating files through CobiGen CLI# + +In order to generate the files using the CobiGen CLI it is needed to do the following steps: + +1. Go to devonfw distribution folder +2. Run *console.bat*, this will open a console. +3. Go to the folder you downloaded the *devon4net template* and your *yml* file. +4. Run the command: + + cobigen generate {yourOpenAPIFile}.yml + +5. A list of increments will be printed so that you can start the generation. It has to be selected *CRUD devon4net Server* increment. + +=== [navy]#Configuration# + +==== [navy]#Data base# + +CobiGen is generating an empty context that has to be filled with manually in order to be able to work with the database. The context can be found in `*[Project_Name]/Devon4Net.Application.WebAPI/Domain/Database/CobigenContext.cs*`. + +image::images/howtos/devon4net/CobigenContextLocation.png["CobiGen", width=="350", link=="images/howtos/devon4net/CobigenContextLocation.png] + +==== [navy]#Run the application# + +After the configuration of the database, open a terminal in path: `*[Project_Name]/Devon4Net.Application.WebAPI*` and then type: + + dotnet run + +This will deploy our application in our localhost with the port 8085, so when you click https://localhost:8085/swagger/index.html[here] (https://localhost:8085/swagger) you can see, in swagger, all the services and the data model. \ No newline at end of file diff --git a/documentation/images/howtos/devon4net/CobigenContextLocation.png b/documentation/images/howtos/devon4net/CobigenContextLocation.png index 9744124a3f..06e8136b4d 100644 Binary files a/documentation/images/howtos/devon4net/CobigenContextLocation.png and b/documentation/images/howtos/devon4net/CobigenContextLocation.png differ diff --git a/documentation/images/howtos/devon4net/OpenAPI_file_root_folder.png b/documentation/images/howtos/devon4net/OpenAPI_file_root_folder.png index 033bc9854d..3ed542dbf7 100644 Binary files a/documentation/images/howtos/devon4net/OpenAPI_file_root_folder.png and b/documentation/images/howtos/devon4net/OpenAPI_file_root_folder.png differ