Skip to content

Commit

Permalink
feat: expose visitors count on api
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloanan committed Aug 7, 2024
1 parent c1c0226 commit f9020c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/routes/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct ShortenedUrl {
target_url: String,
comment: Option<String>,
active: bool,
visitor_count: u64,
}

#[typeshare]
Expand All @@ -50,7 +51,7 @@ async fn list_urls(State(state): State<Arc<AppState>>) -> Json<AllShortenedUrls>

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
Expand All @@ -62,11 +63,13 @@ async fn list_urls(State(state): State<Arc<AppState>>) -> Json<AllShortenedUrls>
let target_url = row.get::<String>(1).expect("Unable to get target_url");
let comment = row.get::<Option<String>>(2).expect("Unable to get active");
let active = row.get::<bool>(3).expect("Unable to get active");
let visitor_count = row.get::<u64>(4).expect("Unable to get visitor_count");
urls.push(ShortenedUrl {
short_url,
target_url,
comment,
active,
visitor_count,
});
}

Expand Down

0 comments on commit f9020c3

Please sign in to comment.