diff --git a/development/compose.yml b/development/compose.yml new file mode 100644 index 0000000..7392d2f --- /dev/null +++ b/development/compose.yml @@ -0,0 +1,54 @@ +name: user-manager +services: + + db: + image: postgres:16.4 + container_name: user-manager-dev-deb + restart: unless-stopped + ports: + - "5432:5432" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: user-manager + volumes: + - user-manager-db-data:/var/lib/postgresql/data + + minio: + image: quay.io/minio/minio:RELEASE.2024-09-13T20-26-02Z + container_name: user-manager-dev-minio + restart: unless-stopped + ports: + - "9000:9000" + - "9001:9001" + environment: + MINIO_ROOT_USER: miniodev + MINIO_ROOT_PASSWORD: miniodevpw + volumes: + - user-manager-minio-data:/data + command: minio server /data --console-address ":9001" + + make-minio-buckets: + image: minio/mc + restart: no + container_name: user-manager-dev-minio-mc + depends_on: + - minio + entrypoint: sh + command: + - -c + - | + mc alias set minio http://minio:9000 miniodev miniodevpw; + mc mb minio/usermanager-dev; + mc admin user add minio usermanagerdevaccesskey usermanagerdevsecretkey; + mc admin policy create minio usermanager-dev-rw-access /tmp/minio-policy.json; + mc admin policy attach minio usermanager-dev-rw-access --user usermanageraccesskey; + mc admin user info minio usermanagerdevaccesskey; + exit 0; + + volumes: + - ./misc/minio-policy.json:/tmp/minio-policy.json + +volumes: + user-manager-db-data: + user-manager-minio-data: \ No newline at end of file diff --git a/development/minio-policy.json b/development/minio-policy.json new file mode 100644 index 0000000..04b8a08 --- /dev/null +++ b/development/minio-policy.json @@ -0,0 +1,15 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetObject", + "s3:PutObject" + ], + "Resource": [ + "arn:aws:s3:::usermanager-dev/*" + ] + } + ] +} \ No newline at end of file diff --git a/src/UserManager.API/Controllers/WeatherForecastController.cs b/src/UserManager.API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..16433fc --- /dev/null +++ b/src/UserManager.API/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace UserManager.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/src/UserManager.API/Program.cs b/src/UserManager.API/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/src/UserManager.API/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/src/UserManager.API/Properties/launchSettings.json b/src/UserManager.API/Properties/launchSettings.json new file mode 100644 index 0000000..7e6f6f4 --- /dev/null +++ b/src/UserManager.API/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:35300", + "sslPort": 44337 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5110", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7151;http://localhost:5110", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/UserManager.API/UserManager.API.csproj b/src/UserManager.API/UserManager.API.csproj new file mode 100644 index 0000000..5419ef0 --- /dev/null +++ b/src/UserManager.API/UserManager.API.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/src/UserManager.API/UserManager.API.http b/src/UserManager.API/UserManager.API.http new file mode 100644 index 0000000..da05126 --- /dev/null +++ b/src/UserManager.API/UserManager.API.http @@ -0,0 +1,6 @@ +@UserManager.API_HostAddress = http://localhost:5110 + +GET {{UserManager.API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/src/UserManager.API/WeatherForecast.cs b/src/UserManager.API/WeatherForecast.cs new file mode 100644 index 0000000..9a85090 --- /dev/null +++ b/src/UserManager.API/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace UserManager.API +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/src/UserManager.API/appsettings.Development.json b/src/UserManager.API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/UserManager.API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/UserManager.API/appsettings.json b/src/UserManager.API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/UserManager.API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/UserManager.Application/Features/Users/Interfaces/IUserService.cs b/src/UserManager.Application/Features/Users/Interfaces/IUserService.cs new file mode 100644 index 0000000..9874aaa --- /dev/null +++ b/src/UserManager.Application/Features/Users/Interfaces/IUserService.cs @@ -0,0 +1,10 @@ +using UserManager.Application.Features.Users.Requests; +using UserManager.Application.Features.Users.Responses; + +namespace UserManager.Application.Features.Users.Interfaces +{ + public interface IUserService + { + Task CreateUserAsync(CreateUserRequestDto request); + } +} diff --git a/src/UserManager.Application/Features/Users/Requests/CreateUserRequestDto.cs b/src/UserManager.Application/Features/Users/Requests/CreateUserRequestDto.cs new file mode 100644 index 0000000..964ea53 --- /dev/null +++ b/src/UserManager.Application/Features/Users/Requests/CreateUserRequestDto.cs @@ -0,0 +1,10 @@ +namespace UserManager.Application.Features.Users.Requests +{ + public class CreateUserRequestDto + { + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public int? FavouriteRestaurantId { get; set; } + public string? FavouriteRestaurantName { get; set; } + } +} diff --git a/src/UserManager.Application/Features/Users/Responses/CreateUserResponseDto.cs b/src/UserManager.Application/Features/Users/Responses/CreateUserResponseDto.cs new file mode 100644 index 0000000..1c53e4c --- /dev/null +++ b/src/UserManager.Application/Features/Users/Responses/CreateUserResponseDto.cs @@ -0,0 +1,7 @@ +namespace UserManager.Application.Features.Users.Responses +{ + public class CreateUserResponseDto + { + public string FirstName { get; set; } = string.Empty; + } +} diff --git a/src/UserManager.Application/Features/Users/Services/UserService.cs b/src/UserManager.Application/Features/Users/Services/UserService.cs new file mode 100644 index 0000000..5ca0f2c --- /dev/null +++ b/src/UserManager.Application/Features/Users/Services/UserService.cs @@ -0,0 +1,19 @@ +using UserManager.Application.Features.Users.Interfaces; +using UserManager.Application.Features.Users.Requests; +using UserManager.Application.Features.Users.Responses; +using UserManager.Application.Interfaces; + +namespace UserManager.Application.Features.Users.Services +{ + class UserService(IUserRepository userRepository) : IUserService + { + private readonly IUserRepository _userRepository = userRepository; + + public Task CreateUserAsync(CreateUserRequestDto request) + { + // TODO + // First validate this user does not exist + // Then create the user + } + } +} diff --git a/src/UserManager.Application/Interfaces/IBaseRepository.cs b/src/UserManager.Application/Interfaces/IBaseRepository.cs new file mode 100644 index 0000000..46aaaaa --- /dev/null +++ b/src/UserManager.Application/Interfaces/IBaseRepository.cs @@ -0,0 +1,7 @@ +namespace UserManager.Application.Interfaces +{ + public interface IBaseRepository where TEntity : class + { + Task CreateAsync(TEntity entity); + } +} diff --git a/src/UserManager.Application/Interfaces/IUserRepository.cs b/src/UserManager.Application/Interfaces/IUserRepository.cs new file mode 100644 index 0000000..9047846 --- /dev/null +++ b/src/UserManager.Application/Interfaces/IUserRepository.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UserManager.Domain.Entities; + +namespace UserManager.Application.Interfaces +{ + public interface IUserRepository : IBaseRepository { } +} diff --git a/src/UserManager.Application/UserManager.Application.csproj b/src/UserManager.Application/UserManager.Application.csproj new file mode 100644 index 0000000..2481cb1 --- /dev/null +++ b/src/UserManager.Application/UserManager.Application.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/src/UserManager.Domain/Entities/User.cs b/src/UserManager.Domain/Entities/User.cs new file mode 100644 index 0000000..2e003af --- /dev/null +++ b/src/UserManager.Domain/Entities/User.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UserManager.Domain.Entities +{ + public class User + { + public int UserId { get; set; } + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + } +} diff --git a/src/UserManager.Domain/UserManager.Domain.csproj b/src/UserManager.Domain/UserManager.Domain.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/UserManager.Domain/UserManager.Domain.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/UserManager.Infrastructure/Class1.cs b/src/UserManager.Infrastructure/Class1.cs new file mode 100644 index 0000000..f3cd240 --- /dev/null +++ b/src/UserManager.Infrastructure/Class1.cs @@ -0,0 +1,7 @@ +namespace UserManager.Infrastructure +{ + public class Class1 + { + + } +} diff --git a/src/UserManager.Infrastructure/UserManager.Infrastructure.csproj b/src/UserManager.Infrastructure/UserManager.Infrastructure.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/UserManager.Infrastructure/UserManager.Infrastructure.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/UserManager.sln b/src/UserManager.sln new file mode 100644 index 0000000..6f7d91e --- /dev/null +++ b/src/UserManager.sln @@ -0,0 +1,60 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{74E412ED-9D1B-4597-BBFD-05623C814F98}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5B673FE8-32DA-4CD3-8394-1BD8E1275270}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManager.API", "UserManager.API\UserManager.API.csproj", "{A9A6D6F8-424B-4555-95D9-ECE60837B800}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManager.Domain", "UserManager.Domain\UserManager.Domain.csproj", "{17851242-59E3-4790-9FD8-32B848BBAB3D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManager.Infrastructure", "UserManager.Infrastructure\UserManager.Infrastructure.csproj", "{A85D13CB-884E-439D-AAE7-C4C4C2511FDE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManager.Application", "UserManager.Application\UserManager.Application.csproj", "{C7215859-A216-4527-A192-7B8F57E50BB4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManager.Application.UnitTests", "..\tests\UserManager.Application.Tests\UserManager.Application.UnitTests.csproj", "{B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A9A6D6F8-424B-4555-95D9-ECE60837B800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9A6D6F8-424B-4555-95D9-ECE60837B800}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9A6D6F8-424B-4555-95D9-ECE60837B800}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9A6D6F8-424B-4555-95D9-ECE60837B800}.Release|Any CPU.Build.0 = Release|Any CPU + {17851242-59E3-4790-9FD8-32B848BBAB3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17851242-59E3-4790-9FD8-32B848BBAB3D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17851242-59E3-4790-9FD8-32B848BBAB3D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17851242-59E3-4790-9FD8-32B848BBAB3D}.Release|Any CPU.Build.0 = Release|Any CPU + {A85D13CB-884E-439D-AAE7-C4C4C2511FDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A85D13CB-884E-439D-AAE7-C4C4C2511FDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A85D13CB-884E-439D-AAE7-C4C4C2511FDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A85D13CB-884E-439D-AAE7-C4C4C2511FDE}.Release|Any CPU.Build.0 = Release|Any CPU + {C7215859-A216-4527-A192-7B8F57E50BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7215859-A216-4527-A192-7B8F57E50BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7215859-A216-4527-A192-7B8F57E50BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7215859-A216-4527-A192-7B8F57E50BB4}.Release|Any CPU.Build.0 = Release|Any CPU + {B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A9A6D6F8-424B-4555-95D9-ECE60837B800} = {74E412ED-9D1B-4597-BBFD-05623C814F98} + {17851242-59E3-4790-9FD8-32B848BBAB3D} = {74E412ED-9D1B-4597-BBFD-05623C814F98} + {A85D13CB-884E-439D-AAE7-C4C4C2511FDE} = {74E412ED-9D1B-4597-BBFD-05623C814F98} + {C7215859-A216-4527-A192-7B8F57E50BB4} = {74E412ED-9D1B-4597-BBFD-05623C814F98} + {B0F63D11-6933-4D87-B0D8-6DD7DFC5A23C} = {5B673FE8-32DA-4CD3-8394-1BD8E1275270} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6E7F90F4-4A09-4CDB-8653-6E094E164853} + EndGlobalSection +EndGlobal diff --git a/tests/UserManager.Application.Tests/Class1.cs b/tests/UserManager.Application.Tests/Class1.cs new file mode 100644 index 0000000..7e59215 --- /dev/null +++ b/tests/UserManager.Application.Tests/Class1.cs @@ -0,0 +1,7 @@ +namespace UserManager.Application.Tests +{ + public class Class1 + { + + } +} diff --git a/tests/UserManager.Application.Tests/UserManager.Application.UnitTests.csproj b/tests/UserManager.Application.Tests/UserManager.Application.UnitTests.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/tests/UserManager.Application.Tests/UserManager.Application.UnitTests.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + +