Handlers for GET and POST engages added, renders numbers of unique engagements per post

This commit is contained in:
Hollgy 2024-03-22 22:38:18 +01:00
parent efcdaf0cd2
commit ea25fa9489
4 changed files with 75 additions and 27 deletions

View file

@ -101,7 +101,18 @@ pub async fn engage_post(
}
}
return Ok(HttpResponse::Ok().json("Engaged"));
// Get engagement count
let q = sqlx::query!("SELECT COUNT(*) FROM engagements WHERE post_id = $1", post_id)
.fetch_one(&state.pool)
.await;
match q {
Ok(count) => Ok(HttpResponse::Ok().json(count.count)),
Err(e) => {
info!("Error getting engagements: {}", e);
Ok(HttpResponse::InternalServerError().json("Error"))
}
}
}
#[get("/posts/{id}/engage")]