feat: expose display_name, also_known_as, profile fields in GET /profile
This commit is contained in:
@@ -84,9 +84,12 @@ pub struct UserProfileResponse {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
||||||
pub struct ProfileResponse {
|
pub struct ProfileResponse {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
pub banner_url: Option<String>,
|
pub banner_url: Option<String>,
|
||||||
|
pub also_known_as: Option<String>,
|
||||||
|
pub fields: Vec<ProfileFieldDto>,
|
||||||
pub role: String,
|
pub role: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,19 @@ use domain::errors::DomainError;
|
|||||||
|
|
||||||
use crate::{context::AppContext, users::queries::GetCurrentProfileQuery};
|
use crate::{context::AppContext, users::queries::GetCurrentProfileQuery};
|
||||||
|
|
||||||
|
pub struct ProfileFieldData {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CurrentProfileData {
|
pub struct CurrentProfileData {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
pub avatar_url: Option<String>,
|
pub avatar_url: Option<String>,
|
||||||
pub banner_url: Option<String>,
|
pub banner_url: Option<String>,
|
||||||
|
pub also_known_as: Option<String>,
|
||||||
|
pub fields: Vec<ProfileFieldData>,
|
||||||
pub role: String,
|
pub role: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +37,23 @@ pub async fn execute(
|
|||||||
.banner_path()
|
.banner_path()
|
||||||
.map(|path| format!("{}/images/{}", ctx.config.base_url, path));
|
.map(|path| format!("{}/images/{}", ctx.config.base_url, path));
|
||||||
|
|
||||||
|
let fields = user
|
||||||
|
.profile_fields()
|
||||||
|
.iter()
|
||||||
|
.map(|f| ProfileFieldData {
|
||||||
|
name: f.name.clone(),
|
||||||
|
value: f.value.clone(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(CurrentProfileData {
|
Ok(CurrentProfileData {
|
||||||
username: user.username().value().to_string(),
|
username: user.username().value().to_string(),
|
||||||
|
display_name: user.display_name().map(|s| s.to_string()),
|
||||||
bio: user.bio().map(|s| s.to_string()),
|
bio: user.bio().map(|s| s.to_string()),
|
||||||
avatar_url,
|
avatar_url,
|
||||||
banner_url,
|
banner_url,
|
||||||
|
also_known_as: user.also_known_as().map(|s| s.to_string()),
|
||||||
|
fields,
|
||||||
role: user.role().as_str().into(),
|
role: user.role().as_str().into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,9 +414,19 @@ pub async fn get_profile(
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(Json(ProfileResponse {
|
Ok(Json(ProfileResponse {
|
||||||
username: profile.username,
|
username: profile.username,
|
||||||
|
display_name: profile.display_name,
|
||||||
bio: profile.bio,
|
bio: profile.bio,
|
||||||
avatar_url: profile.avatar_url,
|
avatar_url: profile.avatar_url,
|
||||||
banner_url: profile.banner_url,
|
banner_url: profile.banner_url,
|
||||||
|
also_known_as: profile.also_known_as,
|
||||||
|
fields: profile
|
||||||
|
.fields
|
||||||
|
.into_iter()
|
||||||
|
.map(|f| api_types::ProfileFieldDto {
|
||||||
|
name: f.name,
|
||||||
|
value: f.value,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
role: profile.role,
|
role: profile.role,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user