-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from Devolutions/WAYK-2564
Wayk 2564 - Add endpoint /sessions to list sessions + Fix tests
- Loading branch information
Showing
22 changed files
with
361 additions
and
234 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,5 @@ embed-resource = "1.3" | |
|
||
[dev-dependencies] | ||
exitcode = "1.1" | ||
tokio-test = "0.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
use crate::SESSION_IN_PROGRESS_COUNT; | ||
use crate::http::HttpErrorStatus; | ||
use crate::{GatewaySessionInfo, SESSIONS_IN_PROGRESS}; | ||
use saphir::controller::Controller; | ||
use saphir::http::{Method, StatusCode}; | ||
use saphir::macros::controller; | ||
use std::sync::atomic::Ordering; | ||
use saphir::prelude::Json; | ||
|
||
pub struct SessionsController; | ||
|
||
impl Default for SessionsController { | ||
fn default() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
#[controller(name = "sessions")] | ||
impl SessionsController { | ||
#[get("/count")] | ||
async fn get_count(&self) -> (StatusCode, String) { | ||
let sessions_count = SESSION_IN_PROGRESS_COUNT.load(Ordering::Relaxed).to_string(); | ||
(StatusCode::OK, sessions_count) | ||
let sessions = SESSIONS_IN_PROGRESS.read().await; | ||
(StatusCode::OK, sessions.len().to_string()) | ||
} | ||
|
||
#[get("/")] | ||
async fn get_sessions(&self) -> Result<Json<Vec<GatewaySessionInfo>>, HttpErrorStatus> { | ||
let sessions = SESSIONS_IN_PROGRESS.read().await; | ||
|
||
let sessions_in_progress: Vec<GatewaySessionInfo> = sessions.values().map(|x| x.clone()).collect(); | ||
|
||
Ok(Json(sessions_in_progress)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.