feat: enhance user registration and follow functionality, add popular tags endpoint, and update tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use axum::{extract::State, response::IntoResponse, routing::get, Json, Router};
|
||||
|
||||
use app::{
|
||||
persistence::{follow::get_followed_ids, thought::get_feed_for_user},
|
||||
persistence::{follow::get_following_ids, thought::get_feed_for_user},
|
||||
state::AppState,
|
||||
};
|
||||
use models::schemas::thought::{ThoughtListSchema, ThoughtSchema};
|
||||
@@ -23,8 +23,8 @@ async fn feed_get(
|
||||
State(state): State<AppState>,
|
||||
auth_user: AuthUser,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
let followed_ids = get_followed_ids(&state.conn, auth_user.id).await?;
|
||||
let mut thoughts_with_authors = get_feed_for_user(&state.conn, followed_ids).await?;
|
||||
let following_ids = get_following_ids(&state.conn, auth_user.id).await?;
|
||||
let mut thoughts_with_authors = get_feed_for_user(&state.conn, following_ids).await?;
|
||||
|
||||
let own_thoughts = get_feed_for_user(&state.conn, vec![auth_user.id]).await?;
|
||||
thoughts_with_authors.extend(own_thoughts);
|
||||
|
@@ -1,5 +1,8 @@
|
||||
use crate::error::ApiError;
|
||||
use app::{persistence::thought::get_thoughts_by_tag_name, state::AppState};
|
||||
use app::{
|
||||
persistence::{tag, thought::get_thoughts_by_tag_name},
|
||||
state::AppState,
|
||||
};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::IntoResponse,
|
||||
@@ -27,6 +30,20 @@ async fn get_thoughts_by_tag(
|
||||
Ok(Json(ThoughtListSchema::from(thoughts_schema)))
|
||||
}
|
||||
|
||||
pub fn create_tag_router() -> Router<AppState> {
|
||||
Router::new().route("/{tag_name}", get(get_thoughts_by_tag))
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/popular",
|
||||
responses((status = 200, description = "List of popular tags", body = Vec<String>))
|
||||
)]
|
||||
async fn get_popular_tags(State(state): State<AppState>) -> Result<impl IntoResponse, ApiError> {
|
||||
let tags = tag::get_popular_tags(&state.conn).await;
|
||||
println!("Fetched popular tags: {:?}", tags);
|
||||
let tags = tags?;
|
||||
Ok(Json(tags))
|
||||
}
|
||||
|
||||
pub fn create_tag_router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/{tag_name}", get(get_thoughts_by_tag))
|
||||
.route("/popular", get(get_popular_tags))
|
||||
}
|
||||
|
@@ -248,7 +248,12 @@ async fn get_user_by_param(
|
||||
}
|
||||
} else {
|
||||
match get_user_by_username(&state.conn, &username).await {
|
||||
Ok(Some(user)) => Json(UserSchema::from(user)).into_response(),
|
||||
Ok(Some(user)) => {
|
||||
let top_friends = app::persistence::user::get_top_friends(&state.conn, user.id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
Json(UserSchema::from((user, top_friends))).into_response()
|
||||
}
|
||||
Ok(None) => ApiError::from(UserError::NotFound).into_response(),
|
||||
Err(e) => ApiError::from(e).into_response(),
|
||||
}
|
||||
@@ -332,7 +337,9 @@ async fn get_me(
|
||||
let user = get_user(&state.conn, auth_user.id)
|
||||
.await?
|
||||
.ok_or(UserError::NotFound)?;
|
||||
Ok(axum::Json(UserSchema::from(user)))
|
||||
let top_friends = app::persistence::user::get_top_friends(&state.conn, auth_user.id).await?;
|
||||
|
||||
Ok(axum::Json(UserSchema::from((user, top_friends))))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
|
Reference in New Issue
Block a user