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

Feature/add todolist usecase #11

Merged
merged 4 commits into from
Sep 13, 2024
Merged
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
6 changes: 6 additions & 0 deletions .template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"symbolInfo": {
"UseOracle": {
"longName": "use-oracle"
},
"EnableContainerSupport": {
"longName": "enable-container-support"
},
"UseController": {
"longName": "use-controller"
}
}
}
20 changes: 18 additions & 2 deletions .template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
{
"id": "UseOracle",
"name": {
"text": "Use Oracle"
"text": "Use oracle"
},
"description": {
"text": "Use Oracle for database (default is LocalDB)."
"text": "Use oracle for database (default is LocalDB)."
},
"isVisible": true
},
{
"id": "EnableContainerSupport",
"name": {
"text": "Enable container support"
},
"description": {
"text": "Enable container support and add Docker file for linux."
},
"isVisible": true
},
{
"id": "UseController",
"name": {
"text": "Use controller instead of minimals APIs."
}
}
]
}
27 changes: 26 additions & 1 deletion .template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
"type": "computed",
"value": "(!UseOracle)"
},
"UseController": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "true",
"description": "Use controller instead of minimals APIs."
},
"EnableContainerSupport": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Enable container support (Docker for linux)."
},
"fcaRepositoryUrl": {
"type": "generated",
"generator": "constant",
Expand All @@ -44,7 +56,7 @@
"generator": "constant",
"replaces": "fcaPackageVersion",
"parameters": {
"value": "8.0.8"
"value": "8.0.1"
}
}
},
Expand Down Expand Up @@ -93,6 +105,19 @@
"appsettings.Oracle.json": "appsettings.json",
"TestDatabase.Oracle.cs": "TestDatabase.cs"
}
},
{
"condition": "(!UseController)",
"exclude": [
"src/API/Controllers"
]
},
{
"condition": "(!EnableContainerSupport)",
"exclude": [
"src/API/Dockerfile",
".dockerignore"
]
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
52 changes: 27 additions & 25 deletions FastCleanArchitecture.nuspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<metadata>

<id>Fast.Clean.Architecture.Solution.Template</id>
<version>8.0.1</version>
<title>Fast Clean Architecture Solution Template</title>
<authors>christiandr</authors>
<description>Fast Clean Architecture Solution Template for .NET 8.</description>
<summary>
A Clean Architecture Solution Template for creating apps using Web API only with DotNet.
</summary>
<id>Fast.Clean.Architecture.Solution.Template</id>
<version>8.0.1</version>
<title>Fast Clean Architecture Solution Template</title>
<authors>christiandr</authors>
<description>Fast Clean Architecture Solution Template for .NET 8.</description>
<summary>
A Clean Architecture Solution Template for create apps.
</summary>
<releaseNotes>
</releaseNotes>

<projectUrl>https://github.com/christianrd/FastCleanArchitecture</projectUrl>
<repository type="git" url="https://github.com/christianrd/FastCleanArchitecture.git" branch="main" />
<projectUrl>https://github.com/christianrd/FastCleanArchitecture</projectUrl>
<repository type="git" url="https://github.com/christianrd/FastCleanArchitecture.git" branch="main" />

<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>fast-clean-architecture clean-architecture project template csharp dotnet</tags>
<icon>icon.png</icon>
<readme>README.md</readme>
<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>fast-clean-architecture clean-architecture project template csharp dotnet</tags>
<icon>icon.png</icon>
<readme>README.md</readme>

<packageTypes>
<packageType name="Template" />
</packageTypes>
</metadata>
<packageTypes>
<packageType name="Template" />
</packageTypes>
</metadata>

<files>
<file src=".template.config\icon.png" />
<file src="README.md" />
<file src=".\**" target="content" exclude="**\bin\**;**\obj\**;.\.vs\**;.\.vscode\**;content\Directory.Build.*;.\.git\**;.\.github\workflows\package.yml;.\.github\workflows\codeql.yml;.\.github\workflows\build.yml;.\.github\ISSUE_TEMPLATE\**;.\.github\icon.png;.\.github\FUNDING.md;.\CODE_OF_CONDUCT.md;.\LICENSE;.\README.md;" />
</files>
<files>
<file src=".template.config\icon.png" />
<file src="README.md" />
<file src=".\**" target="content" exclude="**\bin\**;**\obj\**;.\.vs\**;.\.vscode\**;content\Directory.Build.*;.\.git\**;.\.github\workflows\package.yml;.\.github\workflows\codeql.yml;.\.github\workflows\build.yml;.\.github\ISSUE_TEMPLATE\**;.\.github\icon.png;.\.github\FUNDING.md;.\CODE_OF_CONDUCT.md;.\LICENSE;.\README.md;" />
</files>
</package>
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Starting is quick and easy-just install the .NET template (detailed instructions
The following prerequisites are required to build and run the solution:

- [.NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) (latest version)
- [Node.js](https://nodejs.org/) (latest LTS, only required if you are using Angular or React)

The easiest way to get started is to install the [.NET template](https://www.nuget.org/packages/Fast.Clean.Architecture.Solution.Template):
```
Expand Down Expand Up @@ -85,6 +84,8 @@ The template includes a full CI/CD pipeline. The pipeline is responsible for bui
* [ASP.NET Core 8](https://docs.microsoft.com/en-us/aspnet/core/introduction-to-aspnet-core)
* [Entity Framework Core 8](https://docs.microsoft.com/en-us/ef/core/)
* [MediatR](https://github.com/jbogard/MediatR)
* [Maspter](https://github.com/MapsterMapper/Mapster)
* [FluentResult](https://github.com/altmann/FluentResults)
* [FluentValidation](https://fluentvalidation.net/)
* [NUnit](https://nunit.org/), [FluentAssertions](https://fluentassertions.com/), [Moq](https://github.com/devlooped/moq) & [Respawn](https://github.com/jbogard/Respawn)

Expand Down
3 changes: 2 additions & 1 deletion fastCleanArchitecture.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "src\Infra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "src\API\API.csproj", "{3A7EAD0E-2F46-4022-9119-96593FFEC72D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C7FBE7FF-00ED-4E1B-B015-CC61AE8E0FD3}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7FBE7FF-00ED-4E1B-B015-CC61AE8E0FD3}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
FastCleanArchitecture.nuspec = FastCleanArchitecture.nuspec
README-template.md = README-template.md
README.md = README.md
EndProjectSection
EndProject
Expand Down
4 changes: 4 additions & 0 deletions src/API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>f5e32e1e-4b42-4557-9635-b9a0c84f3591</UserSecretsId>
<!--#if (EnableContainerSupport)-->
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<!--#endif-->
<CompanyName>FastCleanArchitecture</CompanyName>
<Company>$(CompanyName)</Company>
<RootNamespace>$(CompanyName.Replace(" ", "")).$(MSBuildProjectName.Replace(" ", ""))</RootNamespace>
<AssemblyName>$(CompanyName.Replace(" ", "")).$(MSBuildProjectName.Replace(" ", ""))</AssemblyName>
</PropertyGroup>

<ItemGroup>
<!--#if (EnableContainerSupport)-->
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<!--#endif-->
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace FastCleanArchitecture.API.Controllers;

[ApiController]
public abstract class BaseController : ControllerBase
public abstract class ApiControllerBase : ControllerBase
{
protected readonly ISender Sender;

public BaseController(ISender Sender) => this.Sender = Sender;
}
public ApiControllerBase(ISender Sender) => this.Sender = Sender;
}
36 changes: 36 additions & 0 deletions src/API/Controllers/TodoItems/TodoItemsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using FastCleanArchitecture.Application.TodoItems.Commands.CreateTodoItem;
using FastCleanArchitecture.Application.TodoItems.Commands.DeleteTodoItem;
using FastCleanArchitecture.Application.TodoItems.Commands.UpdateTodoItem;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace FastCleanArchitecture.API.Controllers.TodoItems;

[Route("api/[controller]")]
public sealed class TodoItemsController(ISender sender) : ApiControllerBase(sender)
{
[HttpPost]
public async Task<IActionResult> CreateTodoItem([FromBody] CreateTodoItemCommand request)
{
await Sender.Send(request);

return NoContent();
}

[HttpPut("{Id}")]
public async Task<IActionResult> UpdateTodoItem(UpdateTodoItemCommand request)
{
var result = await Sender.Send(request);
if (result.IsFailed)
return NotFound("Item not found.");

return NoContent();
}

[HttpDelete("{Id}")]
public async Task<IActionResult> DeleteTodoItem([FromRoute] DeleteTodoItemCommand request)
{
await Sender.Send(request);
return NoContent();
}
}
46 changes: 46 additions & 0 deletions src/API/Controllers/TodoLists/TodoListsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using FastCleanArchitecture.Application.TodoLists.Commands.Create;
using FastCleanArchitecture.Application.TodoLists.Commands.Delete;
using FastCleanArchitecture.Application.TodoLists.Commands.Update;
using FastCleanArchitecture.Application.TodoLists.Queries.GetTodos;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace FastCleanArchitecture.API.Controllers.TodoLists;

[Route("api/[controller]")]
public sealed class TodoListsController(ISender Sender) : ApiControllerBase(Sender)
{
[HttpGet(Name = nameof(GetTodoLists))]
public async Task<IActionResult> GetTodoLists()
{
var result = await Sender.Send(new GetTodosQuery());
return Ok(result.ValueOrDefault);
}

[HttpPost]
public async Task<IActionResult> CreateTodoList(CreateTodoListCommand request)
{
var result = await Sender.Send(request);
if (result.IsFailed)
return BadRequest(result.Errors);

return CreatedAtRoute(nameof(GetTodoLists), result.Value);
}

[HttpPut("{Id}")]
public async Task<IActionResult> UpdateTodoList(UpdateTodoListCommand request)
{
var result = await Sender.Send(request);
if (result.IsFailed)
return BadRequest(result.Errors);

return NoContent();
}

[HttpDelete("{Id}")]
public async Task<IActionResult> DeleteTodoList([FromRoute] DeleteTodoListCommand request)
{
await Sender.Send(request);
return NoContent();
}
}
19 changes: 0 additions & 19 deletions src/API/Controllers/TodoListsController.cs

This file was deleted.

7 changes: 5 additions & 2 deletions src/API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using FastCleanArchitecture.Infrastructure;

var builder = WebApplication.CreateBuilder(args);

#if (UseController)
builder.Services.AddControllers();
#endif

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand All @@ -22,8 +23,10 @@

app.UseHttpsRedirection();

#if (UseController)
app.MapControllers();
#endif

await app.UseInfrastructureAsync();

app.Run();
app.Run();
16 changes: 16 additions & 0 deletions src/Application/.templating.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"symbolInfo": {
"featureName": {
"longName": "feature-name",
"shortName": "fn"
},
"returnType": {
"longName": "return-type",
"shortName": "rt"
},
"useCaseType": {
"longName": "usecase-type",
"shortName": "ut"
}
}
}
Binary file added src/Application/.templating.config/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading