use rocket::{ get, http::Status, patch, post, response::status::Custom, serde::json::Json, }; use neveko_core::*; // JSON APIs /// Create a product by passings json product #[post("/create", data = "")] pub async fn create_product( req_product: Json, _token: auth::BearerToken, ) -> Custom> { let m_product: models::Product = product::create(req_product); Custom(Status::Created, Json(m_product)) } /// Get a product by passing id #[get("/")] pub async fn get_product(pid: String, _token: auth::BearerToken) -> Custom> { let m_product: models::Product = product::find(&pid); Custom(Status::Ok, Json(m_product)) } /// Update product information #[patch("/update", data = "")] pub async fn update_product( product: Json, _token: auth::BearerToken, ) -> Custom> { let m_product: models::Product = product::modify(product); Custom(Status::Ok, Json(m_product)) } /// Return all products #[get("/")] pub async fn get_products(_token: auth::BearerToken) -> Custom>> { let m_products: Vec = product::find_all(); Custom(Status::Ok, Json(m_products)) } /// Get a order by passing id #[get("/")] pub async fn get_order(orid: String, _token: auth::BearerToken) -> Custom> { let m_order: models::Order = order::find(&orid); Custom(Status::Ok, Json(m_order)) } /// Get a order by passing id #[get("/")] pub async fn get_orders(_token: auth::BearerToken) -> Custom>> { let m_orders: Vec = order::find_all(); Custom(Status::Ok, Json(m_orders)) } /// Update order information #[patch("/update", data = "")] pub async fn update_order( order: Json, _token: auth::BearerToken, ) -> Custom> { let m_order: models::Order = order::modify(order); Custom(Status::Ok, Json(m_order)) } /// Create a dispute #[post("/create", data = "")] pub async fn create_dispute( dispute: Json, _token: auth::BearerToken, ) -> Custom> { let m_dispute: models::Dispute = dispute::create(dispute); Custom(Status::Ok, Json(m_dispute)) } /// Create a dispute #[get("/")] pub async fn get_dispute(_token: auth::BearerToken, did: String) -> Custom> { let m_dispute: models::Dispute = dispute::find(&did); Custom(Status::Ok, Json(m_dispute)) } // END JSON APIs