#![allow(non_snake_case)] 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 = product::create(req_product); Custom(Status::Created, Json(m_product.unwrap_or_default())) } /// Get a product by passing id #[get("/")] pub async fn get_product(pid: String, _token: auth::BearerToken) -> Custom> { let m_product = product::find(&pid); Custom(Status::Ok, Json(m_product.unwrap_or_default())) } /// Update product information #[patch("/update", data = "")] pub async fn update_product( product: Json, _token: auth::BearerToken, ) -> Custom> { let m_product = product::modify(product); Custom(Status::Ok, Json(m_product.unwrap_or_default())) } /// Return all products #[get("/")] pub async fn get_products(_token: auth::BearerToken) -> Custom>> { let m_products = product::find_all(); Custom(Status::Ok, Json(m_products.unwrap_or_default())) } /// Get a order by passing id #[get("/")] pub async fn get_order(orid: String, _token: auth::BearerToken) -> Custom> { let m_order = order::find(&orid); Custom(Status::Ok, Json(m_order.unwrap_or_default())) } /// Get all orders #[get("/")] pub async fn get_orders(_token: auth::BearerToken) -> Custom>> { let m_orders = order::find_all(); Custom(Status::Ok, Json(m_orders.unwrap_or_default())) } /// Update order information #[patch("/update", data = "")] pub async fn update_order( order: Json, _token: auth::BearerToken, ) -> Custom> { let m_order = order::modify(order); Custom(Status::Ok, Json(m_order.unwrap_or_default())) } /// Create a dispute #[post("/create", data = "")] pub async fn create_dispute( dispute: Json, _token: auth::BearerToken, ) -> Custom> { let m_dispute = dispute::create(dispute); Custom(Status::Ok, Json(m_dispute.unwrap_or_default())) } /// Fetch a dispute #[get("/")] pub async fn get_dispute(_token: auth::BearerToken, did: String) -> Custom> { let m_dispute = dispute::find(&did); Custom(Status::Ok, Json(m_dispute.unwrap_or_default())) } /// Sign and submit multisig #[post("/sign/submit", data = "")] pub async fn sign_and_submit_multisig( r_data: Json, _token: auth::BearerToken, ) -> Custom> { let result: reqres::XmrRpcSubmitMultisigResponse = order::sign_and_submit_multisig(&r_data.orid, &r_data.txset).await; if result.result.tx_hash_list.is_empty() { return Custom(Status::BadRequest, Json(Default::default())); } Custom(Status::Ok, Json(Default::default())) } /// API for uploading delivery info in vendor mode /// /// Attempts to trigger NASR so that and automate txset draft from vendor. /// /// Protected: true #[post("/", data = "")] pub async fn upload_delivery_info( orid: String, r_data: Json, _token: auth::BearerToken, ) -> Custom> { let upload = order::upload_delivery_info(&orid, &r_data.delivery_info).await; let u_upload = upload.unwrap_or_default(); if u_upload.delivery_info.is_empty() { return Custom(Status::BadRequest, Json(Default::default())); } Custom(Status::Ok, Json(u_upload)) } /// toggle vendor mode #[get("/")] pub async fn toggle_vendor_mode( _token: auth::BearerToken, ) -> Custom> { let mode = utils::toggle_vendor_enabled().unwrap_or_default(); Custom(Status::Ok, Json(reqres::VendorModeResponse { mode })) } // END JSON APIs