aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-06-20 22:01:26 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-06-20 22:01:26 +0200
commit951cb293111db9ea0947cd65872da744bce92d31 (patch)
treed232f6c1443b96b24d821fdf05b1d96037091c30 /planetwars-server
parenta2a8a41689ad07eb2236ee438e9d01266946008d (diff)
downloadplanetwars.dev-951cb293111db9ea0947cd65872da744bce92d31.tar.xz
planetwars.dev-951cb293111db9ea0947cd65872da744bce92d31.zip
upgrade to axum 0.5
Diffstat (limited to 'planetwars-server')
-rw-r--r--planetwars-server/Cargo.toml2
-rw-r--r--planetwars-server/src/db/matches.rs9
-rw-r--r--planetwars-server/src/lib.rs12
-rw-r--r--planetwars-server/src/routes/bots.rs2
-rw-r--r--planetwars-server/src/routes/users.rs6
5 files changed, 19 insertions, 12 deletions
diff --git a/planetwars-server/Cargo.toml b/planetwars-server/Cargo.toml
index d85a011..99161bb 100644
--- a/planetwars-server/Cargo.toml
+++ b/planetwars-server/Cargo.toml
@@ -9,7 +9,7 @@ edition = "2021"
futures = "0.3"
tokio = { version = "1.15", features = ["full"] }
hyper = "0.14"
-axum = { version = "0.4", features = ["json", "headers", "multipart"] }
+axum = { version = "0.5", features = ["json", "headers", "multipart"] }
diesel = { version = "1.4.4", features = ["postgres", "chrono"] }
diesel-derive-enum = { version = "1.1", features = ["postgres"] }
bb8 = "0.7"
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs
index ee25e85..dfff3cf 100644
--- a/planetwars-server/src/db/matches.rs
+++ b/planetwars-server/src/db/matches.rs
@@ -160,14 +160,17 @@ pub fn find_match_base(id: i32, conn: &PgConnection) -> QueryResult<MatchBase> {
}
pub enum MatchResult {
- Finished { winner: Option<i32> }
+ Finished { winner: Option<i32> },
}
pub fn save_match_result(id: i32, result: MatchResult, conn: &PgConnection) -> QueryResult<()> {
let MatchResult::Finished { winner } = result;
diesel::update(matches::table.find(id))
- .set((matches::winner.eq(winner), matches::state.eq(MatchState::Finished)))
+ .set((
+ matches::winner.eq(winner),
+ matches::state.eq(MatchState::Finished),
+ ))
.execute(conn)?;
Ok(())
-} \ No newline at end of file
+}
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index e50003c..9c9a03c 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -24,7 +24,7 @@ use axum::{
extract::{Extension, FromRequest, RequestParts},
http::StatusCode,
routing::{get, post},
- AddExtensionLayer, Router,
+ Router,
};
// TODO: make these configurable
@@ -105,12 +105,16 @@ pub fn get_config() -> Result<Configuration, ConfigError> {
.try_deserialize()
}
-async fn run_registry(_db_pool: DbPool) {
+async fn run_registry(db_pool: DbPool) {
// TODO: put in config
let addr = SocketAddr::from(([127, 0, 0, 1], 9001));
axum::Server::bind(&addr)
- .serve(registry_service().into_make_service())
+ .serve(
+ registry_service()
+ .layer(Extension(db_pool))
+ .into_make_service(),
+ )
.await
.unwrap();
}
@@ -124,7 +128,7 @@ pub async fn run_app() {
let api_service = Router::new()
.nest("/api", api())
- .layer(AddExtensionLayer::new(db_pool))
+ .layer(Extension(db_pool))
.into_make_service();
// TODO: put in config
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs
index 3bbaa1a..df0c4d0 100644
--- a/planetwars-server/src/routes/bots.rs
+++ b/planetwars-server/src/routes/bots.rs
@@ -12,7 +12,7 @@ use std::path::PathBuf;
use thiserror;
use crate::db::bots::{self, CodeBundle};
-use crate::db::ratings::{RankedBot, self};
+use crate::db::ratings::{self, RankedBot};
use crate::db::users::User;
use crate::modules::bots::save_code_bundle;
use crate::{DatabaseConnection, BOTS_DIR};
diff --git a/planetwars-server/src/routes/users.rs b/planetwars-server/src/routes/users.rs
index 54ddd09..1989904 100644
--- a/planetwars-server/src/routes/users.rs
+++ b/planetwars-server/src/routes/users.rs
@@ -5,7 +5,7 @@ use axum::extract::{FromRequest, RequestParts, TypedHeader};
use axum::headers::authorization::Bearer;
use axum::headers::Authorization;
use axum::http::StatusCode;
-use axum::response::{Headers, IntoResponse, Response};
+use axum::response::{IntoResponse, Response};
use axum::{async_trait, Json};
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -163,9 +163,9 @@ pub async fn login(conn: DatabaseConnection, params: Json<LoginParams>) -> Respo
Some(user) => {
let session = sessions::create_session(&user, &conn);
let user_data: UserData = user.into();
- let headers = Headers(vec![("Token", &session.token)]);
+ let headers = [("Token", &session.token)];
- (headers, Json(user_data)).into_response()
+ (StatusCode::OK, headers, Json(user_data)).into_response()
}
}
}