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),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -221,6 +221,10 @@ pub fn routes() -> Router {
|
|||
get(auth::profile::redirect_from_ip),
|
||||
)
|
||||
.route("/auth/ip/{ip}/block", post(auth::social::ip_block_request))
|
||||
.route(
|
||||
"/auth/user/{id}/gpa",
|
||||
get(auth::profile::get_user_gpa_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/user/{id}/_connect/{stream}",
|
||||
any(auth::profile::subscription_handler),
|
||||
|
|
|
@ -350,6 +350,7 @@ pub async fn posts_request(
|
|||
context.insert("pinned", &pinned);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("tag", &props.tag);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
@ -453,6 +454,7 @@ pub async fn replies_request(
|
|||
|
||||
context.insert("posts", &posts);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
@ -558,6 +560,7 @@ pub async fn media_request(
|
|||
|
||||
context.insert("posts", &posts);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
@ -652,6 +655,7 @@ pub async fn outbox_request(
|
|||
|
||||
context.insert("questions", &questions);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&Some(user),
|
||||
|
@ -746,6 +750,7 @@ pub async fn following_request(
|
|||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
@ -840,6 +845,7 @@ pub async fn followers_request(
|
|||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("gpa", &data.0.calculate_user_gpa(other_user.id).await);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue