Skip to content

Commit

Permalink
feat(backend): endpoint for active boards
Browse files Browse the repository at this point in the history
  • Loading branch information
lindtvedtsebastian committed Jun 13, 2024
1 parent 11bd191 commit 3e3e631
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::time::Duration;

use axum::{
body::Body,
extract::{Path, State},
http::{HeaderValue, Method, StatusCode},
response::Response,
routing::{get, post},
Json, Router,
};
Expand Down Expand Up @@ -56,6 +58,7 @@ async fn main() {
]);

let app = Router::new()
.route("/active", get(active_boards))
.route("/subscribe/:bid", get(subscribe))
.route("/refresh/:bid", post(trigger))
.route("/update", post(update))
Expand All @@ -68,6 +71,20 @@ async fn main() {
.unwrap()
}

async fn active_boards(
AuthBearer(token): AuthBearer,
State(mut state): State<AppState>,
) -> Result<Response<Body>, AppError> {
if token != state.key {
return Ok(Response::builder()
.status(StatusCode::UNAUTHORIZED)
.body(Body::from(0.to_string()))
.unwrap());
}
let active_boards = state.master.get::<&str, i32>("active_boards").await?;
Ok(Response::new(Body::from(active_boards.to_string())))
}

async fn trigger(
Path(bid): Path<String>,
AuthBearer(token): AuthBearer,
Expand Down

0 comments on commit 3e3e631

Please sign in to comment.