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_extra::extract::CookieJar;
use tetratto_core::model::{
auth::AchievementName,
littleweb::{Domain, ServiceFsMime},
oauth, ApiReturn, Error,
};
@ -48,11 +49,20 @@ pub async fn create_request(
Json(req): Json<CreateDomain>,
) -> impl IntoResponse {
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,
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
.create_domain(Domain::new(req.name, req.tld, user.id))
.await

View file

@ -7,7 +7,7 @@ use crate::{
};
use axum::{extract::Path, response::IntoResponse, Extension, Json};
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(
Path(id): Path<usize>,
@ -47,11 +47,20 @@ pub async fn create_request(
Json(req): Json<CreateService>,
) -> impl IntoResponse {
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,
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 {
Ok(x) => Json(ApiReturn {
ok: true,