Skip to content

Commit 6dcccb7

Browse files
Add support for posts: database migration, domain model, repository, service, DTOs, API endpoints, and related tests.
1 parent c95d996 commit 6dcccb7

29 files changed

+918
-27
lines changed

Migrations/20251126210845_AddPosts.Designer.cs

Lines changed: 254 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace sparkly_server.Services.Users.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class AddPosts : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "posts",
16+
columns: table => new
17+
{
18+
Id = table.Column<Guid>(type: "uuid", nullable: false),
19+
AuthorId = table.Column<Guid>(type: "uuid", nullable: false),
20+
ProjectId = table.Column<Guid>(type: "uuid", nullable: true),
21+
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
22+
Content = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: false),
23+
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
24+
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
25+
},
26+
constraints: table =>
27+
{
28+
table.PrimaryKey("PK_posts", x => x.Id);
29+
table.ForeignKey(
30+
name: "FK_posts_projects_ProjectId",
31+
column: x => x.ProjectId,
32+
principalTable: "projects",
33+
principalColumn: "Id",
34+
onDelete: ReferentialAction.Cascade);
35+
table.ForeignKey(
36+
name: "FK_posts_users_AuthorId",
37+
column: x => x.AuthorId,
38+
principalTable: "users",
39+
principalColumn: "Id",
40+
onDelete: ReferentialAction.Cascade);
41+
});
42+
43+
migrationBuilder.CreateIndex(
44+
name: "IX_posts_AuthorId",
45+
table: "posts",
46+
column: "AuthorId");
47+
48+
migrationBuilder.CreateIndex(
49+
name: "IX_posts_ProjectId",
50+
table: "posts",
51+
column: "ProjectId");
52+
}
53+
54+
/// <inheritdoc />
55+
protected override void Down(MigrationBuilder migrationBuilder)
56+
{
57+
migrationBuilder.DropTable(
58+
name: "posts");
59+
}
60+
}
61+
}

Migrations/AppDbContextModelSnapshot.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ protected override void BuildModel(ModelBuilder modelBuilder)
7373
b.ToTable("refresh_tokens", (string)null);
7474
});
7575

76+
modelBuilder.Entity("sparkly_server.Domain.Posts.Post", b =>
77+
{
78+
b.Property<Guid>("Id")
79+
.ValueGeneratedOnAdd()
80+
.HasColumnType("uuid");
81+
82+
b.Property<Guid>("AuthorId")
83+
.HasColumnType("uuid");
84+
85+
b.Property<string>("Content")
86+
.IsRequired()
87+
.HasMaxLength(4000)
88+
.HasColumnType("character varying(4000)");
89+
90+
b.Property<DateTime>("CreatedAt")
91+
.HasColumnType("timestamp with time zone");
92+
93+
b.Property<Guid?>("ProjectId")
94+
.HasColumnType("uuid");
95+
96+
b.Property<string>("Title")
97+
.IsRequired()
98+
.HasMaxLength(200)
99+
.HasColumnType("character varying(200)");
100+
101+
b.Property<DateTime>("UpdatedAt")
102+
.HasColumnType("timestamp with time zone");
103+
104+
b.HasKey("Id");
105+
106+
b.HasIndex("AuthorId");
107+
108+
b.HasIndex("ProjectId");
109+
110+
b.ToTable("posts", (string)null);
111+
});
112+
76113
modelBuilder.Entity("sparkly_server.Domain.Projects.Project", b =>
77114
{
78115
b.Property<Guid>("Id")
@@ -179,8 +216,33 @@ protected override void BuildModel(ModelBuilder modelBuilder)
179216
b.Navigation("User");
180217
});
181218

219+
modelBuilder.Entity("sparkly_server.Domain.Posts.Post", b =>
220+
{
221+
b.HasOne("sparkly_server.Domain.Users.User", "Author")
222+
.WithMany("Posts")
223+
.HasForeignKey("AuthorId")
224+
.OnDelete(DeleteBehavior.Cascade)
225+
.IsRequired();
226+
227+
b.HasOne("sparkly_server.Domain.Projects.Project", "Project")
228+
.WithMany("Posts")
229+
.HasForeignKey("ProjectId")
230+
.OnDelete(DeleteBehavior.Cascade);
231+
232+
b.Navigation("Author");
233+
234+
b.Navigation("Project");
235+
});
236+
237+
modelBuilder.Entity("sparkly_server.Domain.Projects.Project", b =>
238+
{
239+
b.Navigation("Posts");
240+
});
241+
182242
modelBuilder.Entity("sparkly_server.Domain.Users.User", b =>
183243
{
244+
b.Navigation("Posts");
245+
184246
b.Navigation("RefreshTokens");
185247
});
186248
#pragma warning restore 612, 618

0 commit comments

Comments
 (0)