Skip to content

Commit 1fe9e45

Browse files
add migrate
1 parent 23f460d commit 1fe9e45

File tree

8 files changed

+292
-25
lines changed

8 files changed

+292
-25
lines changed

Core/Entities/BaseModel/BaseModel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ namespace PaymentCoreServiceApi.Core.Entities.BaseModel;
22

33
public abstract class EntityBase
44
{
5-
public long Id { get; private set; } = Random.Shared.NextInt64(1000, 10000);
6-
public DateTime CreatedAt { get; set; }
7-
public DateTime UpdatedAt { get; set; }
8-
public bool Active { get; set; }
9-
public bool Deleted { get; set; }
10-
public int? DeletedBy { get; set; }
11-
public DateTime? DeletedAt { get; set; }
12-
public int? CreatedBy { get; set; }
13-
public int? UpdatedBy { get; set; }
5+
public long Id { get; private set; }
6+
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
7+
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
8+
public bool Active { get; set; } = true;
9+
public bool Deleted { get; set; } = false;
10+
public int? DeletedBy { get; set; } = null;
11+
public DateTime? DeletedAt { get; set; } = null;
12+
public int? CreatedBy { get; set; } = null;
13+
public int? UpdatedBy { get; set; } = null;
1414
}

Core/Repositories/IUserRepository.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

Features/Users/Commands/CreateUserCommand.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ namespace PaymentCoreServiceApi.Features.Users.Commands;
55

66
public record CreateUserCommand : IRequest<User>
77
{
8-
public string Username { get; init; } = default!;
9-
public string Email { get; init; } = default!;
10-
public string Password { get; init; } = default!;
8+
public string NickName { get; set; }
9+
public string Avatar { get; set; }
10+
public int? Gender { get; set; }
11+
public DateTime? BirthDate { get; set; }
12+
public int Age { get; set; }
13+
public string Email { get; set; }
14+
public string UserName { get; set; }
15+
public string Password { get; set; }
16+
public string PhoneNumber { get; set; }
17+
public string Address { get; set; }
1118
}

Features/Users/Commands/CreateUserCommandHandler.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@ public async Task<User> Handle(CreateUserCommand request, CancellationToken canc
1717
{
1818
var user = new User
1919
{
20-
UserName = request.Username,
20+
NickName = request.NickName,
21+
Avatar = request.Avatar,
22+
Gender = request.Gender,
23+
BirthDate = request.BirthDate,
24+
Age = request.Age,
2125
Email = request.Email,
22-
Password = request.Password // Note: In a real application, you should hash the password
26+
UserName = request.UserName,
27+
Password = request.Password,
28+
PhoneNumber = request.PhoneNumber,
29+
Address = request.Address,
30+
Active = true,
2331
};
2432

33+
2534
var result = await _userWriteRepository.AddAsync(user);
35+
2636
return result;
2737
}
38+
39+
public IUserWriteRepository UserWriteRepository => _userWriteRepository;
2840
}

Infrastructure/DbContexts/AppDbContext.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
99
{
1010
}
1111
public DbSet<User> Users { get; set; }
12-
protected override void OnModelCreating(ModelBuilder modelBuilder)
13-
{
14-
base.OnModelCreating(modelBuilder);
15-
// Optional: Fluent API config here
16-
}
12+
//dotnet ef database update
1713
}

