From a2906cc1133eff77b95d6e6fc1a0a568ab1bd94e Mon Sep 17 00:00:00 2001 From: ivanszabo Date: Wed, 15 Jan 2025 14:01:58 +0100 Subject: [PATCH] =?UTF-8?q?Na=20most=20m=C5=B1k=C3=B6dik=20az=20API=20+=20?= =?UTF-8?q?adatb=C3=A1zis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WorkFlowCheck.API.sln | 48 +++++++++++++++++++ .../.config/dotnet-tools.json | 13 +++++ .../Controllers/UserController.cs | 9 +++- src/WorkFlowCheck.API/Program.cs | 32 +++++++++---- .../Properties/launchSettings.json | 24 ++++++++-- .../WorkFlowCheck.API.csproj | 14 ++++-- src/WorkFlowCheck.API/appsettings.json | 21 ++++++-- src/WorkFlowCheck.API/publish.cmd | 2 + src/WorkFlowCheck.BL/DTO/UserDTO.cs | 3 +- src/WorkFlowCheck.BL/Infra/DIConfig.cs | 19 ++++++++ .../Mappings/MapperProfile.cs | 20 ++++++++ .../Services/Interfaces/IUserService.cs | 14 ++++++ src/WorkFlowCheck.BL/Services/UserService.cs | 43 +++++++++++++++++ src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj | 10 ++++ src/WorkFlowCheck.DL/AppDbContext.cs | 6 +++ .../Configurations/UserTypeConfiguration.cs | 21 ++++++++ src/WorkFlowCheck.DL/Entities/User.cs | 7 ++- 17 files changed, 283 insertions(+), 23 deletions(-) create mode 100644 src/WorkFlowCheck.API.sln create mode 100644 src/WorkFlowCheck.API/.config/dotnet-tools.json create mode 100644 src/WorkFlowCheck.API/publish.cmd create mode 100644 src/WorkFlowCheck.BL/Infra/DIConfig.cs create mode 100644 src/WorkFlowCheck.BL/Mappings/MapperProfile.cs create mode 100644 src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs create mode 100644 src/WorkFlowCheck.BL/Services/UserService.cs create mode 100644 src/WorkFlowCheck.DL/Configurations/UserTypeConfiguration.cs diff --git a/src/WorkFlowCheck.API.sln b/src/WorkFlowCheck.API.sln new file mode 100644 index 0000000..0782e62 --- /dev/null +++ b/src/WorkFlowCheck.API.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowCheck.API", "WorkFlowCheck.API\WorkFlowCheck.API.csproj", "{2466E04A-CB0C-4421-9074-A928F819926C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.NFC", "Plugin.NFC\Plugin.NFC.csproj", "{6B46795C-DF5A-4F12-95A9-691BC1741AB8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowCheck.MAUI", "WorkFlowCheck.MAUI\WorkFlowCheck.MAUI.csproj", "{0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowCheck.DL", "WorkFlowCheck.DL\WorkFlowCheck.DL.csproj", "{25A8C0E7-18C7-4672-ABE8-29596E7E9B72}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkFlowCheck.BL", "WorkFlowCheck.BL\WorkFlowCheck.BL.csproj", "{73049F81-7A5D-4819-ADB8-A9926672365E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2466E04A-CB0C-4421-9074-A928F819926C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2466E04A-CB0C-4421-9074-A928F819926C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2466E04A-CB0C-4421-9074-A928F819926C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2466E04A-CB0C-4421-9074-A928F819926C}.Release|Any CPU.Build.0 = Release|Any CPU + {6B46795C-DF5A-4F12-95A9-691BC1741AB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B46795C-DF5A-4F12-95A9-691BC1741AB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B46795C-DF5A-4F12-95A9-691BC1741AB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B46795C-DF5A-4F12-95A9-691BC1741AB8}.Release|Any CPU.Build.0 = Release|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Release|Any CPU.Build.0 = Release|Any CPU + {0E2BD120-EE91-4A24-A78A-CE7CA87E09AE}.Release|Any CPU.Deploy.0 = Release|Any CPU + {25A8C0E7-18C7-4672-ABE8-29596E7E9B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25A8C0E7-18C7-4672-ABE8-29596E7E9B72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25A8C0E7-18C7-4672-ABE8-29596E7E9B72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25A8C0E7-18C7-4672-ABE8-29596E7E9B72}.Release|Any CPU.Build.0 = Release|Any CPU + {73049F81-7A5D-4819-ADB8-A9926672365E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {73049F81-7A5D-4819-ADB8-A9926672365E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {73049F81-7A5D-4819-ADB8-A9926672365E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {73049F81-7A5D-4819-ADB8-A9926672365E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/WorkFlowCheck.API/.config/dotnet-tools.json b/src/WorkFlowCheck.API/.config/dotnet-tools.json new file mode 100644 index 0000000..4f48799 --- /dev/null +++ b/src/WorkFlowCheck.API/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "9.0.0", + "commands": [ + "dotnet-ef" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/src/WorkFlowCheck.API/Controllers/UserController.cs b/src/WorkFlowCheck.API/Controllers/UserController.cs index 5ec0994..8930a29 100644 --- a/src/WorkFlowCheck.API/Controllers/UserController.cs +++ b/src/WorkFlowCheck.API/Controllers/UserController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WorkFlowCheck.BL.DTO; +using WorkFlowCheck.BL.Services.Interfaces; namespace WorkFlowCheck.API.Controllers { @@ -8,15 +9,21 @@ namespace WorkFlowCheck.API.Controllers [ApiController] public class UserController : ControllerBase { + private IUserService _userService; + public UserController(IUserService userService) + { + _userService = userService; + } [HttpGet] public async Task> Get() { - var userDTO = new UserDTO() { Id = 1, Email = "email", Name = "Name" }; + var userDTO = await _userService.GetUser(1); var retVal = new ApiResponseDTO() { IsSuccess = true, Data = userDTO }; + return retVal; } } diff --git a/src/WorkFlowCheck.API/Program.cs b/src/WorkFlowCheck.API/Program.cs index b534504..223552d 100644 --- a/src/WorkFlowCheck.API/Program.cs +++ b/src/WorkFlowCheck.API/Program.cs @@ -5,19 +5,33 @@ using System.Text.Json.Serialization; using WorkFlowCheck.API; using WorkFlowCheck.DL; using Microsoft.AspNetCore.Mvc; +using Serilog; +using WorkFlowCheck.BL.Mappings; +using WorkFlowCheck.BL.Infra; var builder = WebApplication.CreateBuilder(args); -builder.WebHost.ConfigureKestrel(options => -{ - options.ListenAnyIP(5069, listenOptions => - { - listenOptions.UseHttps(Path.Combine(AppContext.BaseDirectory, "Certs", "SwaggerCert.pfx"), "Noispot135!Xy()zz654321"); - }); -}); +Log.Logger = new LoggerConfiguration() + .WriteTo.Console() // Logok írása a konzolra + .WriteTo.File("logs/WorkFlowCheck.log", rollingInterval: RollingInterval.Day) // Logok fájlba + .CreateLogger(); + +//builder.WebHost.ConfigureKestrel(options => +//{ +// options.ListenAnyIP(5069, listenOptions => +// { +// listenOptions.UseHttps(Path.Combine(AppContext.BaseDirectory, "Certs", "SwaggerCert.pfx"), "Noispot135!Xy()zz654321"); +// }); +//}); +builder.Services.AddAutoMapper(typeof(MapperProfile)); + +var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext(options => - options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); + options.UseSqlServer(connectionString)); +//DI + +DIConfig.DIInit(builder.Services); // SWAGGER !!! builder.Services.AddEndpointsApiExplorer(); @@ -54,6 +68,8 @@ builder.Services.AddSwaggerGen(c => }); }); +builder.Host.UseSerilog(); + builder.Services.AddControllers() .AddNewtonsoftJson(options => { diff --git a/src/WorkFlowCheck.API/Properties/launchSettings.json b/src/WorkFlowCheck.API/Properties/launchSettings.json index 2bc9139..e0cc546 100644 --- a/src/WorkFlowCheck.API/Properties/launchSettings.json +++ b/src/WorkFlowCheck.API/Properties/launchSettings.json @@ -1,15 +1,31 @@ { - "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "todos", - "applicationUrl": "https://192.168.50.128:5069", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:5069" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "todos", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59027/", + "sslPort": 44382 + } } -} +} \ No newline at end of file diff --git a/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj b/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj index 45ebccc..03f15fa 100644 --- a/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj +++ b/src/WorkFlowCheck.API/WorkFlowCheck.API.csproj @@ -1,13 +1,15 @@ - + net8.0 + OutOfProcess + win-x64 + true enable enable - true - true + false + false - @@ -16,6 +18,10 @@ + + + + diff --git a/src/WorkFlowCheck.API/appsettings.json b/src/WorkFlowCheck.API/appsettings.json index 6e69caf..d3e074e 100644 --- a/src/WorkFlowCheck.API/appsettings.json +++ b/src/WorkFlowCheck.API/appsettings.json @@ -1,13 +1,28 @@ { - "DefaultConnection": { - "ConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=WorkFlowCheckDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" + "ConnectionStrings": { + "DefaultConnection": "Data Source=WS2016DC\\SQLEXPRESS;Initial Catalog=WFC;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False" }, "ApiKey": "RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU=", "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Verbose" } }, + "Serilog": { + "MinimumLevel": "Verbose", + "WriteTo": [ + { + "Name": "Console" + }, + { + "Name": "File", + "Args": { + "path": "logs/log-.txt", + "rollingInterval": "Day" + } + } + ] + }, "AllowedHosts": "*" } diff --git a/src/WorkFlowCheck.API/publish.cmd b/src/WorkFlowCheck.API/publish.cmd new file mode 100644 index 0000000..a290b9c --- /dev/null +++ b/src/WorkFlowCheck.API/publish.cmd @@ -0,0 +1,2 @@ +dotnet publish -c Release -o e:\wfcapi\ +pause \ No newline at end of file diff --git a/src/WorkFlowCheck.BL/DTO/UserDTO.cs b/src/WorkFlowCheck.BL/DTO/UserDTO.cs index 2ebece0..5b13dca 100644 --- a/src/WorkFlowCheck.BL/DTO/UserDTO.cs +++ b/src/WorkFlowCheck.BL/DTO/UserDTO.cs @@ -3,7 +3,8 @@ public class UserDTO { public int Id { get; set; } - public string Name { get; set; } = null!; public string Email { get; set; } = null!; + public string FirstName { get; set; } = null!; + public string LastName { get; set; } = null!; } } diff --git a/src/WorkFlowCheck.BL/Infra/DIConfig.cs b/src/WorkFlowCheck.BL/Infra/DIConfig.cs new file mode 100644 index 0000000..2b2e8ac --- /dev/null +++ b/src/WorkFlowCheck.BL/Infra/DIConfig.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.BL.Services; +using WorkFlowCheck.BL.Services.Interfaces; + +namespace WorkFlowCheck.BL.Infra +{ + public static class DIConfig + { + public static void DIInit(IServiceCollection service) + { + service.AddScoped(); + } + } +} diff --git a/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs new file mode 100644 index 0000000..30398b3 --- /dev/null +++ b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoMapper; +using AutoMapper.Configuration.Conventions; +using WorkFlowCheck.BL.DTO; +using WorkFlowCheck.DL.Entities; + +namespace WorkFlowCheck.BL.Mappings +{ + public class MapperProfile : Profile + { + public MapperProfile() + { + CreateMap(); + } + } +} diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs new file mode 100644 index 0000000..28496a9 --- /dev/null +++ b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.BL.DTO; + +namespace WorkFlowCheck.BL.Services.Interfaces +{ + public interface IUserService + { + Task GetUser(int Id); + } +} diff --git a/src/WorkFlowCheck.BL/Services/UserService.cs b/src/WorkFlowCheck.BL/Services/UserService.cs new file mode 100644 index 0000000..517d842 --- /dev/null +++ b/src/WorkFlowCheck.BL/Services/UserService.cs @@ -0,0 +1,43 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.BL.DTO; +using WorkFlowCheck.BL.Services.Interfaces; +using WorkFlowCheck.DL; + +namespace WorkFlowCheck.BL.Services +{ + public class UserService : IUserService + { + private AppDbContext _dbContext; + private IMapper _mapper; + public UserService(AppDbContext dbContext, IMapper mapper) + { + _dbContext = dbContext; + _mapper = mapper; + } + public async Task GetUser(int Id) + { + var retVal = new UserDTO(); + + try + { + var user = await _dbContext.Users.Where(w => w.Id == Id).FirstOrDefaultAsync(); + if (user != null) + { + retVal = _mapper.Map(user); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } + } +} diff --git a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj index fa71b7a..1faa4c4 100644 --- a/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj +++ b/src/WorkFlowCheck.BL/WorkFlowCheck.BL.csproj @@ -6,4 +6,14 @@ enable + + + + + + + + + + diff --git a/src/WorkFlowCheck.DL/AppDbContext.cs b/src/WorkFlowCheck.DL/AppDbContext.cs index 5319fa3..dd61b02 100644 --- a/src/WorkFlowCheck.DL/AppDbContext.cs +++ b/src/WorkFlowCheck.DL/AppDbContext.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WorkFlowCheck.DL.Configurations; namespace WorkFlowCheck.DL { @@ -15,5 +16,10 @@ namespace WorkFlowCheck.DL } public DbSet Users { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new UserTypeConfiguration()); + } } } diff --git a/src/WorkFlowCheck.DL/Configurations/UserTypeConfiguration.cs b/src/WorkFlowCheck.DL/Configurations/UserTypeConfiguration.cs new file mode 100644 index 0000000..da57722 --- /dev/null +++ b/src/WorkFlowCheck.DL/Configurations/UserTypeConfiguration.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.DL.Configurations +{ + public class UserTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Users"); + builder.HasKey(e => e.Id); + builder.Property(e => e.Id).ValueGeneratedOnAdd(); + } + + } +} diff --git a/src/WorkFlowCheck.DL/Entities/User.cs b/src/WorkFlowCheck.DL/Entities/User.cs index 6092e0a..84e7853 100644 --- a/src/WorkFlowCheck.DL/Entities/User.cs +++ b/src/WorkFlowCheck.DL/Entities/User.cs @@ -1,9 +1,12 @@ -namespace WorkFlowCheck.DL.Entities +using System.ComponentModel.DataAnnotations.Schema; + +namespace WorkFlowCheck.DL.Entities { public class User { public int Id { get; set; } - public string Name { get; set; } = null!; public string Email { get; set; } = null!; + public string FirstName { get; set; } = null!; + public string LastName { get; set; } = null!; } }