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": [
|
"rust-analyzer.linkedProjects": [
|
||||||
|
"./Cargo.toml",
|
||||||
"./Cargo.toml",
|
"./Cargo.toml",
|
||||||
"./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]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
|
mod api;
|
||||||
mod database;
|
mod database;
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let client = match DatabaseHandler::create().await {
|
let db = match DatabaseHandler::create().await {
|
||||||
Ok(client) => client,
|
Ok(client) => client,
|
||||||
Err(err) => panic!(
|
Err(err) => panic!(
|
||||||
"Encountered an error while connecting to the database!\n{}",
|
"Encountered an error while connecting to the database!\n{}",
|
||||||
|
@ -16,8 +17,8 @@ async fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
match rocket::build()
|
match rocket::build()
|
||||||
.manage(client)
|
.manage(db)
|
||||||
.mount("/", routes![])
|
.mount("/api/v1/maps", api::maps::get_all_routes())
|
||||||
.launch()
|
.launch()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user