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
---
 src/handlers.rs | 13 +++++++++++++
 src/routes.rs   |  8 ++++++++
 2 files changed, 21 insertions(+)

(limited to 'src')

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<impl warp::Reply, Infallible> {
     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<impl warp::Reply, Infallible> {
+    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<impl warp::Reply, Infallible> {
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<Extract = impl Reply, Error = Rej
         .and_then(handlers::get_config)
 }
 
+/// GET /version warp route
+pub fn get_version() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
+    warp::path!("version")
+        .and(warp::get())
+        .and_then(handlers::get_version)
+}
+
 /// GET /user warp route
 pub fn list_users(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
     warp::path!("user")
-- 
cgit v1.2.3-70-g09d2