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

@@ -1,68 +0,0 @@
use axum::{
extract::{Query, State},
http::StatusCode,
response::IntoResponse,
routing::get,
Router,
};
use sea_orm::TryIntoModel;
use app::persistence::blog::{create_blog, search_blogs};
use app::state::AppState;
use models::params::blog::CreateBlogParams;
use models::queries::blog::BlogQuery;
use models::schemas::blog::{BlogListSchema, BlogSchema};
use crate::error::ApiError;
use crate::extractor::{Json, Valid};
use crate::models::{ApiErrorResponse, ParamsErrorResponse};
#[utoipa::path(
post,
path = "",
request_body = CreateBlogParams,
responses(
(status = 201, description = "Blog created", body = BlogSchema),
(status = 400, description = "Bad request", body = ApiErrorResponse),
(status = 422, description = "Validation error", body = ParamsErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
)
)]
async fn blogs_post(
state: State<AppState>,
Valid(Json(params)): Valid<Json<CreateBlogParams>>,
) -> Result<impl IntoResponse, ApiError> {
let blog = create_blog(&state.conn, params)
.await
.map_err(ApiError::from)?;
let blog = blog.try_into_model().unwrap();
Ok((StatusCode::CREATED, Json(BlogSchema::from(blog))))
}
#[utoipa::path(
get,
path = "",
params(
BlogQuery
),
responses(
(status = 200, description = "List blogs", body = BlogListSchema),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
)
)]
async fn blogs_get(
state: State<AppState>,
query: Query<BlogQuery>,
) -> Result<impl IntoResponse, ApiError> {
let Query(query) = query;
let blogs = search_blogs(&state.conn, query)
.await
.map_err(ApiError::from)?;
Ok(Json(BlogListSchema::from(blogs)))
}
pub fn create_blog_router() -> Router<AppState> {
Router::new().route("/", get(blogs_get).post(blogs_post))
}

View File

@@ -1,11 +1,9 @@
use axum::Router;
pub mod blog;
pub mod root;
pub mod user;
use app::state::AppState;
use blog::create_blog_router;
use root::create_root_router;
use user::create_user_router;
@@ -13,6 +11,5 @@ pub fn create_router(state: AppState) -> Router {
Router::new()
.merge(create_root_router())
.nest("/users", create_user_router())
.nest("/blogs", create_blog_router())
.with_state(state)
}