Migrations/20250712080102_InitCreate.Designer.cs

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4+
5+
#nullable disable
6+
7+
namespace PaymentCoreServiceApi.Migrations
8+
{
9+
/// <inheritdoc />
10+
public partial class InitCreate : Migration
11+
{
12+
/// <inheritdoc />
13+
protected override void Up(MigrationBuilder migrationBuilder)
14+
{
15+
migrationBuilder.CreateTable(
16+
name: "Users",
17+
columns: table => new
18+
{
19+
Id = table.Column<long>(type: "bigint", nullable: false)
20+
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
21+
NickName = table.Column<string>(type: "text", nullable: false),
22+
Avatar = table.Column<string>(type: "text", nullable: false),
23+
Gender = table.Column<int>(type: "integer", nullable: true),
24+
BirthDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
25+
Age = table.Column<int>(type: "integer", nullable: false),
26+
Email = table.Column<string>(type: "text", nullable: false),
27+
UserName = table.Column<string>(type: "text", nullable: false),
28+
Password = table.Column<string>(type: "text", nullable: false),
29+
PhoneNumber = table.Column<string>(type: "text", nullable: false),
30+
Address = table.Column<string>(type: "text", nullable: false),
31+
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
32+
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
33+
Active = table.Column<bool>(type: "boolean", nullable: false),
34+
Deleted = table.Column<bool>(type: "boolean", nullable: false),
35+
DeletedBy = table.Column<int>(type: "integer", nullable: true),
36+
DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
37+
CreatedBy = table.Column<int>(type: "integer", nullable: true),
38+
UpdatedBy = table.Column<int>(type: "integer", nullable: true)
39+
},
40+
constraints: table =>
41+
{
42+
table.PrimaryKey("PK_Users", x => x.Id);
43+
});
44+
}
45+
46+
/// <inheritdoc />
47+
protected override void Down(MigrationBuilder migrationBuilder)
48+
{
49+
migrationBuilder.DropTable(
50+
name: "Users");
51+
}
52+
}
53+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// <auto-generated />
2+
using System;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6+
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
7+
using PaymentCoreServiceApi.Infrastructure.DbContexts;
8+
9+
#nullable disable
10+
11+
namespace PaymentCoreServiceApi.Migrations
12+
{
13+
[DbContext(typeof(AppDbContext))]
14+
partial class AppDbContextModelSnapshot : ModelSnapshot
15+
{
16+
protected override void BuildModel(ModelBuilder modelBuilder)
17+
{
18+
#pragma warning disable 612, 618
19+
modelBuilder
20+
.HasAnnotation("ProductVersion", "8.0.10")
21+
.HasAnnotation("Relational:MaxIdentifierLength", 63);
22+
23+
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
24+
25+
modelBuilder.Entity("PaymentCoreServiceApi.Core.Entities.UserAgents.User", b =>
26+
{
27+
b.Property<long>("Id")
28+
.ValueGeneratedOnAdd()
29+
.HasColumnType("bigint");
30+
31+
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
32+
33+
b.Property<bool>("Active")
34+
.HasColumnType("boolean");
35+
36+
b.Property<string>("Address")
37+
.IsRequired()
38+
.HasColumnType("text");
39+
40+
b.Property<int>("Age")
41+
.HasColumnType("integer");
42+
43+
b.Property<string>("Avatar")
44+
.IsRequired()
45+
.HasColumnType("text");
46+
47+
b.Property<DateTime?>("BirthDate")
48+
.HasColumnType("timestamp with time zone");
49+
50+
b.Property<DateTime>("CreatedAt")
51+
.HasColumnType("timestamp with time zone");
52+
53+
b.Property<int?>("CreatedBy")
54+
.HasColumnType("integer");
55+
56+
b.Property<bool>("Deleted")
57+
.HasColumnType("boolean");
58+
59+
b.Property<DateTime?>("DeletedAt")
60+
.HasColumnType("timestamp with time zone");
61+
62+
b.Property<int?>("DeletedBy")
63+
.HasColumnType("integer");
64+
65+
b.Property<string>("Email")
66+
.IsRequired()
67+
.HasColumnType("text");
68+
69+
b.Property<int?>("Gender")
70+
.HasColumnType("integer");
71+
72+
b.Property<string>("NickName")
73+
.IsRequired()
74+
.HasColumnType("text");
75+
76+
b.Property<string>("Password")
77+
.IsRequired()
78+
.HasColumnType("text");
79+
80+
b.Property<string>("PhoneNumber")
81+
.IsRequired()
82+
.HasColumnType("text");
83+
84+
b.Property<DateTime>("UpdatedAt")
85+
.HasColumnType("timestamp with time zone");
86+
87+
b.Property<int?>("UpdatedBy")
88+
.HasColumnType("integer");
89+
90+
b.Property<string>("UserName")
91+
.IsRequired()
92+
.HasColumnType("text");
93+
94+
b.HasKey("Id");
95+
96+
b.ToTable("Users");
97+
});
98+
#pragma warning restore 612, 618
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)