This commit is contained in:
parent
2b110af845
commit
44959df6d8
1 changed files with 21 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ use axum::{
|
|||
routing::{delete, get, post},
|
||||
};
|
||||
use axum_extra::extract::{CookieJar, cookie::Cookie};
|
||||
use tracing::{error, info};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -52,9 +53,12 @@ async fn upvote_handler(
|
|||
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||
|
||||
match insert_new_vote(&slug, &voter_id, &state.db).await {
|
||||
Ok(()) => (StatusCode::OK, jar, "Successfully upvoted"),
|
||||
Ok(()) => {
|
||||
info!(slug = %slug, voter_id = %voter_id, "upvoted successfully");
|
||||
(StatusCode::OK, jar, "Successfully upvoted")
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{err}");
|
||||
error!(error = %err, slug = %slug, voter_id = %voter_id, "failed to insert vote");
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, jar, "Failed to upvote")
|
||||
}
|
||||
}
|
||||
|
|
@ -68,9 +72,12 @@ async fn delete_vote_handler(
|
|||
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||
|
||||
match delete_vote(&slug, &voter_id, &state.db).await {
|
||||
Ok(()) => (StatusCode::OK, jar, "Successfully deleted vote"),
|
||||
Ok(()) => {
|
||||
info!(slug = %slug, voter_id = %voter_id, "vote deleted successfully");
|
||||
(StatusCode::OK, jar, "Successfully deleted vote")
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{err}");
|
||||
error!(error = %err, slug = %slug, voter_id = %voter_id, "failed to delete vote");
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
jar,
|
||||
|
|
@ -87,9 +94,17 @@ async fn get_votes_and_voted_handler(
|
|||
) -> impl IntoResponse {
|
||||
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||
match get_votes_and_voted(&slug, &voter_id, &state.db).await {
|
||||
Ok(votes_and_voted) => (StatusCode::OK, jar, Json(votes_and_voted)).into_response(),
|
||||
Ok(votes_and_voted) => {
|
||||
info!(slug = %slug, voter_id = %voter_id, "fetched vote count and voter status successfully");
|
||||
(StatusCode::OK, jar, Json(votes_and_voted)).into_response()
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{err}");
|
||||
error!(
|
||||
error = %err,
|
||||
slug = %slug,
|
||||
voter_id = %voter_id,
|
||||
"failed to fetch vote count and voter status"
|
||||
);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, jar, "Failed to upvote").into_response()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue