client-api: Update profile endpoints to the new API standards

This commit is contained in:
Jonas Platte 2020-09-03 17:44:34 +02:00
parent d6d5ad84c1
commit e7dde6850c
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
5 changed files with 93 additions and 8 deletions

View File

@ -13,12 +13,15 @@ ruma_api! {
requires_authentication: false,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The user whose avatar URL will be retrieved.
#[ruma_api(path)]
pub user_id: UserId
pub user_id: &'a UserId,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
/// The user's avatar URL, if set.
#[serde(skip_serializing_if = "Option::is_none")]
@ -27,3 +30,17 @@ ruma_api! {
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID.
pub fn new(user_id: &'a UserId) -> Self {
Self { user_id }
}
}
impl Response {
/// Creates a new `Response` with the given avatar URL.
pub fn new(avatar_url: Option<String>) -> Self {
Self { avatar_url }
}
}

View File

@ -13,17 +13,34 @@ ruma_api! {
requires_authentication: false,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The user whose display name will be retrieved.
#[ruma_api(path)]
pub user_id: UserId
pub user_id: &'a UserId,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
/// The user's display name, if set.
#[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String>
pub displayname: Option<String>,
}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID.
pub fn new(user_id: &'a UserId) -> Self {
Self { user_id }
}
}
impl Response {
/// Creates a new `Response` with the given display name.
pub fn new(displayname: Option<String>) -> Self {
Self { displayname }
}
}

View File

@ -13,12 +13,15 @@ ruma_api! {
requires_authentication: false,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The user whose profile will be retrieved.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {
/// The user's avatar URL, if set.
#[serde(skip_serializing_if = "Option::is_none")]
@ -31,3 +34,17 @@ ruma_api! {
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID.
pub fn new(user_id: &'a UserId) -> Self {
Self { user_id }
}
}
impl Response {
/// Creates a new `Response` with the given avatar URL and display name.
pub fn new(avatar_url: Option<String>, displayname: Option<String>) -> Self {
Self { avatar_url, displayname }
}
}

View File

@ -13,18 +13,35 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The user whose avatar URL will be set.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
/// The new avatar URL for the user.
///
/// `None` is used to unset the avatar.
pub avatar_url: Option<String>,
pub avatar_url: Option<&'a str>,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID and avatar URL.
pub fn new(user_id: &'a UserId, avatar_url: Option<&'a str>) -> Self {
Self { user_id, avatar_url }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}

View File

@ -13,17 +13,34 @@ ruma_api! {
requires_authentication: true,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
request: {
/// The user whose display name will be set.
#[ruma_api(path)]
pub user_id: UserId,
pub user_id: &'a UserId,
/// The new display name for the user.
#[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String>,
pub displayname: Option<&'a str>,
}
#[derive(Default)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
response: {}
error: crate::Error
}
impl<'a> Request<'a> {
/// Creates a new `Request` with the given user ID and display name.
pub fn new(user_id: &'a UserId, displayname: Option<&'a str>) -> Self {
Self { user_id, displayname }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self
}
}