Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 paths #106

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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