Skip to content

Commit

Permalink
add GET /v1/me
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Mar 1, 2024
1 parent f9cb0c2 commit 42d459e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/endpoints/developers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -194,3 +197,18 @@ pub async fn get_own_mods(
payload: mods,
}))
}

#[get("v1/me")]
pub async fn get_me(auth: Auth) -> Result<impl Responder, ApiError> {
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,
},
}))
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
9 changes: 9 additions & 0 deletions src/types/models/developer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 42d459e

Please sign in to comment.