Skip to content

Commit

Permalink
v1 paths (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm authored Nov 26, 2024
1 parent d12be6d commit 345b71b
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 201 deletions.
30 changes: 17 additions & 13 deletions backend/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ use sea_orm::ConnectionTrait;

pub fn routes<S: StateTrait>(state: S) -> Router<S> {
Router::new()
.route("/register", post(register::register::<S>))
.nest("/team", team::routes::<S>(state.clone()))
.nest("/problem", problem::routes::<S>(state.clone()))
.nest("/competition", competition::routes::<S>(state.clone()))
.route("/ws", get(socket::ws_handler::<S>))
.route(
"/stats",
post(
stats::get_stats::<S>
.layer(PermissionsLayer::new(state, &["mathcompetition.admin"])),
),
.nest(
"/v1",
Router::new()
.route("/register", post(register::register::<S>))
.nest("/team", team::routes::<S>(state.clone()))
.nest("/problem", problem::routes::<S>(state.clone()))
.nest("/competition", competition::routes::<S>(state.clone()))
.route("/ws", get(socket::ws_handler::<S>))
.route(
"/stats",
post(
stats::get_stats::<S>
.layer(PermissionsLayer::new(state, &["mathcompetition.admin"])),
),
),
)
.route("/liveness", get(liveness::<S>))
.route("/readiness", get(|| async {}))
.route("/livez", get(liveness::<S>))
.route("/readyz", get(|| async {}))
}

async fn liveness<S: StateTrait>(State(state): State<S>) -> StatusCode {
Expand Down
20 changes: 10 additions & 10 deletions backend/tests/competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod time {
let app = get_cached_app().await;
let user = iam::register_user().await;

let res = app.put("/competition/time").user(&user).send().await;
let res = app.put("/v1/competition/time").user(&user).send().await;

assert_error!(res, error::NOT_ENOUGH_PERMISSIONS);
}
Expand All @@ -20,7 +20,7 @@ mod time {
let app = get_cached_app().await;
let user = iam::register_user().await;

let res = app.patch("/competition/time").user(&user).send().await;
let res = app.patch("/v1/competition/time").user(&user).send().await;

assert_error!(res, error::NOT_ENOUGH_PERMISSIONS);
}
Expand All @@ -34,7 +34,7 @@ mod time {
iam::make_admin(&user).await;

let res = app
.patch("/competition/time")
.patch("/v1/competition/time")
.user(&user)
.json(&json!({
"start_time": 123,
Expand All @@ -44,7 +44,7 @@ mod time {

assert_eq!(res.status(), StatusCode::NO_CONTENT);

let res = app.get("/competition/time").user(&user).send().await;
let res = app.get("/v1/competition/time").user(&user).send().await;

assert_eq!(res.status(), StatusCode::OK);

Expand All @@ -67,7 +67,7 @@ mod time {
iam::make_admin(&user).await;

let res = app
.patch("/competition/time")
.patch("/v1/competition/time")
.user(&user)
.json(&json!({
"end_time": 123,
Expand All @@ -77,7 +77,7 @@ mod time {

assert_eq!(res.status(), StatusCode::NO_CONTENT);

let res = app.get("/competition/time").user(&user).send().await;
let res = app.get("/v1/competition/time").user(&user).send().await;

assert_eq!(res.status(), StatusCode::OK);

Expand All @@ -100,7 +100,7 @@ mod time {
iam::make_admin(&user).await;

let res = app
.patch("/competition/time")
.patch("/v1/competition/time")
.user(&user)
.json(&json!({
"start_time": 432,
Expand All @@ -111,7 +111,7 @@ mod time {

assert_eq!(res.status(), StatusCode::NO_CONTENT);

let res = app.get("/competition/time").user(&user).send().await;
let res = app.get("/v1/competition/time").user(&user).send().await;

assert_eq!(res.status(), StatusCode::OK);

Expand All @@ -136,11 +136,11 @@ mod time {

let owner = app.register_user().await;
let _ = app.create_team(&owner).await;
let mut socket = app.socket("/ws").start().await;
let mut socket = app.socket("/v1/ws").start().await;
assert_team_info!(socket, owner);

let res = app
.put("/competition/time")
.put("/v1/competition/time")
.user(&admin)
.json(&json!({
"start_time": 1234,
Expand Down
Loading

0 comments on commit 345b71b

Please sign in to comment.