diff --git a/src/gimme/Commands/ApiController.cs b/src/gimme/Commands/ApiController.cs index 058bacf..87f9418 100644 --- a/src/gimme/Commands/ApiController.cs +++ b/src/gimme/Commands/ApiController.cs @@ -35,7 +35,9 @@ public void OnExecute() "Controllers" ); var controllerCs = $"{ControllerName}.cs"; - var appnamespace = $"{GimmeConfiguration.WebApiProjectName.Replace("\\",".")}.Controllers"; + var controllernamespace = $"{GimmeConfiguration.WebApiProjectName.Replace("\\",".")}.Controllers"; + var appnamespace = $"{GimmeConfiguration.ApplicationProjectName.Replace("\\", ".")}"; + var controllerFile = Path.Combine(apiDirectory, controllerCs); if (!filesService.DirectoryExists(apiDirectory)) @@ -43,8 +45,9 @@ public void OnExecute() filesService.WriteAllTextToFile(controllerFile, ResourceUtil.GetResourceText("Api_Controller") - .Replace("{{namespace}}", appnamespace) - .Replace("{{name}}", ControllerName) + .Replace("{{namespace}}", controllernamespace) + .Replace("{{appnamespace}}", appnamespace) + .Replace("{{name}}", ControllerName) ); ConsoleUtil.SuccessMessage($"Mediator Controller succesfully generated!"); diff --git a/src/gimme/Commands/WebApiStarter/Command.Step03.Scaffold.cs b/src/gimme/Commands/WebApiStarter/Command.Step03.Scaffold.cs index 903331b..5369801 100644 --- a/src/gimme/Commands/WebApiStarter/Command.Step03.Scaffold.cs +++ b/src/gimme/Commands/WebApiStarter/Command.Step03.Scaffold.cs @@ -35,6 +35,12 @@ private void Step03_Scaffold() filesService.WriteAllTextToFile(recordNotFoundException, ResourceUtil.GetResourceText("WAS_App_RecordNotFoundException").Replace("{{solutionname}}", variable.SolutionName)); + ConsoleUtil.HiglightedMessage($"Creating Application Response {variable.CSPROJ_ApplicationProjectFile}"); + + var responseClasses = Path.Combine(ApplicationPath, "Response.cs"); + filesService.WriteAllTextToFile(responseClasses, + ResourceUtil.GetResourceText("WAS_App_Response").Replace("{{solutionname}}", variable.SolutionName)); + /// ConsoleUtil.HiglightedMessage($"Creating Web Api Controllers and Filters {variable.CSPROJ_WebApiProjectFile}"); var WebApiPath = Path.Combine(variable.SolutionBasePath, variable.ApiProjectName); diff --git a/src/gimme/Commands/WebApiStarter/Command.Step04.Nuget.cs b/src/gimme/Commands/WebApiStarter/Command.Step04.Nuget.cs index e400f70..c217960 100644 --- a/src/gimme/Commands/WebApiStarter/Command.Step04.Nuget.cs +++ b/src/gimme/Commands/WebApiStarter/Command.Step04.Nuget.cs @@ -32,8 +32,8 @@ private void Step04_ConfigureNugetReference() ConsoleUtil.HiglightedMessage($"Add package reference to {variable.CSPROJ_ApplicationUnitTestProjectFile}"); Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package Microsoft.EntityFrameworkCore.InMemory")); Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package Moq")); - Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package nunit -f netcoreapp2.2")); - Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package NUnit3TestAdapter -f netcoreapp2.2")); + Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package xunit -f netcoreapp2.2")); + Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package xunit.runner.visualstudio -f netcoreapp2.2")); Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package Microsoft.NET.Test.Sdk -f netcoreapp2.2")); Console.WriteLine(shellService.Exec($"dotnet add {variable.CSPROJ_ApplicationUnitTestProjectFile} package AutoMapper")); diff --git a/src/gimme/Commands/WebApiStarter/Command.cs b/src/gimme/Commands/WebApiStarter/Command.cs index dc28670..7dbc8ab 100644 --- a/src/gimme/Commands/WebApiStarter/Command.cs +++ b/src/gimme/Commands/WebApiStarter/Command.cs @@ -1,5 +1,6 @@ using gimme.Services.Files; using gimme.Shell.Services; +using gimme.Utils; using McMaster.Extensions.CommandLineUtils; using System; using System.ComponentModel.DataAnnotations; @@ -37,6 +38,7 @@ public void OnExecute() Step02_CreateProjects(); Step03_Scaffold(); Step04_ConfigureNugetReference(); + ConsoleUtil.SuccessMessage($"Done! ^_^"); } } } diff --git a/src/gimme/Properties/Resources.Designer.cs b/src/gimme/Properties/Resources.Designer.cs index 530f755..48da765 100644 --- a/src/gimme/Properties/Resources.Designer.cs +++ b/src/gimme/Properties/Resources.Designer.cs @@ -65,17 +65,17 @@ internal Resources() { ///using System.Net; ///using System.Threading.Tasks; ///using Microsoft.AspNetCore.Mvc; + ///using Commands = {{appnamespace}}.YourApplicationGroupHere.Commands; + ///using Models = {{appnamespace}}.YourApplicationGroupHere.Models; + ///using Queries = {{appnamespace}}.YourApplicationGroupHere.Queries; /// ///namespace {{namespace}} ///{ - /// [Route ("api/[controller]")] + /// [Route ("api/[controller]")] /// public class {{name}} : MediatorController { + /// /// [HttpGet] - /// [DescriptionAttribute ("Your endpoint description goes here.")] - /// [ProducesResponseType (typeof (YourReturnType), (int) HttpStatusCode.OK)] - /// public async Task<IActionResult> Get() - /// { - /// //TODO: Implement Realistic Implementati [rest of string was truncated]";. + /// [DescriptionAttribute ("Your endpoint description go [rest of string was truncated]";. /// internal static string Api_Controller { get { @@ -97,16 +97,16 @@ internal static string Api_Controller { /// /// Command /// /// </summary> /// [JsonSchema("{{name}}Command")] - /// public class Command : IRequest<YouReturnTypeHere> + /// public class Command : IRequest<Response> /// { /// } /// /// /// <summary> /// /// Command Handler /// /// </summary> - /// public class CommandHandler : IRequestHandler<Command, YouReturnTypeHere> + /// public class CommandHandler : IRequestHandler<Command, Response> /// { - /// publi [rest of string was truncated]";. + /// public CommandHandler() [rest of string was truncated]";. /// internal static string App_Command { get { @@ -250,10 +250,13 @@ internal static string WAS_Api_ActionValidationFilterAttribute { ///{ /// public static class AutoMapper { /// internal static void RegisterAutoMapper (IServiceCollection services) { - /// services.AddAutoMapper (); - /// } - /// } - ///}. + /// //http://docs.automapper.org/en/stable/Inline-Mapping.html + /// services.AddAutoMapper( + /// configAction => + /// { + /// configAction.ValidateInlineMaps = false; + /// }, + /// typeof(Applicati [rest of string was truncated]";. /// internal static string WAS_Api_Conf_AutoMapper { get { @@ -350,20 +353,26 @@ internal static string WAS_Api_Conf_Mvc { } /// - /// Looks up a localized string similar to using System; - ///using System.Reflection; - ///using Microsoft.AspNetCore.Authentication.JwtBearer; + /// Looks up a localized string similar to using System.Linq; ///using Microsoft.AspNetCore.Builder; - ///using Microsoft.AspNetCore.Hosting; - ///using NJsonSchema; + ///using Microsoft.Extensions.DependencyInjection; ///using NSwag; ///using NSwag.AspNetCore; ///using NSwag.SwaggerGeneration.Processors.Security; /// + /// + /// ///namespace {{solutionname}}.Api.Configurations { - /// public static class Swagger { - /// internal static void ConfigureSwagger (IApplicationBuilder app, IHostingEnvironment env) { - /// app.UseSwaggerUi3 (typeof (Swagger [rest of string was truncated]";. + /// + /// public static class Swagger + /// { + /// /// <summary> + /// /// Register Swagger + /// /// </summary> + /// internal static void RegisterSwagger(IServiceCollection services) + /// { + /// services.AddSwaggerDocument(c => + /// [rest of string was truncated]";. /// internal static string WAS_Api_Conf_Swagger { get { @@ -421,7 +430,8 @@ internal static string WAS_Api_HomeController { /// ///namespace {{solutionname}}.Api.Controllers ///{ - /// public abstract class MediatorController : Controller + /// [ApiController] + /// public abstract class MediatorController : ControllerBase /// { /// private IMediator _mediator; /// @@ -431,9 +441,7 @@ internal static string WAS_Api_HomeController { /// { /// return _mediator ?? (_mediator = HttpContext.RequestServices.GetService<IMediator>()); /// } - /// } - /// } - ///}. + /// [rest of string was truncated]";. /// internal static string WAS_Api_MediatorController { get { @@ -493,6 +501,35 @@ internal static string WAS_App_RecordNotFoundException { } } + /// + /// Looks up a localized string similar to namespace {{solutionname}}.Application + ///{ + /// public abstract class Response + /// { + /// protected Response(string message = null) + /// { + /// Message = message; + /// } + /// public string Message { get; set; } + /// } + /// + /// public class NotFoundResponse : Response + /// { + /// public NotFoundResponse(string message = null) : base(message) + /// { + /// } + /// } + /// + /// public class BadRequestResponse : Response + /// { + /// public BadRequestResponse(string message = null) [rest of string was truncated]";. + /// + internal static string WAS_App_Response { + get { + return ResourceManager.GetString("WAS_App_Response", resourceCulture); + } + } + /// /// Looks up a localized string similar to { /// "Logging": { diff --git a/src/gimme/Properties/Resources.resx b/src/gimme/Properties/Resources.resx index 9471ede..5d81e1b 100644 --- a/src/gimme/Properties/Resources.resx +++ b/src/gimme/Properties/Resources.resx @@ -181,6 +181,9 @@ ..\resources\was_app_recordnotfoundexception.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\resources\was_app_response.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + ..\resources\was_domain_baseentity.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 @@ -188,9 +191,9 @@ ..\resources\was_gitignore.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\resources\was_Persistence_dbcontext.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + ..\resources\was_persistence_dbcontext.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\resources\was_Persistence_dbcontextfactory.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + ..\resources\was_persistence_dbcontextfactory.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 \ No newline at end of file diff --git a/src/gimme/Resources/Api_Controller.txt b/src/gimme/Resources/Api_Controller.txt index 81efb18..2d88dd9 100644 --- a/src/gimme/Resources/Api_Controller.txt +++ b/src/gimme/Resources/Api_Controller.txt @@ -2,19 +2,26 @@ using System.ComponentModel; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Commands = {{appnamespace}}.YourApplicationGroupHere.Commands; +using Models = {{appnamespace}}.YourApplicationGroupHere.Models; +using Queries = {{appnamespace}}.YourApplicationGroupHere.Queries; namespace {{namespace}} { - [Route ("api/[controller]")] + [Route ("api/[controller]")] public class {{name}} : MediatorController { + [HttpGet] - [DescriptionAttribute ("Your endpoint description goes here.")] - [ProducesResponseType (typeof (YourReturnType), (int) HttpStatusCode.OK)] - public async Task Get() + [Description("Your endpoint description goes here.")] + public async Task> Get() { //TODO: Implement Realistic Implementation - await Mediator.Send (new YourCommandOrQueryHere() {}); - return Ok(); + var result = await Mediator.Send (new YourCommandOrQueryHere() {}); + + if(result == null) + return NotFound(); + + return Ok(result); } } } \ No newline at end of file diff --git a/src/gimme/Resources/App_Command.txt b/src/gimme/Resources/App_Command.txt index 3bc6c9c..f91027d 100644 --- a/src/gimme/Resources/App_Command.txt +++ b/src/gimme/Resources/App_Command.txt @@ -11,20 +11,20 @@ namespace {{namespace}} /// Command /// [JsonSchema("{{name}}Command")] - public class Command : IRequest + public class Command : IRequest { } /// /// Command Handler /// - public class CommandHandler : IRequestHandler + public class CommandHandler : IRequestHandler { public CommandHandler() { } - public async Task Handle(Command request, CancellationToken cancellationToken) + public async Task Handle(Command request, CancellationToken cancellationToken) { throw new NotImplementedException(); } diff --git a/src/gimme/Resources/WAS_Api_Conf_AutoMapper.txt b/src/gimme/Resources/WAS_Api_Conf_AutoMapper.txt index bdcecfb..e046f4c 100644 --- a/src/gimme/Resources/WAS_Api_Conf_AutoMapper.txt +++ b/src/gimme/Resources/WAS_Api_Conf_AutoMapper.txt @@ -5,7 +5,14 @@ namespace {{solutionname}}.Api.Configurations { public static class AutoMapper { internal static void RegisterAutoMapper (IServiceCollection services) { - services.AddAutoMapper (); + //http://docs.automapper.org/en/stable/Inline-Mapping.html + services.AddAutoMapper( + configAction => + { + configAction.ValidateInlineMaps = false; + }, + typeof(Application.Response) + ); } } } \ No newline at end of file diff --git a/src/gimme/Resources/WAS_Api_Conf_Swagger.txt b/src/gimme/Resources/WAS_Api_Conf_Swagger.txt index cd7ee34..1eac8da 100644 --- a/src/gimme/Resources/WAS_Api_Conf_Swagger.txt +++ b/src/gimme/Resources/WAS_Api_Conf_Swagger.txt @@ -1,14 +1,12 @@ -using System; -using System.Reflection; -using Microsoft.AspNetCore.Authentication.JwtBearer; +using System.Linq; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using NJsonSchema; using NSwag; using NSwag.AspNetCore; using NSwag.SwaggerGeneration.Processors.Security; + + namespace {{solutionname}}.Api.Configurations { public static class Swagger @@ -24,13 +22,15 @@ namespace {{solutionname}}.Api.Configurations { c.Title = "{{solutionname}} Api"; c.Version = "v1"; c.Description = "RESTFul Api for {{solutionname}}"; - c.DocumentProcessors.Add(new SecurityDefinitionAppender("JWT", new SwaggerSecurityScheme + + c.AddSecurity("JWT", Enumerable.Empty(), new SwaggerSecurityScheme { Type = SwaggerSecuritySchemeType.ApiKey, Name = "Authorization", In = SwaggerSecurityApiKeyLocation.Header, Description = "Copy 'Bearer ' + valid JWT token into field" - })); + }); + c.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT")); }); diff --git a/src/gimme/Resources/WAS_Api_MediatorController.txt b/src/gimme/Resources/WAS_Api_MediatorController.txt index 55f7adf..36d3b72 100644 --- a/src/gimme/Resources/WAS_Api_MediatorController.txt +++ b/src/gimme/Resources/WAS_Api_MediatorController.txt @@ -5,7 +5,8 @@ using Microsoft.Extensions.DependencyInjection; namespace {{solutionname}}.Api.Controllers { - public abstract class MediatorController : Controller + [ApiController] + public abstract class MediatorController : ControllerBase { private IMediator _mediator; diff --git a/src/gimme/Resources/WAS_App_Response.txt b/src/gimme/Resources/WAS_App_Response.txt new file mode 100644 index 0000000..c373327 --- /dev/null +++ b/src/gimme/Resources/WAS_App_Response.txt @@ -0,0 +1,42 @@ +namespace {{solutionname}}.Application +{ + public abstract class Response + { + protected Response(string message = null) + { + Message = message; + } + public string Message { get; set; } + } + + public class NotFoundResponse : Response + { + public NotFoundResponse(string message = null) : base(message) + { + } + } + + public class BadRequestResponse : Response + { + public BadRequestResponse(string message = null) : base(message) + { + } + } + + public class SuccessResponse : Response + { + public SuccessResponse(string message = null) : base(message) + { + } + } + + public class SuccessResponse : Response + { + public SuccessResponse(T data) + { + Data = data; + Message = "Success"; + } + public T Data { get; set; } + } +} diff --git a/src/gimme/gimme.csproj b/src/gimme/gimme.csproj index 01a9d2c..7d34944 100644 --- a/src/gimme/gimme.csproj +++ b/src/gimme/gimme.csproj @@ -10,10 +10,15 @@ https://www.nuget.org/packages/dotnet-gimme A CLI tool for dotnetcore that gives you want you want ;) Gimme! - 1.0.4 + 1.0.5 true + https://github.com/reggieboyYEAH/dotnet-gimme + + + + Always @@ -75,6 +80,9 @@ Always + + Always + Always