use rocket::serde::json::Json; use crate::{ db, errors::{RbOption, RbResult}, guards::Admin, RbDbConn, }; #[get("/?&")] pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult>> { Ok(Json( conn.run(move |c| db::posts::get(c, offset, limit)).await?, )) } #[post("/", data = "")] pub async fn create( _admin: Admin, conn: RbDbConn, new_post: Json, ) -> RbResult> { Ok(Json( conn.run(move |c| db::posts::create(c, &new_post.into_inner())) .await?, )) } #[get("/")] pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption> { Ok(conn .run(move |c| db::posts::find(c, &id)) .await? .and_then(|p| Some(Json(p)))) } #[patch("/", data = "")] pub async fn patch( _admin: Admin, conn: RbDbConn, id: uuid::Uuid, patch_post: Json, ) -> RbResult> { Ok(Json( conn.run(move |c| db::posts::update(c, &id, &patch_post.into_inner())) .await?, )) } #[delete("/")] pub async fn delete(_admin: Admin, conn: RbDbConn, id: uuid::Uuid) -> RbResult<()> { Ok(conn.run(move |c| db::posts::delete(c, &id)).await?) }