Refactor delete() to take less boilerplate args

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

View File

@ -58,23 +58,22 @@ impl Channel {
/// # Returns /// # Returns
/// ///
/// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful. /// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful.
pub async fn delete( pub async fn delete(self, user: &mut UserMeta) -> Option<InstanceServerError> {
self, let mut belongs_to = user.belongs_to.borrow_mut();
token: &str,
url_api: &str,
limits_user: &mut Limits,
limits_instance: &mut Limits,
) -> Option<InstanceServerError> {
let request = Client::new() let request = Client::new()
.delete(format!("{}/channels/{}/", url_api, self.id.to_string())) .delete(format!(
.bearer_auth(token); "{}/channels/{}/",
belongs_to.urls.get_api(),
self.id.to_string()
))
.bearer_auth(user.token());
match LimitedRequester::new() match LimitedRequester::new()
.await .await
.send_request( .send_request(
request, request,
crate::api::limits::LimitType::Channel, crate::api::limits::LimitType::Channel,
limits_instance, &mut belongs_to.limits,
limits_user, &mut user.limits,
) )
.await .await
{ {

View File

@ -19,16 +19,7 @@ async fn get_channel() {
#[tokio::test] #[tokio::test]
async fn delete_channel() { async fn delete_channel() {
let mut bundle = common::setup().await; let mut bundle = common::setup().await;
let result = bundle let result = bundle.channel.clone().delete(&mut bundle.user).await;
.channel
.clone()
.delete(
&bundle.user.token,
bundle.instance.urls.get_api(),
&mut bundle.user.limits,
&mut bundle.instance.limits,
)
.await;
assert!(result.is_none()); assert!(result.is_none());
common::teardown(bundle).await common::teardown(bundle).await
} }