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},
|
routing::{delete, get, post},
|
||||||
};
|
};
|
||||||
use axum_extra::extract::{CookieJar, cookie::Cookie};
|
use axum_extra::extract::{CookieJar, cookie::Cookie};
|
||||||
|
use tracing::{error, info};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -52,9 +53,12 @@ async fn upvote_handler(
|
||||||
let (jar, voter_id) = get_or_init_voter_id(jar);
|
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||||
|
|
||||||
match insert_new_vote(&slug, &voter_id, &state.db).await {
|
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) => {
|
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")
|
(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);
|
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||||
|
|
||||||
match delete_vote(&slug, &voter_id, &state.db).await {
|
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) => {
|
Err(err) => {
|
||||||
println!("{err}");
|
error!(error = %err, slug = %slug, voter_id = %voter_id, "failed to delete vote");
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
jar,
|
jar,
|
||||||
|
|
@ -87,9 +94,17 @@ async fn get_votes_and_voted_handler(
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let (jar, voter_id) = get_or_init_voter_id(jar);
|
let (jar, voter_id) = get_or_init_voter_id(jar);
|
||||||
match get_votes_and_voted(&slug, &voter_id, &state.db).await {
|
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) => {
|
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()
|
(StatusCode::INTERNAL_SERVER_ERROR, jar, "Failed to upvote").into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue