Skip to content

Commit

Permalink
Rename solution and projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Loupeznik committed Jan 28, 2024
1 parent 72c68a8 commit 81d1eb0
Show file tree
Hide file tree
Showing 106 changed files with 378 additions and 343 deletions.
27 changes: 0 additions & 27 deletions DZarsky.ToDoAppTemplate.Api/Dockerfile

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# ToDo app template API

A template repository for a ToDo app API with .NET8 and PostgreSQL. REPR (FastEndpoints), CQRS (MediatR) and partially Clean Architecture patterns are used.
The API is easily extensible and can be used as a starting point for a new project.

Functionality:

- Create, read, update and delete ToDos
- User registration, login, option to reset user's password. Accounts are stored in the database, authentication is done using JWT.
- Email templates and sending emails via Smtp or SendGrid is supported.

## Prerequisites

- [.NET 8](https://dotnet.microsoft.com/download/dotnet/8.0)
- [PostgreSQL](https://www.postgresql.org/download/)
- [Dotnet ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet)
- Optional: [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)

## Applying the database migrations

The database migrations are located in the `ToDoAppTemplate.Data` project. The following commands can be run from the solution root directory:

```powershell
# Create a new migration
dotnet ef migrations add MigrationName --project ./ToDoAppTemplate.Data --startup-project ./ToDoAppTemplate/Api
# Apply a migration
dotnet ef database update --project ./ToDoAppTemplate.Data --startup-project ./ToDoAppTemplate.Api
```

## Running the API

Either run the API by running `docker-compose up` from the root of the solution. This will start the API and a PostgreSQL database in Docker containers.

Or run the API from Visual Studio or the command line. The connection string to the database can be configured in the `appsettings.json` file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Application.Auth.Commands;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Application.Auth.Commands;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Endpoints;
namespace ToDoAppTemplate.Api.Auth.Endpoints;

public sealed class ChangePasswordEndpoint : Endpoint<PasswordChangeRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Resolvers;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Security;
using DZarsky.ToDoAppTemplate.Application.Auth.Queries;
using DZarsky.ToDoAppTemplate.Core.Auth.Models;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Api.Infrastructure.Resolvers;
using ToDoAppTemplate.Application.Auth.Queries;
using ToDoAppTemplate.Core.Auth.Models;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Auth.Models;
using ToDoAppTemplate.Api.Infrastructure.Security;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Endpoints;
namespace ToDoAppTemplate.Api.Auth.Endpoints;

public class LoginEndpoint : Endpoint<LoginRequest, LoginResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Resolvers;
using DZarsky.ToDoAppTemplate.Application.Auth.Commands;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Api.Infrastructure.Resolvers;
using ToDoAppTemplate.Application.Auth.Commands;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Endpoints;
namespace ToDoAppTemplate.Api.Auth.Endpoints;

public sealed class RegisterEndpoint : Endpoint<RegisterRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Application.Auth.Commands;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Application.Auth.Commands;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Endpoints;
namespace ToDoAppTemplate.Api.Auth.Endpoints;

public sealed class RequestPasswordResetEndpoint : Endpoint<RequestPasswordResetRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Application.Auth.Commands;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Application.Auth.Commands;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Endpoints;
namespace ToDoAppTemplate.Api.Auth.Endpoints;

public sealed class ResetPasswordEndpoint : Endpoint<PasswordResetRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public class LoginRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public sealed class LoginResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DZarsky.ToDoAppTemplate.Domain.Common;
using ToDoAppTemplate.Domain.Common;
using FastEndpoints;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public sealed class PasswordChangeRequest : IAuthenticatedRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public class PasswordResetRequest : RequestPasswordResetRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public sealed class RegisterRequest : LoginRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Auth.Models;
namespace ToDoAppTemplate.Api.Auth.Models;

public class RequestPasswordResetRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using FastEndpoints;
using FastEndpoints;
using FluentValidation;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Validators;
namespace ToDoAppTemplate.Api.Auth.Validators;

public sealed class PasswordChangeRequestValidator : Validator<PasswordChangeRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using FastEndpoints;
using FastEndpoints;
using FluentValidation;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Validators;
namespace ToDoAppTemplate.Api.Auth.Validators;

public sealed class PasswordResetRequestValidator : Validator<PasswordResetRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using FastEndpoints;
using FastEndpoints;
using FluentValidation;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Validators;
namespace ToDoAppTemplate.Api.Auth.Validators;

public class RegisterRequestValidator : Validator<RegisterRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Auth.Models;
using FastEndpoints;
using FastEndpoints;
using FluentValidation;
using ToDoAppTemplate.Api.Auth.Models;

namespace DZarsky.ToDoAppTemplate.Api.Auth.Validators;
namespace ToDoAppTemplate.Api.Auth.Validators;

public class RequestPasswordResetRequestValidator : Validator<RequestPasswordResetRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Common.Constants;
namespace ToDoAppTemplate.Api.Common.Constants;

public static class Endpoints
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Common.Models;
namespace ToDoAppTemplate.Api.Common.Models;

public abstract class GetResourceByIdRequest
{
Expand Down
27 changes: 27 additions & 0 deletions ToDoAppTemplate.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ToDoAppTemplate.Api/ToDoAppTemplate.Api.csproj", "ToDoAppTemplate.Api/"]
COPY ["ToDoAppTemplate.Domain/ToDoAppTemplate.Domain.csproj", "ToDoAppTemplate.Domain/"]
COPY ["ToDoAppTemplate.Application/ToDoAppTemplate.Application.csproj", "ToDoAppTemplate.Application/"]
COPY ["ToDoAppTemplate.Data/ToDoAppTemplate.Data.csproj", "ToDoAppTemplate.Data/"]
COPY ["ToDoAppTemplate.Core/ToDoAppTemplate.Core.csproj", "ToDoAppTemplate.Core/"]
RUN dotnet restore "ToDoAppTemplate.Api/ToDoAppTemplate.Api.csproj"
COPY . .
WORKDIR "/src/ToDoAppTemplate.Api"
RUN dotnet build "ToDoAppTemplate.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "ToDoAppTemplate.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ToDoAppTemplate.Api.dll"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Security;
using FastEndpoints;
using FastEndpoints;
using FastEndpoints.Security;
using FastEndpoints.Swagger;
using Microsoft.IdentityModel.Protocols.Configuration;
using ToDoAppTemplate.Api.Infrastructure.Security;

namespace DZarsky.ToDoAppTemplate.Api.Infrastructure.Configuration;
namespace ToDoAppTemplate.Api.Infrastructure.Configuration;

internal static class ApiConfigurationExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Resolvers;
using DZarsky.ToDoAppTemplate.Domain.Common.MediatR;
using ToDoAppTemplate.Api.Infrastructure.Resolvers;
using ToDoAppTemplate.Domain.Common.MediatR;
using FastEndpoints;

namespace DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
namespace ToDoAppTemplate.Api.Infrastructure.Extensions;

internal static class EndpointExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DZarsky.ToDoAppTemplate.Core.Auth.Models;
using DZarsky.ToDoAppTemplate.Domain.Common.Results;
using ToDoAppTemplate.Core.Auth.Models;
using ToDoAppTemplate.Domain.Common.Results;

namespace DZarsky.ToDoAppTemplate.Api.Infrastructure.Resolvers;
namespace ToDoAppTemplate.Api.Infrastructure.Resolvers;

internal static class StatusCodeResolver
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DZarsky.ToDoAppTemplate.Api.Infrastructure.Security;
namespace ToDoAppTemplate.Api.Infrastructure.Security;

public sealed class AuthConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Security.Claims;
using DZarsky.ToDoAppTemplate.Core.Auth.Models;
using ToDoAppTemplate.Core.Auth.Models;
using FastEndpoints.Security;

namespace DZarsky.ToDoAppTemplate.Api.Infrastructure.Security;
namespace ToDoAppTemplate.Api.Infrastructure.Security;

public sealed class TokenGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Configuration;
using DZarsky.ToDoAppTemplate.Application.Infrastructure.Configuration;
using DZarsky.ToDoAppTemplate.Core.Infrastructure.Configuration;
using DZarsky.ToDoAppTemplate.Data.Infrastructure.Configuration;
using DZarsky.ToDoAppTemplate.Data.Infrastructure.EF;
using ToDoAppTemplate.Api.Infrastructure.Configuration;
using ToDoAppTemplate.Application.Infrastructure.Configuration;
using ToDoAppTemplate.Core.Infrastructure.Configuration;
using ToDoAppTemplate.Data.Infrastructure.Configuration;
using ToDoAppTemplate.Data.Infrastructure.EF;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DZarsky.ToDoAppTemplate.Application\DZarsky.ToDoAppTemplate.Application.csproj" />
<ProjectReference Include="..\DZarsky.ToDoAppTemplate.Core\DZarsky.ToDoAppTemplate.Core.csproj" />
<ProjectReference Include="..\DZarsky.ToDoAppTemplate.Data\DZarsky.ToDoAppTemplate.Data.csproj" />
<ProjectReference Include="..\DZarsky.ToDoAppTemplate.Domain\DZarsky.ToDoAppTemplate.Domain.csproj" />
<ProjectReference Include="..\ToDoAppTemplate.Application\ToDoAppTemplate.Application.csproj" />
<ProjectReference Include="..\ToDoAppTemplate.Core\ToDoAppTemplate.Core.csproj" />
<ProjectReference Include="..\ToDoAppTemplate.Data\ToDoAppTemplate.Data.csproj" />
<ProjectReference Include="..\ToDoAppTemplate.Domain\ToDoAppTemplate.Domain.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using DZarsky.ToDoAppTemplate.Api.Infrastructure.Extensions;
using DZarsky.ToDoAppTemplate.Api.Todos.Models.Requests;
using DZarsky.ToDoAppTemplate.Api.Todos.Models.Responses;
using DZarsky.ToDoAppTemplate.Application.Todos.Commands;
using ToDoAppTemplate.Api.Infrastructure.Extensions;
using ToDoAppTemplate.Application.Todos.Commands;
using FastEndpoints;
using MediatR;
using ToDoAppTemplate.Api.Todos.Models.Requests;
using ToDoAppTemplate.Api.Todos.Models.Responses;

namespace DZarsky.ToDoAppTemplate.Api.Todos.Endpoints;
namespace ToDoAppTemplate.Api.Todos.Endpoints;

public sealed class AddToDoEndpoint : Endpoint<AddToDoRequest, GetToDoResponse>
{
Expand Down
Loading

0 comments on commit 81d1eb0

Please sign in to comment.