Slight improvement of the api
This commit is contained in:
parent
cf607ae345
commit
db0783fe2e
3 changed files with 12 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::db::db_new_post;
|
||||
use crate::db::{db_get_posts, db_new_post};
|
||||
use crate::ServerState;
|
||||
|
||||
use actix_web::web::Data;
|
||||
|
@ -38,10 +38,7 @@ pub struct User {
|
|||
|
||||
#[get("/posts")]
|
||||
pub async fn get_posts(state: Data<ServerState>) -> Result<impl Responder> {
|
||||
let stream = sqlx::query_as!(Post, "SELECT * FROM posts");
|
||||
|
||||
let posts = stream.fetch_all(&state.pool).await.unwrap();
|
||||
Ok(HttpResponse::Ok().json(posts))
|
||||
Ok(HttpResponse::Ok().json(db_get_posts(&state.pool).await))
|
||||
}
|
||||
|
||||
#[post("/posts")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue