From f9020c3c41b075704e0900afca61bb1a37170e6a Mon Sep 17 00:00:00 2001 From: Christopher Angelo Date: Wed, 7 Aug 2024 23:15:26 +0700 Subject: [PATCH] feat: expose visitors count on api --- src/routes/api.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/routes/api.rs b/src/routes/api.rs index 812e2f9..c1ace25 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -40,6 +40,7 @@ pub struct ShortenedUrl { target_url: String, comment: Option, active: bool, + visitor_count: u64, } #[typeshare] @@ -50,7 +51,7 @@ async fn list_urls(State(state): State>) -> Json let mut rows = conn .query( - "SELECT short_url, target_url, comment, active FROM links", + "SELECT short_url, target_url, comment, active, visitor_count FROM links", (), ) .await @@ -62,11 +63,13 @@ async fn list_urls(State(state): State>) -> Json let target_url = row.get::(1).expect("Unable to get target_url"); let comment = row.get::>(2).expect("Unable to get active"); let active = row.get::(3).expect("Unable to get active"); + let visitor_count = row.get::(4).expect("Unable to get visitor_count"); urls.push(ShortenedUrl { short_url, target_url, comment, active, + visitor_count, }); }