From ba7ac3692000e96e681169e8e8745ea52db82340 Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 16:25:43 +0500 Subject: [PATCH 01/49] start core project rename project to API --- SurveyBackend/SurveyBackend.API/Program.cs | 31 +++++++++++ .../Properties/launchSettings.json | 0 .../SurveyBackend.API.csproj} | 1 + .../SurveyBackend.http | 0 .../appsettings.Development.json | 0 .../appsettings.json | 0 .../SurveyBackend.Core/Models/User.cs | 11 ++++ .../SurveyBackend.Core.csproj | 9 ++++ SurveyBackend/SurveyBackend.sln | 8 ++- SurveyBackend/SurveyBackend/Program.cs | 51 ------------------- .../SurveyBackend/WeatherForecast.cs | 12 ----- 11 files changed, 59 insertions(+), 64 deletions(-) create mode 100644 SurveyBackend/SurveyBackend.API/Program.cs rename SurveyBackend/{SurveyBackend => SurveyBackend.API}/Properties/launchSettings.json (100%) rename SurveyBackend/{SurveyBackend/SurveyBackend.csproj => SurveyBackend.API/SurveyBackend.API.csproj} (88%) rename SurveyBackend/{SurveyBackend => SurveyBackend.API}/SurveyBackend.http (100%) rename SurveyBackend/{SurveyBackend => SurveyBackend.API}/appsettings.Development.json (100%) rename SurveyBackend/{SurveyBackend => SurveyBackend.API}/appsettings.json (100%) create mode 100644 SurveyBackend/SurveyBackend.Core/Models/User.cs create mode 100644 SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj delete mode 100644 SurveyBackend/SurveyBackend/Program.cs delete mode 100644 SurveyBackend/SurveyBackend/WeatherForecast.cs diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs new file mode 100644 index 0000000..3a98e82 --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -0,0 +1,31 @@ +namespace SurveyBackend; + +public class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + builder.Services.AddAuthorization(); + + // 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.Run(); + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend/Properties/launchSettings.json b/SurveyBackend/SurveyBackend.API/Properties/launchSettings.json similarity index 100% rename from SurveyBackend/SurveyBackend/Properties/launchSettings.json rename to SurveyBackend/SurveyBackend.API/Properties/launchSettings.json diff --git a/SurveyBackend/SurveyBackend/SurveyBackend.csproj b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj similarity index 88% rename from SurveyBackend/SurveyBackend/SurveyBackend.csproj rename to SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj index 1060e38..41529c3 100644 --- a/SurveyBackend/SurveyBackend/SurveyBackend.csproj +++ b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + SurveyBackend diff --git a/SurveyBackend/SurveyBackend/SurveyBackend.http b/SurveyBackend/SurveyBackend.API/SurveyBackend.http similarity index 100% rename from SurveyBackend/SurveyBackend/SurveyBackend.http rename to SurveyBackend/SurveyBackend.API/SurveyBackend.http diff --git a/SurveyBackend/SurveyBackend/appsettings.Development.json b/SurveyBackend/SurveyBackend.API/appsettings.Development.json similarity index 100% rename from SurveyBackend/SurveyBackend/appsettings.Development.json rename to SurveyBackend/SurveyBackend.API/appsettings.Development.json diff --git a/SurveyBackend/SurveyBackend/appsettings.json b/SurveyBackend/SurveyBackend.API/appsettings.json similarity index 100% rename from SurveyBackend/SurveyBackend/appsettings.json rename to SurveyBackend/SurveyBackend.API/appsettings.json diff --git a/SurveyBackend/SurveyBackend.Core/Models/User.cs b/SurveyBackend/SurveyBackend.Core/Models/User.cs new file mode 100644 index 0000000..509c503 --- /dev/null +++ b/SurveyBackend/SurveyBackend.Core/Models/User.cs @@ -0,0 +1,11 @@ +namespace SurveyBackend.Core.Models; + +public class User +{ + public int Id { get; set; } + public string Username { get; set; } + public string Email { get; set; } + + public byte[] PasswordHash { get; set; } + public byte[] PasswordSalt { get; set; } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/SurveyBackend/SurveyBackend.sln b/SurveyBackend/SurveyBackend.sln index b7d1a9a..a7701f0 100644 --- a/SurveyBackend/SurveyBackend.sln +++ b/SurveyBackend/SurveyBackend.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend", "SurveyBackend\SurveyBackend.csproj", "{2941E98A-5311-4B97-B8B0-8DBF5E1C3B56}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.API", "SurveyBackend.API\SurveyBackend.API.csproj", "{2941E98A-5311-4B97-B8B0-8DBF5E1C3B56}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Core", "SurveyBackend.Core\SurveyBackend.Core.csproj", "{596B4603-4066-4FF2-9C96-5357193F7229}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -12,5 +14,9 @@ Global {2941E98A-5311-4B97-B8B0-8DBF5E1C3B56}.Debug|Any CPU.Build.0 = Debug|Any CPU {2941E98A-5311-4B97-B8B0-8DBF5E1C3B56}.Release|Any CPU.ActiveCfg = Release|Any CPU {2941E98A-5311-4B97-B8B0-8DBF5E1C3B56}.Release|Any CPU.Build.0 = Release|Any CPU + {596B4603-4066-4FF2-9C96-5357193F7229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {596B4603-4066-4FF2-9C96-5357193F7229}.Debug|Any CPU.Build.0 = Debug|Any CPU + {596B4603-4066-4FF2-9C96-5357193F7229}.Release|Any CPU.ActiveCfg = Release|Any CPU + {596B4603-4066-4FF2-9C96-5357193F7229}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/SurveyBackend/SurveyBackend/Program.cs b/SurveyBackend/SurveyBackend/Program.cs deleted file mode 100644 index 5a9ed2b..0000000 --- a/SurveyBackend/SurveyBackend/Program.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace SurveyBackend; - -public class Program -{ - public static void Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); - - // Add services to the container. - builder.Services.AddAuthorization(); - - // 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(); - - var summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - app.MapGet("/weatherforecast", (HttpContext httpContext) => - { - var forecast = 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(); - return forecast; - }) - .WithName("GetWeatherForecast") - .WithOpenApi(); - - app.Run(); - } -} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend/WeatherForecast.cs b/SurveyBackend/SurveyBackend/WeatherForecast.cs deleted file mode 100644 index 75b15b6..0000000 --- a/SurveyBackend/SurveyBackend/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace SurveyBackend; - -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; } -} \ No newline at end of file From 751b08e805043ae7caa4945099ad8e279ff145cb Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 19:42:06 +0500 Subject: [PATCH 02/49] added Infrastructure --- SurveyBackend/SurveyBackend.Core/Models/Group.cs | 9 +++++++++ SurveyBackend/SurveyBackend.Core/Models/User.cs | 4 +++- .../SurveyBackend.Infrastructure.csproj | 9 +++++++++ SurveyBackend/SurveyBackend.sln | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 SurveyBackend/SurveyBackend.Core/Models/Group.cs create mode 100644 SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj diff --git a/SurveyBackend/SurveyBackend.Core/Models/Group.cs b/SurveyBackend/SurveyBackend.Core/Models/Group.cs new file mode 100644 index 0000000..e74cb3f --- /dev/null +++ b/SurveyBackend/SurveyBackend.Core/Models/Group.cs @@ -0,0 +1,9 @@ +namespace SurveyBackend.Core.Models; + +public class Group +{ + public int Id { get; set; } + public string Label { get; set; } + + public ICollection Users { get; set; } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/Models/User.cs b/SurveyBackend/SurveyBackend.Core/Models/User.cs index 509c503..fd8e2fd 100644 --- a/SurveyBackend/SurveyBackend.Core/Models/User.cs +++ b/SurveyBackend/SurveyBackend.Core/Models/User.cs @@ -6,6 +6,8 @@ public class User public string Username { get; set; } public string Email { get; set; } - public byte[] PasswordHash { get; set; } public byte[] PasswordSalt { get; set; } + public byte[] PasswordHash { get; set; } + + public ICollection Groups { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/SurveyBackend/SurveyBackend.sln b/SurveyBackend/SurveyBackend.sln index a7701f0..c79d7d1 100644 --- a/SurveyBackend/SurveyBackend.sln +++ b/SurveyBackend/SurveyBackend.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.API", "Survey EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Core", "SurveyBackend.Core\SurveyBackend.Core.csproj", "{596B4603-4066-4FF2-9C96-5357193F7229}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Infrastructure", "SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj", "{4006471D-9F65-4AD6-852B-88A1211B49F4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {596B4603-4066-4FF2-9C96-5357193F7229}.Debug|Any CPU.Build.0 = Debug|Any CPU {596B4603-4066-4FF2-9C96-5357193F7229}.Release|Any CPU.ActiveCfg = Release|Any CPU {596B4603-4066-4FF2-9C96-5357193F7229}.Release|Any CPU.Build.0 = Release|Any CPU + {4006471D-9F65-4AD6-852B-88A1211B49F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4006471D-9F65-4AD6-852B-88A1211B49F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4006471D-9F65-4AD6-852B-88A1211B49F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4006471D-9F65-4AD6-852B-88A1211B49F4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From 6732613466845a426528c8aaf71b3828cdedfa81 Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 22:05:28 +0500 Subject: [PATCH 03/49] idk something about efcore --- .../SurveyBackend.API/DTOs/UserLoginDTO.cs | 7 +++ .../DTOs/UserRegistrationDTO.cs | 10 +++++ .../SurveyBackend.Core/Models/User.cs | 2 + .../Repositories/IGenericRepository.cs | 10 +++++ .../Repositories/IUserRepository.cs | 7 +++ .../Data/DataContext.cs | 15 +++++++ .../Repositories/UserRepository.cs | 44 +++++++++++++++++++ .../SurveyBackend.Infrastructure.csproj | 8 ++++ 8 files changed, 103 insertions(+) create mode 100644 SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs create mode 100644 SurveyBackend/SurveyBackend.API/DTOs/UserRegistrationDTO.cs create mode 100644 SurveyBackend/SurveyBackend.Core/Repositories/IGenericRepository.cs create mode 100644 SurveyBackend/SurveyBackend.Core/Repositories/IUserRepository.cs create mode 100644 SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs create mode 100644 SurveyBackend/SurveyBackend.Infrastructure/Repositories/UserRepository.cs diff --git a/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs new file mode 100644 index 0000000..a6125a7 --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs @@ -0,0 +1,7 @@ +namespace SurveyBackend.DTOs; + +public record UserLoginDTO +{ + public string Email { get; set; } + public string Password { get; set; } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/UserRegistrationDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/UserRegistrationDTO.cs new file mode 100644 index 0000000..b3013db --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/DTOs/UserRegistrationDTO.cs @@ -0,0 +1,10 @@ +namespace SurveyBackend.DTOs; + +public record UserRegistrationDTO +{ + public string Email { get; set; } + public string Username { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Password { get; set; } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/Models/User.cs b/SurveyBackend/SurveyBackend.Core/Models/User.cs index fd8e2fd..0f57f37 100644 --- a/SurveyBackend/SurveyBackend.Core/Models/User.cs +++ b/SurveyBackend/SurveyBackend.Core/Models/User.cs @@ -3,6 +3,8 @@ namespace SurveyBackend.Core.Models; public class User { public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } public string Username { get; set; } public string Email { get; set; } diff --git a/SurveyBackend/SurveyBackend.Core/Repositories/IGenericRepository.cs b/SurveyBackend/SurveyBackend.Core/Repositories/IGenericRepository.cs new file mode 100644 index 0000000..228d3b1 --- /dev/null +++ b/SurveyBackend/SurveyBackend.Core/Repositories/IGenericRepository.cs @@ -0,0 +1,10 @@ +namespace SurveyBackend.Core.Repositories; + +public interface IGenericRepository where T : class +{ + Task GetByIdAsync(int id); + Task> GetAllAsync(); + Task AddAsync(T entity); + Task UpdateAsync(T entity); + Task DeleteAsync(T entity); +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/Repositories/IUserRepository.cs b/SurveyBackend/SurveyBackend.Core/Repositories/IUserRepository.cs new file mode 100644 index 0000000..791059a --- /dev/null +++ b/SurveyBackend/SurveyBackend.Core/Repositories/IUserRepository.cs @@ -0,0 +1,7 @@ +using SurveyBackend.Core.Models; + +namespace SurveyBackend.Core.Repositories; + +public interface IUserRepository : IGenericRepository +{ +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs new file mode 100644 index 0000000..26cabc9 --- /dev/null +++ b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using SurveyBackend.Core.Models; + +namespace SurveyBackend.Infrastructure.Data; + +public class DataContext : DbContext +{ + public DbSet Users { get; set; } + public DbSet Groups { get; set; } + + public DataContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Infrastructure/Repositories/UserRepository.cs b/SurveyBackend/SurveyBackend.Infrastructure/Repositories/UserRepository.cs new file mode 100644 index 0000000..306872e --- /dev/null +++ b/SurveyBackend/SurveyBackend.Infrastructure/Repositories/UserRepository.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using SurveyBackend.Core.Models; +using SurveyBackend.Core.Repositories; +using SurveyBackend.Infrastructure.Data; + +namespace SurveyBackend.Infrastructure.Repositories; + +public class UserRepository : IUserRepository +{ + private readonly DataContext _context; + + public UserRepository(DataContext context) + { + _context = context; + } + + public async Task GetByIdAsync(int id) + { + return await _context.Users.FindAsync(id); + } + + public async Task> GetAllAsync() + { + return await _context.Users.ToListAsync(); + } + + public async Task AddAsync(User entity) + { + await _context.Users.AddAsync(entity); + await _context.SaveChangesAsync(); + } + + public async Task UpdateAsync(User entity) + { + _context.Users.Update(entity); + await _context.SaveChangesAsync(); + } + + public async Task DeleteAsync(User entity) + { + _context.Users.Remove(entity); + await _context.SaveChangesAsync(); + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj index 3a63532..eeefcab 100644 --- a/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj +++ b/SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + From f9a680c554b61b549900942e2b6e0f1bfe8fa7db Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 22:22:57 +0500 Subject: [PATCH 04/49] started api work --- .../Controllers/AuthController.cs | 15 +++++++++++++++ .../SurveyBackend.API/DTOs/UserLoginDTO.cs | 4 ++-- SurveyBackend/SurveyBackend.API/Program.cs | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs diff --git a/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs b/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs new file mode 100644 index 0000000..94f1cb4 --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; +using SurveyBackend.DTOs; + +namespace SurveyBackend.Controllers; + +[ApiController] +[Route("[controller]")] +public class AuthController : ControllerBase +{ + [HttpPost("login")] + public async Task GetToken([FromBody] UserLoginDTO loginData) + { + return Ok(); + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs index a6125a7..9dc2510 100644 --- a/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs +++ b/SurveyBackend/SurveyBackend.API/DTOs/UserLoginDTO.cs @@ -2,6 +2,6 @@ namespace SurveyBackend.DTOs; public record UserLoginDTO { - public string Email { get; set; } - public string Password { get; set; } + public required string Email { get; set; } + public required string Password { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index 3a98e82..e7d098c 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -8,6 +8,8 @@ public class Program // Add services to the container. builder.Services.AddAuthorization(); + + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -22,10 +24,10 @@ public class Program app.UseSwaggerUI(); } - app.UseHttpsRedirection(); - app.UseAuthorization(); + app.MapControllers(); + app.Run(); } } \ No newline at end of file From 950babb68c09ea1cc49691d6c794b6437b646c41 Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 22:28:55 +0500 Subject: [PATCH 05/49] Kontur developer assaulted me about using [controller] in route --- SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs b/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs index 94f1cb4..b0b0442 100644 --- a/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs +++ b/SurveyBackend/SurveyBackend.API/Controllers/AuthController.cs @@ -4,7 +4,7 @@ using SurveyBackend.DTOs; namespace SurveyBackend.Controllers; [ApiController] -[Route("[controller]")] +[Route("auth")] public class AuthController : ControllerBase { [HttpPost("login")] From 35331a87f172f786d08b504da8de9e8773ec352e Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 25 Mar 2025 22:56:35 +0500 Subject: [PATCH 06/49] i'm not sure what i'm doing --- SurveyBackend/SurveyBackend.API/Program.cs | 20 ++++++++++++++++--- .../SurveyBackend.API.csproj | 6 ++++++ .../appsettings.Development.json | 3 +++ .../SurveyBackend.API/appsettings.json | 5 ++++- .../SurveyBackend.Core/Models/User.cs | 10 +++------- .../SurveyBackend.Core.csproj | 5 +++++ .../Data/DataContext.cs | 5 +++-- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index e7d098c..8aa2aca 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using SurveyBackend.Core.Models; +using SurveyBackend.Infrastructure.Data; + namespace SurveyBackend; public class Program @@ -8,7 +13,16 @@ public class Program // Add services to the container. builder.Services.AddAuthorization(); - + + builder.Services.AddDbContext(options => + { + options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")); + }); + + builder.Services.AddIdentity>(options => { }) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -25,9 +39,9 @@ public class Program } app.UseAuthorization(); - + app.MapControllers(); - + app.Run(); } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj index 41529c3..e11596b 100644 --- a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj +++ b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj @@ -9,7 +9,13 @@ + + + + + + diff --git a/SurveyBackend/SurveyBackend.API/appsettings.Development.json b/SurveyBackend/SurveyBackend.API/appsettings.Development.json index 0c208ae..c14bf00 100644 --- a/SurveyBackend/SurveyBackend.API/appsettings.Development.json +++ b/SurveyBackend/SurveyBackend.API/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "DefaultConnection": "Data Source=Application.db" } } diff --git a/SurveyBackend/SurveyBackend.API/appsettings.json b/SurveyBackend/SurveyBackend.API/appsettings.json index 10f68b8..19a74e6 100644 --- a/SurveyBackend/SurveyBackend.API/appsettings.json +++ b/SurveyBackend/SurveyBackend.API/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Data Source=Application.db" + } } diff --git a/SurveyBackend/SurveyBackend.Core/Models/User.cs b/SurveyBackend/SurveyBackend.Core/Models/User.cs index 0f57f37..ab4dcbe 100644 --- a/SurveyBackend/SurveyBackend.Core/Models/User.cs +++ b/SurveyBackend/SurveyBackend.Core/Models/User.cs @@ -1,15 +1,11 @@ +using Microsoft.AspNetCore.Identity; + namespace SurveyBackend.Core.Models; -public class User +public class User : IdentityUser { - public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } - public string Username { get; set; } - public string Email { get; set; } - - public byte[] PasswordSalt { get; set; } - public byte[] PasswordHash { get; set; } public ICollection Groups { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj index 3a63532..7bc422a 100644 --- a/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj +++ b/SurveyBackend/SurveyBackend.Core/SurveyBackend.Core.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs index 26cabc9..a44573f 100644 --- a/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs +++ b/SurveyBackend/SurveyBackend.Infrastructure/Data/DataContext.cs @@ -1,11 +1,12 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using SurveyBackend.Core.Models; namespace SurveyBackend.Infrastructure.Data; -public class DataContext : DbContext +public class DataContext : IdentityDbContext, int> { - public DbSet Users { get; set; } public DbSet Groups { get; set; } public DataContext(DbContextOptions options) : base(options) From 009a214b4063d7f145ade4dcda4d247f6368aad6 Mon Sep 17 00:00:00 2001 From: Tatiana Nikolaeva Date: Fri, 4 Apr 2025 21:41:22 +0500 Subject: [PATCH 07/49] components --- SurveyFrontend/public/account.svg | 3 + SurveyFrontend/public/add_circle.svg | 3 + SurveyFrontend/public/logo.svg | 3 + .../src/components/Account/Account.module.css | 9 ++ .../src/components/Account/Account.tsx | 16 ++++ .../AddAnswerButton.module.css | 16 ++++ .../AddAnswerButton/AddAnswerButton.tsx | 17 ++++ .../AddQuestionButton.module.css | 18 ++++ .../AddQuestionButton/AddQuestionButton.tsx | 17 ++++ .../AnswerOption/AnswerOption.module.css | 23 +++++ .../components/AnswerOption/AnswerOption.tsx | 72 +++++++++++++++ .../src/components/Header/Header.module.css | 9 ++ .../src/components/Header/Header.tsx | 28 ++++++ .../src/components/Logo/Logo.module.css | 9 ++ SurveyFrontend/src/components/Logo/Logo.tsx | 16 ++++ .../MainComponent/MainComponent.module.css | 5 ++ .../MainComponent/MainComponent.tsx | 24 +++++ .../Navigation/Navigation.module.css | 12 +++ .../src/components/Navigation/Navigation.tsx | 34 ++++++++ .../NavigationItem/NavigationItem.module.css | 17 ++++ .../NavigationItem/NavigationItem.tsx | 20 +++++ .../PageSurvey/PageSurvey.module.css | 36 ++++++++ .../src/components/PageSurvey/PageSurvey.tsx | 20 +++++ .../QuestionItem/QuestionItem.module.css | 18 ++++ .../components/QuestionItem/QuestionItem.tsx | 66 ++++++++++++++ .../QuestionsList/QuestionsList.module.css | 2 + .../QuestionsList/QuestionsList.tsx | 38 ++++++++ .../SaveButton/SaveButton.module.css | 15 ++++ .../src/components/SaveButton/SaveButton.tsx | 16 ++++ .../src/components/Survey/Survey.module.css | 6 ++ .../src/components/Survey/Survey.tsx | 15 ++++ .../SurveyInfo/SurveyInfo.module.css | 73 ++++++++++++++++ .../src/components/SurveyInfo/SurveyInfo.tsx | 87 +++++++++++++++++++ .../SurveyPagesList.module.css | 7 ++ .../SurveyPagesList/SurveyPagesList.tsx | 27 ++++++ .../TypeDropdown/TypeDropdown.module.css | 69 +++++++++++++++ .../components/TypeDropdown/TypeDropdown.tsx | 87 +++++++++++++++++++ SurveyFrontend/src/pages/Questions.tsx | 13 +++ SurveyFrontend/src/pages/Results.tsx | 0 SurveyFrontend/src/pages/Settings.tsx | 0 40 files changed, 966 insertions(+) create mode 100644 SurveyFrontend/public/account.svg create mode 100644 SurveyFrontend/public/add_circle.svg create mode 100644 SurveyFrontend/public/logo.svg create mode 100644 SurveyFrontend/src/components/Account/Account.module.css create mode 100644 SurveyFrontend/src/components/Account/Account.tsx create mode 100644 SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.module.css create mode 100644 SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.tsx create mode 100644 SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.module.css create mode 100644 SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.tsx create mode 100644 SurveyFrontend/src/components/AnswerOption/AnswerOption.module.css create mode 100644 SurveyFrontend/src/components/AnswerOption/AnswerOption.tsx create mode 100644 SurveyFrontend/src/components/Header/Header.module.css create mode 100644 SurveyFrontend/src/components/Header/Header.tsx create mode 100644 SurveyFrontend/src/components/Logo/Logo.module.css create mode 100644 SurveyFrontend/src/components/Logo/Logo.tsx create mode 100644 SurveyFrontend/src/components/MainComponent/MainComponent.module.css create mode 100644 SurveyFrontend/src/components/MainComponent/MainComponent.tsx create mode 100644 SurveyFrontend/src/components/Navigation/Navigation.module.css create mode 100644 SurveyFrontend/src/components/Navigation/Navigation.tsx create mode 100644 SurveyFrontend/src/components/NavigationItem/NavigationItem.module.css create mode 100644 SurveyFrontend/src/components/NavigationItem/NavigationItem.tsx create mode 100644 SurveyFrontend/src/components/PageSurvey/PageSurvey.module.css create mode 100644 SurveyFrontend/src/components/PageSurvey/PageSurvey.tsx create mode 100644 SurveyFrontend/src/components/QuestionItem/QuestionItem.module.css create mode 100644 SurveyFrontend/src/components/QuestionItem/QuestionItem.tsx create mode 100644 SurveyFrontend/src/components/QuestionsList/QuestionsList.module.css create mode 100644 SurveyFrontend/src/components/QuestionsList/QuestionsList.tsx create mode 100644 SurveyFrontend/src/components/SaveButton/SaveButton.module.css create mode 100644 SurveyFrontend/src/components/SaveButton/SaveButton.tsx create mode 100644 SurveyFrontend/src/components/Survey/Survey.module.css create mode 100644 SurveyFrontend/src/components/Survey/Survey.tsx create mode 100644 SurveyFrontend/src/components/SurveyInfo/SurveyInfo.module.css create mode 100644 SurveyFrontend/src/components/SurveyInfo/SurveyInfo.tsx create mode 100644 SurveyFrontend/src/components/SurveyPagesList/SurveyPagesList.module.css create mode 100644 SurveyFrontend/src/components/SurveyPagesList/SurveyPagesList.tsx create mode 100644 SurveyFrontend/src/components/TypeDropdown/TypeDropdown.module.css create mode 100644 SurveyFrontend/src/components/TypeDropdown/TypeDropdown.tsx create mode 100644 SurveyFrontend/src/pages/Questions.tsx create mode 100644 SurveyFrontend/src/pages/Results.tsx create mode 100644 SurveyFrontend/src/pages/Settings.tsx diff --git a/SurveyFrontend/public/account.svg b/SurveyFrontend/public/account.svg new file mode 100644 index 0000000..031e074 --- /dev/null +++ b/SurveyFrontend/public/account.svg @@ -0,0 +1,3 @@ + + + diff --git a/SurveyFrontend/public/add_circle.svg b/SurveyFrontend/public/add_circle.svg new file mode 100644 index 0000000..35a1a64 --- /dev/null +++ b/SurveyFrontend/public/add_circle.svg @@ -0,0 +1,3 @@ + + + diff --git a/SurveyFrontend/public/logo.svg b/SurveyFrontend/public/logo.svg new file mode 100644 index 0000000..f030325 --- /dev/null +++ b/SurveyFrontend/public/logo.svg @@ -0,0 +1,3 @@ + + + diff --git a/SurveyFrontend/src/components/Account/Account.module.css b/SurveyFrontend/src/components/Account/Account.module.css new file mode 100644 index 0000000..5254866 --- /dev/null +++ b/SurveyFrontend/src/components/Account/Account.module.css @@ -0,0 +1,9 @@ +/*Account.module.css*/ + +.account { + margin: 0; + padding: 0; + width: 52px; + height: 52px; + margin: 31px 39px 25px 0; +} \ No newline at end of file diff --git a/SurveyFrontend/src/components/Account/Account.tsx b/SurveyFrontend/src/components/Account/Account.tsx new file mode 100644 index 0000000..be12c02 --- /dev/null +++ b/SurveyFrontend/src/components/Account/Account.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import styles from './Account.module.css' + +interface AccountProps { + href: string +} + +const Account: React.FC = ({href}) => { + return ( + + Личный кабинет + + ); +}; + +export default Account; \ No newline at end of file diff --git a/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.module.css b/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.module.css new file mode 100644 index 0000000..1f95821 --- /dev/null +++ b/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.module.css @@ -0,0 +1,16 @@ +/*AddAnswerButton.module.css*/ + +.answerButton { + display: flex; + gap: 10px; + align-items: center; + border: none; + background-color: white; + color: #3788D6; + font-size: 18px; + font-weight: 500; +} + +.addAnswerImg{ + vertical-align: middle; +} \ No newline at end of file diff --git a/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.tsx b/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.tsx new file mode 100644 index 0000000..7bb3b30 --- /dev/null +++ b/SurveyFrontend/src/components/AddAnswerButton/AddAnswerButton.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import styles from './AddAnswerButton.module.css' + +interface AddAnswerButtonProps { + onClick(): void; +} + +const AddAnswerButton: React.FC = ({onClick}) => { + return ( + + ); +}; + +export default AddAnswerButton; \ No newline at end of file diff --git a/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.module.css b/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.module.css new file mode 100644 index 0000000..642abe1 --- /dev/null +++ b/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.module.css @@ -0,0 +1,18 @@ +/*AddQuestionButton.module.css*/ + +.questionButton{ + background-color: #F6F6F6; + font-size: 24px; + font-weight: 600; + border: none; + margin: 104px auto 80px; + display: flex; + flex-direction: column; +} + +.questionButtonImg{ + vertical-align: middle; + margin: 0 auto; + margin-bottom: 16px; + width: 54px; +} \ No newline at end of file diff --git a/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.tsx b/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.tsx new file mode 100644 index 0000000..9d71446 --- /dev/null +++ b/SurveyFrontend/src/components/AddQuestionButton/AddQuestionButton.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import styles from './AddQuestionButton.module.css' + +interface AddQuestionButtonProps { + onClick: () => void; +} + +const AddQuestionButton: React.FC = ({onClick}) => { + return ( + + ); +}; + +export default AddQuestionButton; \ No newline at end of file diff --git a/SurveyFrontend/src/components/AnswerOption/AnswerOption.module.css b/SurveyFrontend/src/components/AnswerOption/AnswerOption.module.css new file mode 100644 index 0000000..b4ca193 --- /dev/null +++ b/SurveyFrontend/src/components/AnswerOption/AnswerOption.module.css @@ -0,0 +1,23 @@ +/*AnswerOption.module.css*/ + +.answer{ + display: flex; + gap: 10px; + margin-bottom: 17px; +} + +.textAnswer{ + font-size: 18px; + font-weight: 500; + align-items: center; +} + +.answerIcon{ + vertical-align: middle; +} + +.answerInput{ + outline: none; + border: none; + resize: none; +} \ No newline at end of file diff --git a/SurveyFrontend/src/components/AnswerOption/AnswerOption.tsx b/SurveyFrontend/src/components/AnswerOption/AnswerOption.tsx new file mode 100644 index 0000000..944d187 --- /dev/null +++ b/SurveyFrontend/src/components/AnswerOption/AnswerOption.tsx @@ -0,0 +1,72 @@ +import React, {useState, useRef, useEffect} from "react"; +import styles from'./AnswerOption.module.css'; + +interface AnswerOptionProps{ + src: string; + index: number; + value: string; + onChange: (value: string) => void; +} + +const AnswerOption: React.FC = ({src, index, value, onChange}) => { + const [currentValue, setCurrentValue] = useState(value); + const [isEditing, setIsEditing] = useState(false); //редактируется ли сейчас + + const textAreaRef = useRef(null); + + useEffect(() => { + setCurrentValue(value); + }, [value]); + + const handleSpanClick = () => { + setIsEditing(true); + } + + const handleTextareaChange = (event: React.ChangeEvent) => { + setCurrentValue(event.target.value); + }; + + const handleSave = () => { + setIsEditing(false); + onChange(currentValue); // Отправляем измененное значение родителю + }; + + const handleKeyDown = (event: React.KeyboardEvent) => { + if (event.key === "Enter") { + event.preventDefault(); // Предотвращаем перенос строки в textarea + handleSave(); + } + }; + + const handleBlur = () => { + handleSave(); + }; + + useEffect(() => { + if (isEditing && textAreaRef.current) { + textAreaRef.current.focus(); + } + }, [isEditing]); + + return ( +
+ + {isEditing ? ( +