Main now ignores unused mut
parent
19a21b8cdf
commit
e2003442e2
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{RbError, RbResult, RbOption},
|
errors::{RbError, RbOption, RbResult},
|
||||||
schema::{posts, posts::dsl::*},
|
schema::{posts, posts::dsl::*},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -12,16 +12,14 @@ use figment::{
|
||||||
providers::{Env, Format, Yaml},
|
providers::{Env, Format, Yaml},
|
||||||
Figment,
|
Figment,
|
||||||
};
|
};
|
||||||
|
#[cfg(any(feature = "web", feature = "docs"))]
|
||||||
|
use rocket::fs;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
fairing::AdHoc,
|
fairing::AdHoc,
|
||||||
http::Status,
|
http::Status,
|
||||||
serde::json::{json, Value},
|
serde::json::{json, Value},
|
||||||
Build, Orbit, Request, Rocket,
|
Build, Orbit, Request, Rocket,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(feature = "web", feature="docs"))]
|
|
||||||
use rocket::fs;
|
|
||||||
|
|
||||||
use rocket_sync_db_pools::database;
|
use rocket_sync_db_pools::database;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -98,6 +96,9 @@ fn rocket() -> _
|
||||||
.merge(Yaml::file("Rb.yaml").nested())
|
.merge(Yaml::file("Rb.yaml").nested())
|
||||||
.merge(Env::prefixed("RB_").global());
|
.merge(Env::prefixed("RB_").global());
|
||||||
|
|
||||||
|
// This mut is necessary when the "docs" or "web" feature is enabled, as these further modify
|
||||||
|
// the instance variable
|
||||||
|
#[allow(unused_mut)]
|
||||||
let mut instance = rocket::custom(figment)
|
let mut instance = rocket::custom(figment)
|
||||||
.attach(RbDbConn::fairing())
|
.attach(RbDbConn::fairing())
|
||||||
.attach(AdHoc::try_on_ignite(
|
.attach(AdHoc::try_on_ignite(
|
||||||
|
@ -121,12 +122,24 @@ fn rocket() -> _
|
||||||
// It's weird that this is allowed, but the line on its own isn't
|
// It's weird that this is allowed, but the line on its own isn't
|
||||||
#[cfg(feature = "web")]
|
#[cfg(feature = "web")]
|
||||||
{
|
{
|
||||||
instance = instance.mount("/", fs::FileServer::new("/var/www/html/web", fs::Options::Index | fs::Options::NormalizeDirs));
|
instance = instance.mount(
|
||||||
|
"/",
|
||||||
|
fs::FileServer::new(
|
||||||
|
"/var/www/html/web",
|
||||||
|
fs::Options::Index | fs::Options::NormalizeDirs,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "docs")]
|
#[cfg(feature = "docs")]
|
||||||
{
|
{
|
||||||
instance = instance.mount("/docs", fs::FileServer::new("/var/www/html/docs", fs::Options::Index | fs::Options::NormalizeDirs));
|
instance = instance.mount(
|
||||||
|
"/docs",
|
||||||
|
fs::FileServer::new(
|
||||||
|
"/var/www/html/docs",
|
||||||
|
fs::Options::Index | fs::Options::NormalizeDirs,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance
|
instance
|
||||||
|
|
12
src/posts.rs
12
src/posts.rs
|
@ -1,6 +1,11 @@
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
use crate::{db, errors::RbResult, errors::RbOption, guards::Admin, RbDbConn};
|
use crate::{
|
||||||
|
db,
|
||||||
|
errors::{RbOption, RbResult},
|
||||||
|
guards::Admin,
|
||||||
|
RbDbConn,
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/?<offset>&<limit>")]
|
#[get("/?<offset>&<limit>")]
|
||||||
pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>>
|
pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>>
|
||||||
|
@ -26,7 +31,10 @@ pub async fn create(
|
||||||
#[get("/<id>")]
|
#[get("/<id>")]
|
||||||
pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Post>>
|
pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Post>>
|
||||||
{
|
{
|
||||||
Ok(conn.run(move |c| db::posts::find(c, &id)).await?.and_then(|p| Some(Json(p))))
|
Ok(conn
|
||||||
|
.run(move |c| db::posts::find(c, &id))
|
||||||
|
.await?
|
||||||
|
.and_then(|p| Some(Json(p))))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("/<id>", data = "<patch_post>")]
|
#[patch("/<id>", data = "<patch_post>")]
|
||||||
|
|
|
@ -41,9 +41,4 @@ table! {
|
||||||
joinable!(posts -> sections (section_id));
|
joinable!(posts -> sections (section_id));
|
||||||
joinable!(refresh_tokens -> users (user_id));
|
joinable!(refresh_tokens -> users (user_id));
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(
|
allow_tables_to_appear_in_same_query!(posts, refresh_tokens, sections, users,);
|
||||||
posts,
|
|
||||||
refresh_tokens,
|
|
||||||
sections,
|
|
||||||
users,
|
|
||||||
);
|
|
||||||
|
|
Reference in New Issue