Refactor modify() to take less boilerplate args

This commit is contained in:
bitfl0wer 2023-05-29 23:11:12 +02:00
parent 808224d4fb
commit a12573fe1c
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
2 changed files with 11 additions and 12 deletions

View File

@ -98,23 +98,25 @@ impl Channel {
/// A `Result` that contains a `Channel` object if the request was successful, or an `InstanceServerError` if an error occurred during the request.
pub async fn modify(
modify_data: ChannelModifySchema,
token: &str,
url_api: &str,
channel_id: &str,
limits_user: &mut Limits,
limits_instance: &mut Limits,
user: &mut UserMeta,
) -> Result<Channel, InstanceServerError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let request = Client::new()
.patch(format!("{}/channels/{}/", url_api, channel_id))
.bearer_auth(token)
.patch(format!(
"{}/channels/{}/",
belongs_to.urls.get_api(),
channel_id
))
.bearer_auth(user.token())
.body(to_string(&modify_data).unwrap());
let channel = match LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
limits_instance,
limits_user,
&mut belongs_to.limits,
&mut user.limits,
)
.await
{

View File

@ -48,11 +48,8 @@ async fn modify_channel() {
};
let result = Channel::modify(
modify_data,
&bundle.user.token,
bundle.instance.urls.get_api(),
&bundle.channel.id.to_string(),
&mut bundle.user.limits,
&mut bundle.instance.limits,
&mut bundle.user,
)
.await
.unwrap();