Added a way to receive all maps
This commit is contained in:
parent
34b35e0795
commit
c277eb5ebd
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"rust-analyzer.linkedProjects": [
|
||||
"./Cargo.toml",
|
||||
"./Cargo.toml",
|
||||
"./Cargo.toml",
|
||||
"./Cargo.toml"
|
||||
|
|
3
Rocket.toml
Normal file
3
Rocket.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[global]
|
||||
address = "0.0.0.0"
|
||||
port = 12345
|
15
src/api/maps.rs
Normal file
15
src/api/maps.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use rocket::{serde::json::Json, Route, State};
|
||||
|
||||
use crate::database::{models::map::Map, DatabaseHandler};
|
||||
|
||||
#[get("/")]
|
||||
async fn get_all_maps(db: &State<DatabaseHandler>) -> Result<Json<Vec<Map>>, String> {
|
||||
match Map::get_all_maps(db).await {
|
||||
Ok(maps) => Ok(Json(maps)),
|
||||
Err(err) => Err(format!("Error: {}", err)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_routes() -> Vec<Route> {
|
||||
routes![get_all_maps]
|
||||
}
|
1
src/api/mod.rs
Normal file
1
src/api/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod maps;
|
|
@ -3,11 +3,12 @@ use database::DatabaseHandler;
|
|||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
mod api;
|
||||
mod database;
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
let client = match DatabaseHandler::create().await {
|
||||
let db = match DatabaseHandler::create().await {
|
||||
Ok(client) => client,
|
||||
Err(err) => panic!(
|
||||
"Encountered an error while connecting to the database!\n{}",
|
||||
|
@ -16,8 +17,8 @@ async fn main() {
|
|||
};
|
||||
|
||||
match rocket::build()
|
||||
.manage(client)
|
||||
.mount("/", routes![])
|
||||
.manage(db)
|
||||
.mount("/api/v1/maps", api::maps::get_all_routes())
|
||||
.launch()
|
||||
.await
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user