add: littleweb (common) achievements

This commit is contained in:
trisua 2025-07-09 22:59:28 -04:00
parent 7960f1ed41
commit 4e152b07be
3 changed files with 30 additions and 3 deletions

View file

@ -6,6 +6,7 @@ use crate::{
use axum::{extract::Path, response::IntoResponse, http::StatusCode, Extension, Json}; use axum::{extract::Path, response::IntoResponse, http::StatusCode, Extension, Json};
use axum_extra::extract::CookieJar; use axum_extra::extract::CookieJar;
use tetratto_core::model::{ use tetratto_core::model::{
auth::AchievementName,
littleweb::{Domain, ServiceFsMime}, littleweb::{Domain, ServiceFsMime},
oauth, ApiReturn, Error, oauth, ApiReturn, Error,
}; };
@ -48,11 +49,20 @@ pub async fn create_request(
Json(req): Json<CreateDomain>, Json(req): Json<CreateDomain>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let data = &(data.read().await).0; let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateDomains) { let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateDomains) {
Some(ua) => ua, Some(ua) => ua,
None => return Json(Error::NotAllowed.into()), None => return Json(Error::NotAllowed.into()),
}; };
// award achievement
if let Err(e) = data
.add_achievement(&mut user, AchievementName::CreateDomain.into(), true)
.await
{
return Json(e.into());
}
// ...
match data match data
.create_domain(Domain::new(req.name, req.tld, user.id)) .create_domain(Domain::new(req.name, req.tld, user.id))
.await .await

View file

@ -7,7 +7,7 @@ use crate::{
}; };
use axum::{extract::Path, response::IntoResponse, Extension, Json}; use axum::{extract::Path, response::IntoResponse, Extension, Json};
use axum_extra::extract::CookieJar; use axum_extra::extract::CookieJar;
use tetratto_core::model::{littleweb::Service, oauth, ApiReturn, Error}; use tetratto_core::model::{auth::AchievementName, littleweb::Service, oauth, ApiReturn, Error};
pub async fn get_request( pub async fn get_request(
Path(id): Path<usize>, Path(id): Path<usize>,
@ -47,11 +47,20 @@ pub async fn create_request(
Json(req): Json<CreateService>, Json(req): Json<CreateService>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let data = &(data.read().await).0; let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateServices) { let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateServices) {
Some(ua) => ua, Some(ua) => ua,
None => return Json(Error::NotAllowed.into()), None => return Json(Error::NotAllowed.into()),
}; };
// award achievement
if let Err(e) = data
.add_achievement(&mut user, AchievementName::CreateSite.into(), true)
.await
{
return Json(e.into());
}
// ...
match data.create_service(Service::new(req.name, user.id)).await { match data.create_service(Service::new(req.name, user.id)).await {
Ok(x) => Json(ApiReturn { Ok(x) => Json(ApiReturn {
ok: true, ok: true,

View file

@ -567,6 +567,8 @@ pub enum AchievementName {
GetAllOtherAchievements, GetAllOtherAchievements,
AcceptProfileWarning, AcceptProfileWarning,
OpenSessionSettings, OpenSessionSettings,
CreateSite,
CreateDomain,
} }
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
@ -613,6 +615,8 @@ impl AchievementName {
Self::GetAllOtherAchievements => "The final performance", Self::GetAllOtherAchievements => "The final performance",
Self::AcceptProfileWarning => "I accept the risks!", Self::AcceptProfileWarning => "I accept the risks!",
Self::OpenSessionSettings => "Am I alone in here?", Self::OpenSessionSettings => "Am I alone in here?",
Self::CreateSite => "Littlewebmaster",
Self::CreateDomain => "LittleDNS",
} }
} }
@ -652,6 +656,8 @@ impl AchievementName {
Self::GetAllOtherAchievements => "Get every other achievement.", Self::GetAllOtherAchievements => "Get every other achievement.",
Self::AcceptProfileWarning => "Accept a profile warning.", Self::AcceptProfileWarning => "Accept a profile warning.",
Self::OpenSessionSettings => "Open your session settings.", Self::OpenSessionSettings => "Open your session settings.",
Self::CreateSite => "Create a site.",
Self::CreateDomain => "Create a domain.",
} }
} }
@ -693,6 +699,8 @@ impl AchievementName {
Self::GetAllOtherAchievements => Rare, Self::GetAllOtherAchievements => Rare,
Self::AcceptProfileWarning => Common, Self::AcceptProfileWarning => Common,
Self::OpenSessionSettings => Common, Self::OpenSessionSettings => Common,
Self::CreateSite => Common,
Self::CreateDomain => Common,
} }
} }
} }