Handlers for GET and POST engages added, renders numbers of unique engagements per post
This commit is contained in:
parent
efcdaf0cd2
commit
ea25fa9489
4 changed files with 75 additions and 27 deletions
|
|
@ -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")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue