added get authors posts route, datasource
This commit is contained in:
@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user