Refactor create

This commit is contained in:
bitfl0wer 2023-05-29 23:57:23 +02:00
parent d8d3bf5be6
commit 3cebafecf6
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
2 changed files with 27 additions and 19 deletions

View File

@ -122,19 +122,17 @@ impl Guild {
/// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error.
pub async fn create_channel(
&self,
url_api: &str,
token: &str,
user: &mut UserMeta,
schema: ChannelCreateSchema,
limits_user: &mut Limits,
limits_instance: &mut Limits,
) -> Result<Channel, InstanceServerError> {
Channel::create(
token,
url_api,
let mut belongs_to = user.belongs_to.borrow_mut();
Channel::_create(
&user.token,
&format!("{}", belongs_to.urls.get_api()),
&self.id.to_string(),
schema,
limits_user,
limits_instance,
&mut user.limits,
&mut belongs_to.limits,
)
.await
}
@ -261,6 +259,23 @@ impl Channel {
///
/// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error.
pub async fn create(
user: &mut UserMeta,
guild_id: &str,
schema: ChannelCreateSchema,
) -> Result<Channel, InstanceServerError> {
let mut belongs_to = user.belongs_to.borrow_mut();
Channel::_create(
&user.token,
&format!("{}", belongs_to.urls.get_api()),
guild_id,
schema,
&mut user.limits,
&mut belongs_to.limits,
)
.await
}
async fn _create(
token: &str,
url_api: &str,
guild_id: &str,

View File

@ -66,16 +66,9 @@ pub async fn setup() -> TestBundle {
};
let mut user = instance.register_account(&reg).await.unwrap();
let guild = Guild::create(&mut user, guild_create_schema).await.unwrap();
let channel = Channel::create(
&user.token,
urls.get_api(),
&guild.id.to_string(),
channel_create_schema,
&mut user.limits,
&mut instance.limits,
)
.await
.unwrap();
let channel = Channel::create(&mut user, &guild.id.to_string(), channel_create_schema)
.await
.unwrap();
TestBundle {
urls,