Skip to content
Snippets Groups Projects
Commit 16c5a286 authored by insert's avatar insert
Browse files

Refractor route code.

parent c748b434
No related merge requests found
Pipeline #405 passed with stage
in 2 minutes and 3 seconds
This diff is collapsed.
use rocket::Route;
pub fn routes() -> Vec<Route> {
routes! []
}
This diff is collapsed.
use rocket::Route;
pub fn routes() -> Vec<Route> {
routes! []
}
...@@ -2,71 +2,20 @@ pub use rocket::http::Status; ...@@ -2,71 +2,20 @@ pub use rocket::http::Status;
pub use rocket::response::Redirect; pub use rocket::response::Redirect;
use rocket::Rocket; use rocket::Rocket;
// use crate::database::Permission; mod root;
// use rocket_contrib::json::JsonValue; mod users;
mod guild;
/* pub mod channel; mod onboard;
pub mod guild; mod channels;
pub mod user; */
pub mod root;
/* #[derive(Responder)]
pub enum Response {
#[response()]
Result(Status),
#[response()]
Success(JsonValue),
#[response()]
Redirect(Redirect),
#[response(status = 207)]
PartialStatus(JsonValue),
#[response(status = 400)]
BadRequest(JsonValue),
#[response(status = 401)]
Unauthorized(JsonValue),
#[response(status = 401)]
LackingPermission(Permission),
#[response(status = 404)]
NotFound(JsonValue),
#[response(status = 406)]
NotAcceptable(JsonValue),
#[response(status = 409)]
Conflict(JsonValue),
#[response(status = 410)]
Gone(JsonValue),
#[response(status = 418)]
Teapot(JsonValue),
#[response(status = 422)]
UnprocessableEntity(JsonValue),
#[response(status = 429)]
TooManyRequests(JsonValue),
#[response(status = 500)]
InternalServerError(JsonValue),
}
use rocket::http::ContentType;
use rocket::request::Request;
use std::io::Cursor;
use rocket::response::{Responder, Result};
impl<'a> Responder<'a, 'static> for Permission {
fn respond_to(self, _: &Request) -> Result<'static> {
let body = format!(
"{{\"error\":\"Lacking permission: {:?}.\",\"permission\":{}}}",
self, self as u32,
);
rocket::response::Response::build()
.header(ContentType::JSON)
.sized_body(body.len(), Cursor::new(body))
.ok()
}
} */
pub fn mount(rocket: Rocket) -> Rocket { pub fn mount(rocket: Rocket) -> Rocket {
rocket rocket
.mount("/", routes![root::root, root::teapot]) .mount("/", routes![root::root, root::teapot])
.mount("/onboard", onboard::routes())
.mount("/users", users::routes())
.mount("/channels", channels::routes())
.mount("/guild", guild::routes())
/*.mount( /*.mount(
"/users", "/users",
routes![ routes![
......
use crate::util::result::Result;
use rauth::auth::Session;
#[get("/hello")]
pub async fn req(session: Session) -> Result<String> {
Ok("try onboard user".to_string())
}
use rocket::Route;
mod hello;
pub fn routes() -> Vec<Route> {
routes! [
hello::req
]
}
This diff is collapsed.
use crate::util::result::Result;
#[get("/<id>")]
pub async fn req(id: String) -> Result<String> {
println!("{}", id);
Ok("LETS FUCKING GOOOO".to_string())
}
use rocket::Route;
mod fetch_user;
pub fn routes() -> Vec<Route> {
routes! [
fetch_user::req
]
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment