diff --git a/src/UserSvc/DTOs/UpdateUserDto.cs b/src/UserSvc/DTOs/UpdateUserDto.cs index 27f3fa4..b583d85 100644 --- a/src/UserSvc/DTOs/UpdateUserDto.cs +++ b/src/UserSvc/DTOs/UpdateUserDto.cs @@ -4,7 +4,6 @@ namespace UserSvc.DTOs; public class UpdateUserDto { - public Guid Id { get; set; } public string? Name { get; set; } public string? Surname { get; set; } public int? Age { get; set; } diff --git a/src/UserSvc/DTOs/UserDto.cs b/src/UserSvc/DTOs/UserDto.cs index 7aff05d..254b7e7 100644 --- a/src/UserSvc/DTOs/UserDto.cs +++ b/src/UserSvc/DTOs/UserDto.cs @@ -1,10 +1,13 @@ -using Shared.Enum; +using System.ComponentModel.DataAnnotations; +using Shared.Enum; namespace UserSvc.DTOs; public class UserDto { + [Required] public string Name { get; set; } = "Guest"; + [Required] public string Surname { get; set; } = "Gest"; public int Age { get; set; } = 0; public float Weight { get; set; } = 0.0f; diff --git a/src/UserSvc/Data/Migrations/20250615155615_InitialCreate.Designer.cs b/src/UserSvc/Data/Migrations/20250616180524_InitialCreate.Designer.cs similarity index 72% rename from src/UserSvc/Data/Migrations/20250615155615_InitialCreate.Designer.cs rename to src/UserSvc/Data/Migrations/20250616180524_InitialCreate.Designer.cs index c85e11f..8424a27 100644 --- a/src/UserSvc/Data/Migrations/20250615155615_InitialCreate.Designer.cs +++ b/src/UserSvc/Data/Migrations/20250616180524_InitialCreate.Designer.cs @@ -1,6 +1,5 @@ // using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -13,7 +12,7 @@ using UserSvc.Data; namespace UserSvc.Data.Migrations { [DbContext(typeof(UserDbContext))] - [Migration("20250615155615_InitialCreate")] + [Migration("20250616180524_InitialCreate")] partial class InitialCreate { /// @@ -26,11 +25,10 @@ namespace UserSvc.Data.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("UserService.Entities.User", b => + modelBuilder.Entity("UserSvc.Entities.User", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + b.Property("Id") + .HasColumnType("text"); b.Property("Age") .HasColumnType("integer"); @@ -38,13 +36,12 @@ namespace UserSvc.Data.Migrations b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("Goal") - .IsRequired() - .HasColumnType("text"); + b.Property("Goal") + .HasColumnType("integer"); - b.Property>("HealthProblems") + b.Property("HealthProblems") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("integer[]"); b.Property("Height") .HasColumnType("real"); @@ -63,17 +60,15 @@ namespace UserSvc.Data.Migrations b.Property("Sexe") .HasColumnType("boolean"); - b.Property("SleepLevel") - .IsRequired() - .HasColumnType("text"); + b.Property("SleepLevel") + .HasColumnType("integer"); - b.Property("SportLevel") - .IsRequired() - .HasColumnType("text"); + b.Property("SportLevel") + .HasColumnType("integer"); - b.Property>("Sports") + b.Property("Sports") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("integer[]"); b.Property("Surname") .IsRequired() @@ -87,6 +82,9 @@ namespace UserSvc.Data.Migrations b.HasKey("Id"); + b.HasIndex("Name", "Surname") + .IsUnique(); + b.ToTable("Users"); }); #pragma warning restore 612, 618 diff --git a/src/UserSvc/Data/Migrations/20250615155615_InitialCreate.cs b/src/UserSvc/Data/Migrations/20250616180524_InitialCreate.cs similarity index 70% rename from src/UserSvc/Data/Migrations/20250615155615_InitialCreate.cs rename to src/UserSvc/Data/Migrations/20250616180524_InitialCreate.cs index 096e6a2..8057f88 100644 --- a/src/UserSvc/Data/Migrations/20250615155615_InitialCreate.cs +++ b/src/UserSvc/Data/Migrations/20250616180524_InitialCreate.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable @@ -16,7 +15,7 @@ namespace UserSvc.Data.Migrations name: "Users", columns: table => new { - Id = table.Column(type: "uuid", nullable: false), + Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Surname = table.Column(type: "text", nullable: false), Age = table.Column(type: "integer", nullable: false), @@ -25,11 +24,11 @@ namespace UserSvc.Data.Migrations Sexe = table.Column(type: "boolean", nullable: false), ProfilePict = table.Column(type: "text", nullable: false), NbSessionWeek = table.Column(type: "integer", nullable: false), - Goal = table.Column(type: "text", nullable: false), - SleepLevel = table.Column(type: "text", nullable: false), - SportLevel = table.Column(type: "text", nullable: false), - Sports = table.Column>(type: "text[]", nullable: false), - HealthProblems = table.Column>(type: "text[]", nullable: false), + Goal = table.Column(type: "integer", nullable: false), + SleepLevel = table.Column(type: "integer", nullable: false), + SportLevel = table.Column(type: "integer", nullable: false), + Sports = table.Column(type: "integer[]", nullable: false), + HealthProblems = table.Column(type: "integer[]", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, @@ -37,6 +36,12 @@ namespace UserSvc.Data.Migrations { table.PrimaryKey("PK_Users", x => x.Id); }); + + migrationBuilder.CreateIndex( + name: "IX_Users_Name_Surname", + table: "Users", + columns: new[] { "Name", "Surname" }, + unique: true); } /// diff --git a/src/UserSvc/Data/Migrations/UserDbContextModelSnapshot.cs b/src/UserSvc/Data/Migrations/UserDbContextModelSnapshot.cs index ddea271..fed0b7d 100644 --- a/src/UserSvc/Data/Migrations/UserDbContextModelSnapshot.cs +++ b/src/UserSvc/Data/Migrations/UserDbContextModelSnapshot.cs @@ -1,6 +1,5 @@ // using System; -using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -23,11 +22,10 @@ namespace UserSvc.Data.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("UserService.Entities.User", b => + modelBuilder.Entity("UserSvc.Entities.User", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + b.Property("Id") + .HasColumnType("text"); b.Property("Age") .HasColumnType("integer"); @@ -35,13 +33,12 @@ namespace UserSvc.Data.Migrations b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("Goal") - .IsRequired() - .HasColumnType("text"); + b.Property("Goal") + .HasColumnType("integer"); - b.Property>("HealthProblems") + b.Property("HealthProblems") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("integer[]"); b.Property("Height") .HasColumnType("real"); @@ -60,17 +57,15 @@ namespace UserSvc.Data.Migrations b.Property("Sexe") .HasColumnType("boolean"); - b.Property("SleepLevel") - .IsRequired() - .HasColumnType("text"); + b.Property("SleepLevel") + .HasColumnType("integer"); - b.Property("SportLevel") - .IsRequired() - .HasColumnType("text"); + b.Property("SportLevel") + .HasColumnType("integer"); - b.Property>("Sports") + b.Property("Sports") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("integer[]"); b.Property("Surname") .IsRequired() @@ -84,6 +79,9 @@ namespace UserSvc.Data.Migrations b.HasKey("Id"); + b.HasIndex("Name", "Surname") + .IsUnique(); + b.ToTable("Users"); }); #pragma warning restore 612, 618 diff --git a/src/UserSvc/Entities/User.cs b/src/UserSvc/Entities/User.cs index 561b693..5c316a5 100644 --- a/src/UserSvc/Entities/User.cs +++ b/src/UserSvc/Entities/User.cs @@ -1,10 +1,12 @@ -using Shared.Enum; +using Microsoft.EntityFrameworkCore; +using Shared.Entities; +using Shared.Enum; namespace UserSvc.Entities; -public class User +[Index(nameof(Name), nameof(Surname), IsUnique = true)] +public class User : EntityBase { - public Guid Id { get; set; } public string Name { get; set; } = "Gest"; public string Surname { get; set; } = "Gest"; public int Age { get; set; } = 0; diff --git a/src/UserSvc/RequestHelpers/UserProfile.cs b/src/UserSvc/RequestHelpers/UserProfile.cs index 507cbfe..84482ba 100644 --- a/src/UserSvc/RequestHelpers/UserProfile.cs +++ b/src/UserSvc/RequestHelpers/UserProfile.cs @@ -10,7 +10,8 @@ public class UserProfile : Profile { CreateMap(); CreateMap(); - CreateMap(); + CreateMap() + .ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null)); CreateMap(); } } \ No newline at end of file