Skip to content

Commit

Permalink
Gimme 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Reggie Pangilinan committed May 12, 2019
1 parent 395183c commit 676411c
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 51 deletions.
9 changes: 6 additions & 3 deletions src/gimme/Commands/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ 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))
filesService.CreateDirectory(apiDirectory);

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!");
Expand Down
6 changes: 6 additions & 0 deletions src/gimme/Commands/WebApiStarter/Command.Step03.Scaffold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/gimme/Commands/WebApiStarter/Command.Step04.Nuget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
2 changes: 2 additions & 0 deletions src/gimme/Commands/WebApiStarter/Command.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,6 +38,7 @@ public void OnExecute()
Step02_CreateProjects();
Step03_Scaffold();
Step04_ConfigureNugetReference();
ConsoleUtil.SuccessMessage($"Done! ^_^");
}
}
}
87 changes: 62 additions & 25 deletions src/gimme/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/gimme/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,19 @@
<data name="WAS_App_RecordNotFoundException" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_app_recordnotfoundexception.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="WAS_App_Response" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_app_response.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="WAS_Domain_BaseEntity" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_domain_baseentity.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="WAS_GitIgnore" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_gitignore.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="WAS_Persistence_DbContext" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_Persistence_dbcontext.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
<value>..\resources\was_persistence_dbcontext.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="WAS_Persistence_DbContextFactory" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\was_Persistence_dbcontextfactory.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
<value>..\resources\was_persistence_dbcontextfactory.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>
19 changes: 13 additions & 6 deletions src/gimme/Resources/Api_Controller.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IActionResult> Get()
[Description("Your endpoint description goes here.")]
public async Task<ActionResult<Models.YourModelHere>> 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);
}
}
}
6 changes: 3 additions & 3 deletions src/gimme/Resources/App_Command.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace {{namespace}}
/// 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>
{
public CommandHandler()
{

}
public async Task<YouReturnTypeHere> Handle(Command request, CancellationToken cancellationToken)
public async Task<Response> Handle(Command request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
Expand Down
9 changes: 8 additions & 1 deletion src/gimme/Resources/WAS_Api_Conf_AutoMapper.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
}
14 changes: 7 additions & 7 deletions src/gimme/Resources/WAS_Api_Conf_Swagger.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<string>(), new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "Authorization",
In = SwaggerSecurityApiKeyLocation.Header,
Description = "Copy 'Bearer ' + valid JWT token into field"
}));
});

c.OperationProcessors.Add(new OperationSecurityScopeProcessor("JWT"));
});

Expand Down
3 changes: 2 additions & 1 deletion src/gimme/Resources/WAS_Api_MediatorController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 676411c

Please sign in to comment.