first route! get logo from database
This commit is contained in:
parent
a85f29d3a8
commit
7ed2f4c922
4 changed files with 53 additions and 0 deletions
7
crates/ezidam/src/error/conversion.rs
Normal file
7
crates/ezidam/src/error/conversion.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
use super::Error;
|
||||||
|
|
||||||
|
impl From<settings::Error> for Error {
|
||||||
|
fn from(e: settings::Error) -> Error {
|
||||||
|
Error::internal_server_error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
mod database;
|
mod database;
|
||||||
|
mod error;
|
||||||
|
mod file_from_bytes;
|
||||||
|
mod response_timer;
|
||||||
|
mod routes;
|
||||||
mod shutdown;
|
mod shutdown;
|
||||||
|
|
||||||
// see for using rocket with main function https://github.com/intellij-rust/intellij-rust/issues/5975#issuecomment-920620289
|
// see for using rocket with main function https://github.com/intellij-rust/intellij-rust/issues/5975#issuecomment-920620289
|
||||||
|
|
@ -13,6 +17,15 @@ async fn main() -> std::result::Result<(), rocket::Error> {
|
||||||
// Database
|
// Database
|
||||||
let rocket_builder = database::Database::rocket(rocket_builder);
|
let rocket_builder = database::Database::rocket(rocket_builder);
|
||||||
|
|
||||||
|
// Templates
|
||||||
|
let rocket_builder = rocket_builder.attach(rocket_dyn_templates::Template::fairing());
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
let rocket_builder = routes::routes(rocket_builder);
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
let rocket_builder = error::catchers::register(rocket_builder);
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
let rocket_builder = shutdown::shutdown(rocket_builder);
|
let rocket_builder = shutdown::shutdown(rocket_builder);
|
||||||
|
|
||||||
|
|
|
||||||
17
crates/ezidam/src/routes/mod.rs
Normal file
17
crates/ezidam/src/routes/mod.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
use rocket::{Build, Rocket};
|
||||||
|
|
||||||
|
pub mod root;
|
||||||
|
|
||||||
|
pub(self) mod prelude {
|
||||||
|
pub use crate::database::Database;
|
||||||
|
pub use crate::error::Error;
|
||||||
|
pub use crate::file_from_bytes::FileFromBytes;
|
||||||
|
pub use rocket_db_pools::Connection;
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn routes(rocket_builder: Rocket<Build>) -> Rocket<Build> {
|
||||||
|
// Root
|
||||||
|
rocket_builder.mount("/", root::routes())
|
||||||
|
}
|
||||||
16
crates/ezidam/src/routes/root.rs
Normal file
16
crates/ezidam/src/routes/root.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use super::prelude::*;
|
||||||
|
use rocket::{get, routes};
|
||||||
|
use settings::Settings;
|
||||||
|
|
||||||
|
pub fn routes() -> Vec<rocket::Route> {
|
||||||
|
routes![logo]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/logo")]
|
||||||
|
async fn logo(mut db: Connection<Database>) -> Result<FileFromBytes> {
|
||||||
|
// Get settings
|
||||||
|
let settings = Settings::get(&mut *db).await?;
|
||||||
|
|
||||||
|
// HTTP response
|
||||||
|
Ok(FileFromBytes::from(settings.business_logo()))
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue