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. /// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error.
pub async fn create_channel( pub async fn create_channel(
&self, &self,
url_api: &str, user: &mut UserMeta,
token: &str,
schema: ChannelCreateSchema, schema: ChannelCreateSchema,
limits_user: &mut Limits,
limits_instance: &mut Limits,
) -> Result<Channel, InstanceServerError> { ) -> Result<Channel, InstanceServerError> {
Channel::create( let mut belongs_to = user.belongs_to.borrow_mut();
token, Channel::_create(
url_api, &user.token,
&format!("{}", belongs_to.urls.get_api()),
&self.id.to_string(), &self.id.to_string(),
schema, schema,
limits_user, &mut user.limits,
limits_instance, &mut belongs_to.limits,
) )
.await .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. /// A `Result` containing a `reqwest::Response` if the request was successful, or an `InstanceServerError` if there was an error.
pub async fn create( 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, token: &str,
url_api: &str, url_api: &str,
guild_id: &str, guild_id: &str,

View File

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