use racal::Queryable;
use serde::{Deserialize, Serialize};
use super::{Authentication, Pagination};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct Group {
pub id: crate::id::Group,
}
impl Queryable<Authentication, crate::model::Group> for Group {
fn url(&self, _: &Authentication) -> String {
format!("{}/groups/{}", crate::API_BASE_URI, self.id.as_ref())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GroupAuditLogs {
pub id: crate::id::Group,
#[serde(flatten)]
pub pagination: Pagination,
}
impl Queryable<Authentication, crate::model::GroupAuditLogs>
for GroupAuditLogs
{
fn url(&self, _: &Authentication) -> String {
format!(
"{}/groups/{}/auditLogs?{}",
crate::API_BASE_URI,
self.id.as_ref(),
self.pagination.to_query_str()
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GroupBans {
pub id: crate::id::Group,
#[serde(flatten)]
pub pagination: Pagination,
}
impl Queryable<Authentication, Vec<crate::model::GroupBan>> for GroupBans {
fn url(&self, _: &Authentication) -> String {
format!(
"{}/groups/{}/bans?{}",
crate::API_BASE_URI,
self.id.as_ref(),
self.pagination.to_query_str()
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GroupBan {
pub group_id: crate::id::Group,
pub user_id: crate::id::User,
}
impl Queryable<Authentication, crate::model::GroupBan> for GroupBan {
fn url(&self, _: &Authentication) -> String {
format!("{}/groups/{}/bans", crate::API_BASE_URI, self.group_id.as_ref(),)
}
fn body(
&self, _state: &Authentication,
) -> Option<serde_json::Result<Vec<u8>>> {
Some(serde_json::to_vec(
&serde_json::json!({ "userId": self.user_id.as_ref() }),
))
}
fn method(&self, _state: &Authentication) -> racal::RequestMethod {
racal::RequestMethod::Post
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GroupUnban {
pub group_id: crate::id::Group,
pub user_id: crate::id::User,
}
impl Queryable<Authentication, crate::model::GroupBan> for GroupUnban {
fn url(&self, _: &Authentication) -> String {
format!(
"{}/groups/{}/bans/{}",
crate::API_BASE_URI,
self.group_id.as_ref(),
self.user_id.as_ref()
)
}
fn method(&self, _state: &Authentication) -> racal::RequestMethod {
racal::RequestMethod::Delete
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GroupMember {
pub group_id: crate::id::Group,
pub user_id: crate::id::User,
}
impl Queryable<Authentication, Option<crate::model::GroupMember>>
for GroupMember
{
fn url(&self, _: &Authentication) -> String {
format!(
"{}/groups/{}/members/{}",
crate::API_BASE_URI,
self.group_id.as_ref(),
self.user_id.as_ref()
)
}
}