added get authors posts route, datasource

This commit is contained in:
2024-09-28 02:26:17 -04:00
parent c508f78043
commit 4480b87cab
2 changed files with 25 additions and 1 deletions

View File

@ -31,6 +31,7 @@ impl AuthorsRoute {
axum::Router::new()
.route("/", get(AuthorsRoute::get_all))
.route("/:id", get(AuthorsRoute::get_one))
.route("/:id/posts", get(AuthorsRoute::get_authors_posts))
.with_state(app_state.db.clone())
}
@ -53,4 +54,14 @@ impl AuthorsRoute {
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
async fn get_authors_posts(
State(pool): State<Pool<Postgres>>,
Path(params): Path<AuthorGetOneParams>,
) -> impl IntoResponse {
match AuthorsDatasource::get_authors_posts(&pool, params.id).await {
Ok(p) => Ok(Json(p)),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
}