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