cloudillo_profile/
handler.rs1use axum::{extract::State, http::StatusCode, Json};
2
3use crate::prelude::*;
4use cloudillo_core::extract::OptionalRequestId;
5use cloudillo_core::IdTag;
6use cloudillo_types::types::{ApiResponse, Profile};
7
8pub async fn get_tenant_profile(
9 State(app): State<App>,
10 IdTag(id_tag): IdTag,
11 OptionalRequestId(req_id): OptionalRequestId,
12) -> ClResult<(StatusCode, Json<ApiResponse<Profile>>)> {
13 let auth_profile = app.auth_adapter.read_tenant(&id_tag).await?;
14 let tn_id = app.auth_adapter.read_tn_id(&id_tag).await?;
15 let tenant_meta = app.meta_adapter.read_tenant(tn_id).await?;
16
17 let typ = match tenant_meta.typ {
19 cloudillo_types::meta_adapter::ProfileType::Person => "person",
20 cloudillo_types::meta_adapter::ProfileType::Community => "community",
21 };
22
23 let profile = Profile {
24 id_tag: auth_profile.id_tag.to_string(),
25 name: tenant_meta.name.to_string(),
26 r#type: typ.to_string(),
27 profile_pic: tenant_meta.profile_pic.map(|s| s.to_string()),
28 cover_pic: tenant_meta.cover_pic.map(|s| s.to_string()),
29 keys: auth_profile.keys,
30 };
31
32 let mut response = ApiResponse::new(profile);
33 if let Some(id) = req_id {
34 response = response.with_req_id(id);
35 }
36
37 Ok((StatusCode::OK, Json(response)))
38}
39
40