pull/4/head
Vianney JOURDY 3 days ago
parent cbb99a399f
commit 65ef3f17ce

@ -4,7 +4,6 @@ namespace UserSvc.DTOs;
public class UpdateUserDto public class UpdateUserDto
{ {
public Guid Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public string? Surname { get; set; } public string? Surname { get; set; }
public int? Age { get; set; } public int? Age { get; set; }

@ -1,10 +1,13 @@
using Shared.Enum; using System.ComponentModel.DataAnnotations;
using Shared.Enum;
namespace UserSvc.DTOs; namespace UserSvc.DTOs;
public class UserDto public class UserDto
{ {
[Required]
public string Name { get; set; } = "Guest"; public string Name { get; set; } = "Guest";
[Required]
public string Surname { get; set; } = "Gest"; public string Surname { get; set; } = "Gest";
public int Age { get; set; } = 0; public int Age { get; set; } = 0;
public float Weight { get; set; } = 0.0f; public float Weight { get; set; } = 0.0f;

@ -1,6 +1,5 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
@ -13,7 +12,7 @@ using UserSvc.Data;
namespace UserSvc.Data.Migrations namespace UserSvc.Data.Migrations
{ {
[DbContext(typeof(UserDbContext))] [DbContext(typeof(UserDbContext))]
[Migration("20250615155615_InitialCreate")] [Migration("20250616180524_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -26,11 +25,10 @@ namespace UserSvc.Data.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("UserService.Entities.User", b => modelBuilder.Entity("UserSvc.Entities.User", b =>
{ {
b.Property<Guid>("Id") b.Property<string>("Id")
.ValueGeneratedOnAdd() .HasColumnType("text");
.HasColumnType("uuid");
b.Property<int>("Age") b.Property<int>("Age")
.HasColumnType("integer"); .HasColumnType("integer");
@ -38,13 +36,12 @@ namespace UserSvc.Data.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
b.Property<string>("Goal") b.Property<int>("Goal")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<List<string>>("HealthProblems") b.Property<int[]>("HealthProblems")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("integer[]");
b.Property<float>("Height") b.Property<float>("Height")
.HasColumnType("real"); .HasColumnType("real");
@ -63,17 +60,15 @@ namespace UserSvc.Data.Migrations
b.Property<bool>("Sexe") b.Property<bool>("Sexe")
.HasColumnType("boolean"); .HasColumnType("boolean");
b.Property<string>("SleepLevel") b.Property<int>("SleepLevel")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<string>("SportLevel") b.Property<int>("SportLevel")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<List<string>>("Sports") b.Property<int[]>("Sports")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("integer[]");
b.Property<string>("Surname") b.Property<string>("Surname")
.IsRequired() .IsRequired()
@ -87,6 +82,9 @@ namespace UserSvc.Data.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("Name", "Surname")
.IsUnique();
b.ToTable("Users"); b.ToTable("Users");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable
@ -16,7 +15,7 @@ namespace UserSvc.Data.Migrations
name: "Users", name: "Users",
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uuid", nullable: false), Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false), Name = table.Column<string>(type: "text", nullable: false),
Surname = table.Column<string>(type: "text", nullable: false), Surname = table.Column<string>(type: "text", nullable: false),
Age = table.Column<int>(type: "integer", nullable: false), Age = table.Column<int>(type: "integer", nullable: false),
@ -25,11 +24,11 @@ namespace UserSvc.Data.Migrations
Sexe = table.Column<bool>(type: "boolean", nullable: false), Sexe = table.Column<bool>(type: "boolean", nullable: false),
ProfilePict = table.Column<string>(type: "text", nullable: false), ProfilePict = table.Column<string>(type: "text", nullable: false),
NbSessionWeek = table.Column<int>(type: "integer", nullable: false), NbSessionWeek = table.Column<int>(type: "integer", nullable: false),
Goal = table.Column<string>(type: "text", nullable: false), Goal = table.Column<int>(type: "integer", nullable: false),
SleepLevel = table.Column<string>(type: "text", nullable: false), SleepLevel = table.Column<int>(type: "integer", nullable: false),
SportLevel = table.Column<string>(type: "text", nullable: false), SportLevel = table.Column<int>(type: "integer", nullable: false),
Sports = table.Column<List<string>>(type: "text[]", nullable: false), Sports = table.Column<int[]>(type: "integer[]", nullable: false),
HealthProblems = table.Column<List<string>>(type: "text[]", nullable: false), HealthProblems = table.Column<int[]>(type: "integer[]", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false) UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
}, },
@ -37,6 +36,12 @@ namespace UserSvc.Data.Migrations
{ {
table.PrimaryKey("PK_Users", x => x.Id); table.PrimaryKey("PK_Users", x => x.Id);
}); });
migrationBuilder.CreateIndex(
name: "IX_Users_Name_Surname",
table: "Users",
columns: new[] { "Name", "Surname" },
unique: true);
} }
/// <inheritdoc /> /// <inheritdoc />

@ -1,6 +1,5 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@ -23,11 +22,10 @@ namespace UserSvc.Data.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("UserService.Entities.User", b => modelBuilder.Entity("UserSvc.Entities.User", b =>
{ {
b.Property<Guid>("Id") b.Property<string>("Id")
.ValueGeneratedOnAdd() .HasColumnType("text");
.HasColumnType("uuid");
b.Property<int>("Age") b.Property<int>("Age")
.HasColumnType("integer"); .HasColumnType("integer");
@ -35,13 +33,12 @@ namespace UserSvc.Data.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
b.Property<string>("Goal") b.Property<int>("Goal")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<List<string>>("HealthProblems") b.Property<int[]>("HealthProblems")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("integer[]");
b.Property<float>("Height") b.Property<float>("Height")
.HasColumnType("real"); .HasColumnType("real");
@ -60,17 +57,15 @@ namespace UserSvc.Data.Migrations
b.Property<bool>("Sexe") b.Property<bool>("Sexe")
.HasColumnType("boolean"); .HasColumnType("boolean");
b.Property<string>("SleepLevel") b.Property<int>("SleepLevel")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<string>("SportLevel") b.Property<int>("SportLevel")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.Property<List<string>>("Sports") b.Property<int[]>("Sports")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("integer[]");
b.Property<string>("Surname") b.Property<string>("Surname")
.IsRequired() .IsRequired()
@ -84,6 +79,9 @@ namespace UserSvc.Data.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("Name", "Surname")
.IsUnique();
b.ToTable("Users"); b.ToTable("Users");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618

@ -1,10 +1,12 @@
using Shared.Enum; using Microsoft.EntityFrameworkCore;
using Shared.Entities;
using Shared.Enum;
namespace UserSvc.Entities; 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 Name { get; set; } = "Gest";
public string Surname { get; set; } = "Gest"; public string Surname { get; set; } = "Gest";
public int Age { get; set; } = 0; public int Age { get; set; } = 0;

@ -10,7 +10,8 @@ public class UserProfile : Profile
{ {
CreateMap<User, UserDto>(); CreateMap<User, UserDto>();
CreateMap<UserDto, User>(); CreateMap<UserDto, User>();
CreateMap<UpdateUserDto, User>(); CreateMap<UpdateUserDto, User>()
.ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null));
CreateMap<User, UpdateUserDto>(); CreateMap<User, UpdateUserDto>();
} }
} }
Loading…
Cancel
Save