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:
32
thoughts-backend/models/src/domains/follow.rs
Normal file
32
thoughts-backend/models/src/domains/follow.rs
Normal 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 {}
|
@@ -2,5 +2,6 @@
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod blog;
|
||||
pub mod follow;
|
||||
pub mod thought;
|
||||
pub mod user;
|
||||
|
@@ -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;
|
||||
|
@@ -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)]
|
@@ -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 {}
|
||||
|
@@ -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,
|
||||
}
|
@@ -1,2 +1,2 @@
|
||||
pub mod blog;
|
||||
pub mod thought;
|
||||
pub mod user;
|
||||
|
11
thoughts-backend/models/src/params/thought.rs
Normal file
11
thoughts-backend/models/src/params/thought.rs
Normal 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,
|
||||
}
|
@@ -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>,
|
||||
}
|
@@ -1,2 +1 @@
|
||||
pub mod blog;
|
||||
pub mod user;
|
||||
|
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,2 +1,2 @@
|
||||
pub mod blog;
|
||||
pub mod thought;
|
||||
pub mod user;
|
||||
|
36
thoughts-backend/models/src/schemas/thought.rs
Normal file
36
thoughts-backend/models/src/schemas/thought.rs
Normal 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(),
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user