[feature/backend] add categories param in posts

This commit is contained in:
CDN 2025-02-22 02:42:55 +08:00
parent 958e3c2886
commit be8bf22017
Signed by: CDN
GPG key ID: 0C656827F9F80080
21 changed files with 448 additions and 281 deletions

View file

@ -265,21 +265,12 @@ var (
{Name: "slug", Type: field.TypeString, Unique: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "category_posts", Type: field.TypeInt, Nullable: true},
}
// PostsTable holds the schema information for the "posts" table.
PostsTable = &schema.Table{
Name: "posts",
Columns: PostsColumns,
PrimaryKey: []*schema.Column{PostsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "posts_categories_posts",
Columns: []*schema.Column{PostsColumns[5]},
RefColumns: []*schema.Column{CategoriesColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// PostContentsColumns holds the columns for the "post_contents" table.
PostContentsColumns = []*schema.Column{
@ -387,6 +378,31 @@ var (
Columns: UsersColumns,
PrimaryKey: []*schema.Column{UsersColumns[0]},
}
// CategoryPostsColumns holds the columns for the "category_posts" table.
CategoryPostsColumns = []*schema.Column{
{Name: "category_id", Type: field.TypeInt},
{Name: "post_id", Type: field.TypeInt},
}
// CategoryPostsTable holds the schema information for the "category_posts" table.
CategoryPostsTable = &schema.Table{
Name: "category_posts",
Columns: CategoryPostsColumns,
PrimaryKey: []*schema.Column{CategoryPostsColumns[0], CategoryPostsColumns[1]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "category_posts_category_id",
Columns: []*schema.Column{CategoryPostsColumns[0]},
RefColumns: []*schema.Column{CategoriesColumns[0]},
OnDelete: schema.Cascade,
},
{
Symbol: "category_posts_post_id",
Columns: []*schema.Column{CategoryPostsColumns[1]},
RefColumns: []*schema.Column{PostsColumns[0]},
OnDelete: schema.Cascade,
},
},
}
// RolePermissionsColumns holds the columns for the "role_permissions" table.
RolePermissionsColumns = []*schema.Column{
{Name: "role_id", Type: field.TypeInt},
@ -455,6 +471,7 @@ var (
PostContributorsTable,
RolesTable,
UsersTable,
CategoryPostsTable,
RolePermissionsTable,
UserRolesTable,
}
@ -469,11 +486,12 @@ func init() {
DailyCategoryContentsTable.ForeignKeys[0].RefTable = DailyCategoriesTable
DailyContentsTable.ForeignKeys[0].RefTable = DailiesTable
MediaTable.ForeignKeys[0].RefTable = UsersTable
PostsTable.ForeignKeys[0].RefTable = CategoriesTable
PostContentsTable.ForeignKeys[0].RefTable = PostsTable
PostContributorsTable.ForeignKeys[0].RefTable = ContributorsTable
PostContributorsTable.ForeignKeys[1].RefTable = ContributorRolesTable
PostContributorsTable.ForeignKeys[2].RefTable = PostsTable
CategoryPostsTable.ForeignKeys[0].RefTable = CategoriesTable
CategoryPostsTable.ForeignKeys[1].RefTable = PostsTable
RolePermissionsTable.ForeignKeys[0].RefTable = RolesTable
RolePermissionsTable.ForeignKeys[1].RefTable = PermissionsTable
UserRolesTable.ForeignKeys[0].RefTable = UsersTable