add: great post average
This commit is contained in:
parent
11fb131b8b
commit
15dc2e5d71
5 changed files with 122 additions and 0 deletions
|
@ -645,3 +645,33 @@ pub async fn post_to_socket_request(
|
|||
payload: (),
|
||||
})
|
||||
}
|
||||
|
||||
/// Calculate the user's great post average.
|
||||
pub async fn get_user_gpa_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let gpa = data.calculate_user_gpa(id).await;
|
||||
return Json(ApiReturn {
|
||||
ok: true,
|
||||
message: if gpa >= 3 {
|
||||
"cool".to_string()
|
||||
} else if gpa >= 4 {
|
||||
"extraordinary".to_string()
|
||||
} else {
|
||||
"ok".to_string()
|
||||
},
|
||||
payload: Some(gpa),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue