add: user achievements
This commit is contained in:
parent
e7c4cf14aa
commit
b860f74124
15 changed files with 318 additions and 11 deletions
|
@ -7,6 +7,7 @@ use axum::{
|
|||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{
|
||||
addr::RemoteAddr,
|
||||
auth::AchievementName,
|
||||
communities::{Poll, PollVote, Post},
|
||||
oauth,
|
||||
permissions::FinePermission,
|
||||
|
@ -178,6 +179,41 @@ pub async fn create_request(
|
|||
}
|
||||
}
|
||||
|
||||
// achievements
|
||||
if let Err(e) = data
|
||||
.add_achievement(&user, AchievementName::CreatePost.into())
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
if user.post_count >= 49 {
|
||||
if let Err(e) = data
|
||||
.add_achievement(&user, AchievementName::Create50Posts.into())
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
if user.post_count >= 99 {
|
||||
if let Err(e) = data
|
||||
.add_achievement(&user, AchievementName::Create100Posts.into())
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
if user.post_count >= 999 {
|
||||
if let Err(e) = data
|
||||
.add_achievement(&user, AchievementName::Create1000Posts.into())
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
// return
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
|
|
|
@ -7,7 +7,7 @@ use axum::{
|
|||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{
|
||||
addr::RemoteAddr,
|
||||
auth::IpBlock,
|
||||
auth::{AchievementName, IpBlock},
|
||||
communities::{CommunityReadAccess, Question},
|
||||
oauth,
|
||||
permissions::FinePermission,
|
||||
|
@ -50,6 +50,16 @@ pub async fn create_request(
|
|||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
// award achievement
|
||||
if let Some(ref user) = user {
|
||||
if let Err(e) = data
|
||||
.add_achievement(user, AchievementName::CreateQuestion.into())
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
let mut props = Question::new(
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue