From 42d459eb8dbc15f0eaa7e38b8d9944f7691076d6 Mon Sep 17 00:00:00 2001 From: Fleeym <61891787+Fleeym@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:56:28 +0200 Subject: [PATCH] add GET /v1/me --- src/endpoints/developers.rs | 20 +++++++++++++++++++- src/main.rs | 1 + src/types/models/developer.rs | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/endpoints/developers.rs b/src/endpoints/developers.rs index b741a92..2a03d1d 100644 --- a/src/endpoints/developers.rs +++ b/src/endpoints/developers.rs @@ -7,7 +7,10 @@ use crate::{ extractors::auth::Auth, types::{ api::{ApiError, ApiResponse}, - models::{developer::Developer, mod_entity::Mod}, + models::{ + developer::{Developer, DeveloperProfile}, + mod_entity::Mod, + }, }, AppData, }; @@ -194,3 +197,18 @@ pub async fn get_own_mods( payload: mods, })) } + +#[get("v1/me")] +pub async fn get_me(auth: Auth) -> Result { + let dev = auth.into_developer()?; + Ok(HttpResponse::Ok().json(ApiResponse { + error: "".to_string(), + payload: DeveloperProfile { + id: dev.id, + username: dev.username, + display_name: dev.display_name, + verified: dev.verified, + admin: dev.admin, + }, + })) +} diff --git a/src/main.rs b/src/main.rs index 7faa96c..fdbd336 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,6 +101,7 @@ async fn main() -> anyhow::Result<()> { .service(endpoints::developers::delete_tokens) .service(endpoints::developers::update_profile) .service(endpoints::developers::get_own_mods) + .service(endpoints::developers::get_me) .service(endpoints::tags::index) .service(health) }) diff --git a/src/types/models/developer.rs b/src/types/models/developer.rs index 2e8337e..e20df56 100644 --- a/src/types/models/developer.rs +++ b/src/types/models/developer.rs @@ -13,6 +13,15 @@ pub struct Developer { pub is_owner: bool, } +#[derive(Serialize, Clone)] +pub struct DeveloperProfile { + pub id: i32, + pub username: String, + pub display_name: String, + pub verified: bool, + pub admin: bool, +} + pub struct FetchedDeveloper { pub id: i32, pub username: String,