use rocket::{ get, http::Status, patch, post, response::status::Custom, serde::json::Json, }; use nevmes_core::*; use crate::{ dispute, product, }; // JSON APIs /// Create a product by passing vendor vid #[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::Ok, Json(m_product)) } /// Update product information #[patch("/<_address>/update", data = "")] pub async fn update_product( _address: String, product: Json, _token: auth::BearerToken, ) -> Custom> { let m_product: models::Product = product::modify(product); Custom(Status::Ok, Json(m_product)) } // /// Initialize order // #[get("/
/create/")] // pub async fn initialize_order( // address: String, // _token: auth::BearerToken, // pid: String, // ) -> Custom> { // // get the cid from the address after verification // let m_customer = customer::find(address).await; // let temp_pid = String::from(&pid); // let m_order: models::Order = order::create(m_customer.cid, temp_pid).await; // Custom( // Status::Ok, // Json(reqres::GetOrderResponse::build(pid, m_order)), // ) // } // /// Update order information from vendor // #[patch("/update////vendor")] // pub async fn update_order( // _address: String, // oid: String, // pid: String, // _token: auth::BearerToken, // data: String, // ) -> Custom> { // let temp_pid: String = String::from(&pid); // let m_order: models::Order = order::modify(oid, pid, data, update_type).await; // Custom( // Status::Ok, // Json(reqres::GetOrderResponse::build(temp_pid, m_order)), // ) // } // /// Get all orders // /// by passing auth // #[get("/
/")] // pub async fn get_orders( // address: String, // corv: String, // _token: auth::BearerToken, // ) -> Custom> { // let m_orders: Vec = order::find_all(address, corv).await; // Custom(Status::Ok, Json(reqres::GetOrdersResponse::build(m_orders))) // } /// 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