From 78eb253ced519f5f6b4c5f7f229aac3747228046 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 25 Apr 2022 12:57:32 +0300 Subject: Add new endpoint /version Use this endpoint to compare the live version to the version on vcs From here on, the version should be updated regularly as well --- Cargo.toml | 2 +- src/handlers.rs | 13 +++++++++++++ src/routes.rs | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8e3ec60..1e1fcf5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gradecoin" -version = "0.2.0" +version = "0.2.1" authors = ["Yigit Sever ", "İlker Işık (necrashter) ", "Alperen Keleş "] diff --git a/src/handlers.rs b/src/handlers.rs index 93781e4..ae82441 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -361,6 +361,19 @@ pub async fn get_config(db: Db) -> Result { Ok(reply::with_status(reply::json(&db.config), StatusCode::OK)) } +/// GET /version +/// Returns the current project version, as defined in Cargo.toml +pub async fn get_version() -> Result { + Ok(reply::with_status( + reply::html(format!( + "{} - version {}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION") + )), + StatusCode::OK, + )) +} + /// GET /transaction /// Returns JSON array of transactions pub async fn list_transactions(db: Db) -> Result { diff --git a/src/routes.rs b/src/routes.rs index 0df3470..9e08a27 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -23,6 +23,7 @@ pub fn network(db: Db) -> BoxedFilter<(impl Reply,)> { root.and( transaction_list(db.clone()) .or(get_config_route(db.clone())) + .or(get_version()) .or(register_user(db.clone())) .or(auth_transaction_propose(db.clone())) .or(auth_block_propose(db.clone())) @@ -40,6 +41,13 @@ pub fn get_config_route(db: Db) -> impl Filter impl Filter + Clone { + warp::path!("version") + .and(warp::get()) + .and_then(handlers::get_version) +} + /// GET /user warp route pub fn list_users(db: Db) -> impl Filter + Clone { warp::path!("user") -- cgit v1.2.3-70-g09d2