Refactor blog module and remove blog-related functionality

- Removed blog router and associated API endpoints.
- Deleted blog persistence functions and related query parameters.
- Removed blog schemas and models from the codebase.
- Introduced common crate for shared types, including DateTimeWithTimeZoneWrapper.
- Added Thought and Follow models with corresponding migrations.
- Updated dependencies in Cargo.toml files to reflect changes.
- Adjusted tests to remove references to the blog module.
This commit is contained in:
2025-09-05 18:10:58 +02:00
parent e5747eaaf3
commit 912259ef54
32 changed files with 543 additions and 333 deletions

View File

@@ -19,3 +19,5 @@ sea-orm = { workspace = true, features = [
] }
validator = { workspace = true, features = ["derive"] }
utoipa = { workspace = true }
common = { path = "../common" }

View File

@@ -0,0 +1,32 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "follow")]
pub struct Model {
#[sea_orm(primary_key)]
pub follower_id: i32,
#[sea_orm(primary_key)]
pub followed_id: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::FollowerId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Follower,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::FollowedId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Followed,
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -2,5 +2,6 @@
pub mod prelude;
pub mod blog;
pub mod follow;
pub mod thought;
pub mod user;

View File

@@ -1,4 +1,5 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
pub use super::blog::Entity as Blog;
pub use super::follow::Entity as Follow;
pub use super::thought::Entity as Thought;
pub use super::user::Entity as User;

View File

@@ -1,15 +1,13 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "blog")]
#[sea_orm(table_name = "thought")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub author_id: i32,
pub title: String,
pub content: String,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@@ -12,15 +12,6 @@ pub struct Model {
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::blog::Entity")]
Blog,
}
impl Related<super::blog::Entity> for Entity {
fn to() -> RelationDef {
Relation::Blog.def()
}
}
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -1,14 +0,0 @@
use serde::Deserialize;
use utoipa::ToSchema;
use validator::Validate;
#[derive(Deserialize, Validate, ToSchema)]
pub struct CreateBlogParams {
pub author_id: u32,
#[validate(length(min = 2))]
pub title: String,
#[validate(length(min = 2))]
pub content: String,
}

View File

@@ -1,2 +1,2 @@
pub mod blog;
pub mod thought;
pub mod user;

View File

@@ -0,0 +1,11 @@
use serde::Deserialize;
use utoipa::ToSchema;
use validator::Validate;
#[derive(Deserialize, Validate, ToSchema)]
pub struct CreateThoughtParams {
pub author_id: i32,
#[validate(length(min = 1, max = 128))]
pub content: String,
}

View File

@@ -1,9 +0,0 @@
use serde::Deserialize;
use utoipa::IntoParams;
#[derive(Deserialize, Default, IntoParams)]
#[into_params(style = Form, parameter_in = Query)]
pub struct BlogQuery {
#[param(nullable = true)]
pub title: Option<String>,
}

View File

@@ -1,2 +1 @@
pub mod blog;
pub mod user;

View File

@@ -1,36 +0,0 @@
use serde::Serialize;
use utoipa::ToSchema;
use crate::domains::blog;
#[derive(Serialize, ToSchema)]
pub struct BlogSchema {
pub id: u32,
pub title: String,
pub content: String,
pub author_id: u32,
}
impl From<blog::Model> for BlogSchema {
fn from(blog: blog::Model) -> Self {
Self {
id: blog.id as u32,
title: blog.title,
content: blog.content,
author_id: blog.author_id as u32,
}
}
}
#[derive(Serialize, ToSchema)]
pub struct BlogListSchema {
pub blogs: Vec<BlogSchema>,
}
impl From<Vec<blog::Model>> for BlogListSchema {
fn from(blogs: Vec<blog::Model>) -> Self {
Self {
blogs: blogs.into_iter().map(BlogSchema::from).collect(),
}
}
}

View File

@@ -1,2 +1,2 @@
pub mod blog;
pub mod thought;
pub mod user;

View File

@@ -0,0 +1,36 @@
use crate::domains::thought;
use common::DateTimeWithTimeZoneWrapper;
use serde::Serialize;
use utoipa::ToSchema;
#[derive(Serialize, ToSchema)]
pub struct ThoughtSchema {
pub id: i32,
pub author_id: i32,
pub content: String,
pub created_at: DateTimeWithTimeZoneWrapper,
}
impl From<thought::Model> for ThoughtSchema {
fn from(model: thought::Model) -> Self {
Self {
id: model.id,
author_id: model.author_id,
content: model.content,
created_at: model.created_at.into(),
}
}
}
#[derive(Serialize, ToSchema)]
pub struct ThoughtListSchema {
pub thoughts: Vec<ThoughtSchema>,
}
impl From<Vec<thought::Model>> for ThoughtListSchema {
fn from(models: Vec<thought::Model>) -> Self {
Self {
thoughts: models.into_iter().map(ThoughtSchema::from).collect(),
}
}
}