diff --git a/Exam.StockManagement.API/Controllers/CategoryController.cs b/Exam.StockManagement.API/Controllers/CategoryController.cs index 8e3e3fb..f9f789c 100644 --- a/Exam.StockManagement.API/Controllers/CategoryController.cs +++ b/Exam.StockManagement.API/Controllers/CategoryController.cs @@ -1,9 +1,11 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Exam.StockManagement.API.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class CategoryController : ControllerBase { [HttpPost] diff --git a/Exam.StockManagement.API/Controllers/Identity/AuthController.cs b/Exam.StockManagement.API/Controllers/Identity/AuthController.cs index 45aa332..39d1c59 100644 --- a/Exam.StockManagement.API/Controllers/Identity/AuthController.cs +++ b/Exam.StockManagement.API/Controllers/Identity/AuthController.cs @@ -1,25 +1,54 @@ using Exam.StockManagement.Application.Abstractions.IServices; using Exam.StockManagement.Domain.Entities.DTOs; +using Exam.StockManagement.Domain.Exceptions; using Microsoft.AspNetCore.Mvc; namespace Exam.StockManagement.API.Controllers.Identity { - [Route("api/[controller]")] + [Route("api/[controller]/[action]")] [ApiController] public class AuthController : ControllerBase { + private readonly IEmailSenderService _emailSenderService; private readonly IAuthService _authService; + private readonly IWebHostEnvironment _webHostEnvironment; - public AuthController(IAuthService authService) + + public AuthController(IAuthService authService, + IEmailSenderService emailSenderService, + IWebHostEnvironment webHostEnvironment) { + _emailSenderService = emailSenderService; _authService = authService; + _webHostEnvironment = webHostEnvironment; + } + + [HttpPost] + public async Task SignUp(RequestSignUp model) + { + var result = await _authService.RegisterUser(model); + return Ok(result); } [HttpPost] - public async Task> Login(RequestLogin model) + public async Task Login(RequestLogin model) { - var result = await _authService.GenerateToken(model); + var result = await _authService.UserExist(model); + if (result) + { + string path = Path.Combine(_webHostEnvironment.WebRootPath, "code.txt"); + await _emailSenderService.SendEmailAsync(model.Email, path); + return Ok(result); + } + throw new NotFoundException(); + } + + [HttpPost] + public async Task AcceptUser(CheckEmail model) + { + string path = Path.Combine(_webHostEnvironment.WebRootPath, "code.txt"); + var result = await _authService.GenerateToken(model, path); return Ok(result.Token); } } diff --git a/Exam.StockManagement.API/Controllers/ProductController.cs b/Exam.StockManagement.API/Controllers/ProductController.cs index 181e704..1069da7 100644 --- a/Exam.StockManagement.API/Controllers/ProductController.cs +++ b/Exam.StockManagement.API/Controllers/ProductController.cs @@ -1,9 +1,11 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Exam.StockManagement.API.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class ProductController : ControllerBase { [HttpPost] diff --git a/Exam.StockManagement.API/Controllers/StatsController.cs b/Exam.StockManagement.API/Controllers/StatsController.cs index 0d4f3f9..5fa446b 100644 --- a/Exam.StockManagement.API/Controllers/StatsController.cs +++ b/Exam.StockManagement.API/Controllers/StatsController.cs @@ -1,9 +1,11 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; namespace Exam.StockManagement.API.Controllers { [Route("api/[controller]/[action]")] [ApiController] + [Authorize] public class StatsController : ControllerBase { [HttpPost] diff --git a/Exam.StockManagement.API/Controllers/UsersController.cs b/Exam.StockManagement.API/Controllers/UsersController.cs index 16e836a..736ce04 100644 --- a/Exam.StockManagement.API/Controllers/UsersController.cs +++ b/Exam.StockManagement.API/Controllers/UsersController.cs @@ -1,6 +1,4 @@ using Exam.StockManagement.Application.Abstractions.IServices; -using Exam.StockManagement.Domain.Entities.DTOs; -using Exam.StockManagement.Domain.Entities.Models; using Exam.StockManagement.Domain.Entities.ViewModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -9,7 +7,6 @@ namespace Exam.StockManagement.API.Controllers { [Route("api/[controller]/[action]")] [ApiController] - [Authorize] public class UsersController : ControllerBase { private readonly IUserService _userService; @@ -20,19 +17,12 @@ public UsersController(IUserService userService) } [HttpGet] + [Authorize] public async Task>> GetAllUsers() { var result = await _userService.GetAll(); return Ok(result); } - - [HttpPost] - public async Task>> CreateUser(UserDTO model) - { - var result = await _userService.Create(model); - - return Ok(result); - } } } diff --git a/Exam.StockManagement.API/Exam.StockManagement.API.csproj b/Exam.StockManagement.API/Exam.StockManagement.API.csproj index c691a2f..0a97238 100644 --- a/Exam.StockManagement.API/Exam.StockManagement.API.csproj +++ b/Exam.StockManagement.API/Exam.StockManagement.API.csproj @@ -22,4 +22,8 @@ + + + + diff --git a/Exam.StockManagement.API/appsettings.json b/Exam.StockManagement.API/appsettings.json index ded133b..10ddd98 100644 --- a/Exam.StockManagement.API/appsettings.json +++ b/Exam.StockManagement.API/appsettings.json @@ -14,5 +14,12 @@ "ValidIssuer": "127.0.0.1", "Secret": "TohirjonOdilovImtihonUchunTayyorlaganSecretKey03.02.2024", "ExpireDate": "1000" + }, + "EmailSettings": { + "MailServer": "smtp.gmail.com", + "MailPort": 587, + "SenderName": "Najot Ta'lim", + "Sender": "awscloud223@gmail.com", + "Password": "wcyz cueo vuiv tcku" } } diff --git a/Exam.StockManagement.API/wwwroot/code.txt b/Exam.StockManagement.API/wwwroot/code.txt new file mode 100644 index 0000000..4e11b0f --- /dev/null +++ b/Exam.StockManagement.API/wwwroot/code.txt @@ -0,0 +1 @@ +9430 \ No newline at end of file diff --git a/Exam.StockManagement.Application/Abstractions/IServices/IAuthService.cs b/Exam.StockManagement.Application/Abstractions/IServices/IAuthService.cs index e109657..46e07f3 100644 --- a/Exam.StockManagement.Application/Abstractions/IServices/IAuthService.cs +++ b/Exam.StockManagement.Application/Abstractions/IServices/IAuthService.cs @@ -1,9 +1,13 @@ using Exam.StockManagement.Domain.Entities.DTOs; +using Exam.StockManagement.Domain.Entities.Models; namespace Exam.StockManagement.Application.Abstractions.IServices { public interface IAuthService { public Task GenerateToken(RequestLogin user); + public Task UserExist(RequestLogin user); + public Task CorrectEmail(RegisterLogin user); + public Task RegisterUser(RequestSignUp signUp); } } diff --git a/Exam.StockManagement.Application/Abstractions/IServices/IProductService.cs b/Exam.StockManagement.Application/Abstractions/IServices/IProductService.cs index fe0ce45..0084db4 100644 --- a/Exam.StockManagement.Application/Abstractions/IServices/IProductService.cs +++ b/Exam.StockManagement.Application/Abstractions/IServices/IProductService.cs @@ -1,6 +1,10 @@ +using Exam.StockManagement.Domain.Entities.DTOs; +using Exam.StockManagement.Domain.Entities.Models; +using Exam.StockManagement.Domain.Entities.ViewModels; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; @@ -8,5 +12,13 @@ namespace Exam.StockManagement.Application.Abstractions.IServices { public interface IProductService { + public Task Create(ProductDTO userDTO); + public Task GetByName(string name); + public Task GetById(int Id); + public Task GetByEmail(string email); + public Task GetByLogin(string email); + public Task> GetAll(); + public Task Delete(Expression> expression); + public Task Update(int Id, ProductDTO userDTO); } } diff --git a/Exam.StockManagement.Application/Abstractions/IServices/IUserService.cs b/Exam.StockManagement.Application/Abstractions/IServices/IUserService.cs index e82cdca..932f50b 100644 --- a/Exam.StockManagement.Application/Abstractions/IServices/IUserService.cs +++ b/Exam.StockManagement.Application/Abstractions/IServices/IUserService.cs @@ -7,7 +7,7 @@ namespace Exam.StockManagement.Application.Abstractions.IServices { public interface IUserService { - public Task Create(UserDTO userDTO); + public Task Create(RequestSignUp signUp); public Task GetByName(string name); public Task GetById(int Id); public Task GetByEmail(string email); diff --git a/Exam.StockManagement.Application/Services/AuthServices/AuthService.cs b/Exam.StockManagement.Application/Services/AuthServices/AuthService.cs index 399cc54..629d5eb 100644 --- a/Exam.StockManagement.Application/Services/AuthServices/AuthService.cs +++ b/Exam.StockManagement.Application/Services/AuthServices/AuthService.cs @@ -1,5 +1,7 @@ using Exam.StockManagement.Application.Abstractions.IServices; using Exam.StockManagement.Domain.Entities.DTOs; +using Exam.StockManagement.Domain.Entities.Models; +using Exam.StockManagement.Domain.Exceptions; using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; using System.Globalization; @@ -20,14 +22,21 @@ public AuthService(IConfiguration conf, IUserService userService) _userService = userService; } + public async Task CorrectEmail(RegisterLogin user) + { + var result = await _userService.GetByLogin(user.Login); + if (result.Code == user.Code) + { + return "Login successfully!"; + } + throw new NotFoundException(); + } + public async Task GenerateToken(RequestLogin user) { if (user == null) { - return new ResponseLogin() - { - Token = "User Not Found" - }; + throw new NotFoundException(); } if (await UserExist(user)) @@ -83,9 +92,12 @@ public async Task GenerateToken(IEnumerable additionalClai } - public async Task UserExist(RequestLogin user) { + if (user == null) + { + throw new NotFoundException(); + } var result = await _userService.GetByLogin(user.Login); @@ -93,8 +105,13 @@ public async Task UserExist(RequestLogin user) { return true; } - return false; } + + public async Task RegisterUser(RequestSignUp signUp) + { + var result = await _userService.Create(signUp); + return result; + } } } diff --git a/Exam.StockManagement.Application/Services/UserService.cs b/Exam.StockManagement.Application/Services/UserService.cs index c053bce..2342961 100644 --- a/Exam.StockManagement.Application/Services/UserService.cs +++ b/Exam.StockManagement.Application/Services/UserService.cs @@ -17,10 +17,15 @@ public UserService(IUserRepository userRepository) _userRepository = userRepository; } - public async Task Create(UserDTO userDTO) + public async Task Create(RequestSignUp requestSignUp) { - User? hasLogin = await _userRepository.GetByAny(x => x.Login == userDTO.Login); - var hasEmail = await _userRepository.GetByAny(x => x.Email == userDTO.Email); + User? hasLogin = await _userRepository.GetByAny(x => x.Login == requestSignUp.Login); + var hasEmail = await _userRepository.GetByAny(x => x.Email == requestSignUp.Email); + + if (requestSignUp.Password != requestSignUp.ConfirmPassword) + { + throw new PasswordNotMatchException(); + } if (hasLogin != null && hasEmail != null) { @@ -29,11 +34,12 @@ public async Task Create(UserDTO userDTO) User? user = new User() { - Name = userDTO.Name, - Email = userDTO.Email, - Login = userDTO.Login, - Password = userDTO.Password, - Role = userDTO.Role, + Name = requestSignUp.Name, + Email = requestSignUp.Email, + Login = requestSignUp.Login, + Password = requestSignUp.Password, + Role = requestSignUp.Role + }; User? result = await _userRepository.Create(user); diff --git a/Exam.StockManagement.Domain/Entities/Common/Auditable.cs b/Exam.StockManagement.Domain/Entities/Common/Auditable.cs index 1662c63..335df53 100644 --- a/Exam.StockManagement.Domain/Entities/Common/Auditable.cs +++ b/Exam.StockManagement.Domain/Entities/Common/Auditable.cs @@ -2,7 +2,7 @@ namespace Exam.StockManagement.Domain.Entities.Common { public abstract class Auditable : BaseEntity { - public DateTime CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; } } diff --git a/Exam.StockManagement.Domain/Entities/DTOs/RegisterLogin.cs b/Exam.StockManagement.Domain/Entities/DTOs/RegisterLogin.cs index 75ecb44..f26844b 100644 --- a/Exam.StockManagement.Domain/Entities/DTOs/RegisterLogin.cs +++ b/Exam.StockManagement.Domain/Entities/DTOs/RegisterLogin.cs @@ -2,10 +2,7 @@ { public class RegisterLogin { - public string? Name { get; set; } - public string? Email { get; set; } - public string Login { get; set; } - public string Password { get; set; } - public string ConiformPassword { get; set; } + public string? Login { get; set; } + public string? Code { get; set; } } } diff --git a/Exam.StockManagement.Domain/Entities/DTOs/RequestLogin.cs b/Exam.StockManagement.Domain/Entities/DTOs/RequestLogin.cs index fbe022c..d3d2547 100644 --- a/Exam.StockManagement.Domain/Entities/DTOs/RequestLogin.cs +++ b/Exam.StockManagement.Domain/Entities/DTOs/RequestLogin.cs @@ -5,4 +5,4 @@ public class RequestLogin public string Login { get; set; } public string Password { get; set; } } -} +} \ No newline at end of file diff --git a/Exam.StockManagement.Domain/Entities/DTOs/RequestSignUp.cs b/Exam.StockManagement.Domain/Entities/DTOs/RequestSignUp.cs new file mode 100644 index 0000000..5a3aadc --- /dev/null +++ b/Exam.StockManagement.Domain/Entities/DTOs/RequestSignUp.cs @@ -0,0 +1,12 @@ +namespace Exam.StockManagement.Domain.Entities.DTOs +{ + public class RequestSignUp + { + public string? Name { get; set; } + public string? Email { get; set; } + public string Login { get; set; } + public string Password { get; set; } + public string ConfirmPassword { get; set; } + public string Role { get; set; } + } +} diff --git a/Exam.StockManagement.Domain/Entities/DTOs/UserDTO.cs b/Exam.StockManagement.Domain/Entities/DTOs/UserDTO.cs index 0037ad3..5072432 100644 --- a/Exam.StockManagement.Domain/Entities/DTOs/UserDTO.cs +++ b/Exam.StockManagement.Domain/Entities/DTOs/UserDTO.cs @@ -4,8 +4,8 @@ public class UserDTO { public string? Name { get; set; } public string? Email { get; set; } - public string Password { get; set; } public string Login { get; set; } + public string Password { get; set; } public string Role { get; set; } } } diff --git a/Exam.StockManagement.Domain/Entities/Models/User.cs b/Exam.StockManagement.Domain/Entities/Models/User.cs index 8537b30..62c565d 100644 --- a/Exam.StockManagement.Domain/Entities/Models/User.cs +++ b/Exam.StockManagement.Domain/Entities/Models/User.cs @@ -8,7 +8,7 @@ public class User : Auditable public string? Email { get; set; } public string Login { get; set; } public string Password { get; set; } - public string Role { get; set; } - // salom + public string? Code { get; set; } + public string? Role { get; set; } } } diff --git a/Exam.StockManagement.Domain/Entities/ViewModels/UserViewModel.cs b/Exam.StockManagement.Domain/Entities/ViewModels/UserViewModel.cs index 020b74a..cb256fd 100644 --- a/Exam.StockManagement.Domain/Entities/ViewModels/UserViewModel.cs +++ b/Exam.StockManagement.Domain/Entities/ViewModels/UserViewModel.cs @@ -5,6 +5,5 @@ public class UserViewModel public string? Name { get; set; } public string? Email { get; set; } public string Role { get; set; } - } } diff --git a/Exam.StockManagement.Domain/Exceptions/NotFoundException.cs b/Exam.StockManagement.Domain/Exceptions/NotFoundException.cs index a788dcd..63884b2 100644 --- a/Exam.StockManagement.Domain/Exceptions/NotFoundException.cs +++ b/Exam.StockManagement.Domain/Exceptions/NotFoundException.cs @@ -1,4 +1,4 @@ namespace Exam.StockManagement.Domain.Exceptions { - public class NotFoundException() : Exception("Not Found"); + public class NotFoundException() : Exception("Not found") { } } diff --git a/Exam.StockManagement.Domain/Exceptions/PasswordNotMatchException.cs b/Exam.StockManagement.Domain/Exceptions/PasswordNotMatchException.cs new file mode 100644 index 0000000..01a683f --- /dev/null +++ b/Exam.StockManagement.Domain/Exceptions/PasswordNotMatchException.cs @@ -0,0 +1,7 @@ +namespace Exam.StockManagement.Domain.Exceptions +{ + public class PasswordNotMatchException : Exception + { + public PasswordNotMatchException() : base("Password not match") { } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.Designer.cs b/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.Designer.cs new file mode 100644 index 0000000..f0b4bbc --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.Designer.cs @@ -0,0 +1,178 @@ +// +using System; +using Exam.StockManagement.Infrastructure.Persistance; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + [DbContext(typeof(StockManagementDbContext))] + [Migration("20240303073632_add-column-userDto")] + partial class addcolumnuserDto + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Category", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CategoryId")); + + b.Property("CategoryName") + .HasColumnType("integer"); + + b.HasKey("CategoryId"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ProductDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductPicture") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductPrice") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Stats", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ProductCategoryQuantity") + .HasColumnType("integer"); + + b.Property("ProductCategorySum") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("ProductQuantity") + .HasColumnType("integer"); + + b.Property("ProductSum") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Stats"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Stats", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.cs b/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.cs new file mode 100644 index 0000000..d4b2d85 --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240303073632_add-column-userDto.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + /// + public partial class addcolumnuserDto : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Code", + table: "Users", + type: "text", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Code", + table: "Users"); + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.Designer.cs b/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.Designer.cs new file mode 100644 index 0000000..85e2063 --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.Designer.cs @@ -0,0 +1,176 @@ +// +using System; +using Exam.StockManagement.Infrastructure.Persistance; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + [DbContext(typeof(StockManagementDbContext))] + [Migration("20240303125110_nullable")] + partial class nullable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Category", b => + { + b.Property("CategoryId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CategoryId")); + + b.Property("CategoryName") + .HasColumnType("integer"); + + b.HasKey("CategoryId"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ProductDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductPicture") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductPrice") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Stats", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ProductCategoryQuantity") + .HasColumnType("integer"); + + b.Property("ProductCategorySum") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("ProductQuantity") + .HasColumnType("integer"); + + b.Property("ProductSum") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Stats"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Product", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Exam.StockManagement.Domain.Entities.Models.Stats", b => + { + b.HasOne("Exam.StockManagement.Domain.Entities.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.cs b/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.cs new file mode 100644 index 0000000..c5de0ca --- /dev/null +++ b/Exam.StockManagement.Infrastructure/Migrations/20240303125110_nullable.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Exam.StockManagement.Infrastructure.Migrations +{ + /// + public partial class nullable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Role", + table: "Users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Role", + table: "Users", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Users", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + } + } +} diff --git a/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs b/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs index 77743e2..184f14b 100644 --- a/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs +++ b/Exam.StockManagement.Infrastructure/Migrations/StockManagementDbContextModelSnapshot.cs @@ -115,6 +115,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Code") + .HasColumnType("text"); + b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); @@ -133,7 +136,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("text"); b.Property("Role") - .IsRequired() .HasColumnType("text"); b.Property("UpdatedAt")