-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Group & GroupAuditLogs model & query #7
Changes from 3 commits
29a839e
1bd5a79
3c1cb8f
ab3bc22
e6c4dec
4571ecb
6345d00
0682208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
use either::Either; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::id::User; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Details about a VRC group | ||
pub struct Group { | ||
/// The unique identifier for the group. | ||
pub id: String, | ||
/// The name of the group. | ||
pub name: String, | ||
/// The short code associated with the group. | ||
pub short_code: String, | ||
/// The discriminator for the group. | ||
pub discriminator: String, | ||
/// The description of the group. | ||
pub description: String, | ||
/// The unique identifier for the group's icon. | ||
pub icon_id: String, | ||
/// The URL of the group's icon. | ||
pub icon_url: String, | ||
/// The unique identifier for the group's banner. | ||
pub banner_id: String, | ||
/// The URL of the group's banner. | ||
pub banner_url: String, | ||
/// The privacy setting of the group. | ||
pub privacy: String, | ||
/// The unique identifier of the owner of the group. | ||
pub owner_id: String, | ||
/// The rules associated with the group. | ||
pub rules: String, | ||
/// The list of links associated with the group. | ||
pub links: Vec<String>, | ||
/// The list of languages associated with the group. | ||
pub languages: Vec<String>, | ||
/// The count of members in the group. | ||
pub member_count: i64, | ||
/// The times tamp when the member count was last synchronized. | ||
pub member_count_synced_at: String, | ||
/// Indicates whether the group is verified. | ||
pub is_verified: bool, | ||
/// The join state of the group. | ||
pub join_state: String, | ||
// pub tags: Vec<Value>, | ||
// pub galleries: Vec<Value>, | ||
/// The time stamp when the group was created. | ||
pub created_at: String, | ||
/// The count of online members in the group. | ||
pub online_member_count: i64, | ||
/// The membership status of the user. | ||
pub membership_status: String, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents a collection of group audit logs. | ||
pub struct GroupAuditLogs { | ||
/// The list of group audit logs. | ||
pub results: Vec<GroupAuditLog>, | ||
/// The total count of audit logs. | ||
pub total_count: usize, | ||
/// Indicates whether there are more audit logs. | ||
pub has_next: bool, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents a single group audit log entry. | ||
pub struct GroupAuditLog { | ||
/// The unique identifier for the audit log entry. | ||
pub id: String, | ||
/// The time stamp when the audit log entry was created. | ||
#[serde(rename = "created_at")] | ||
pub created_at: String, | ||
/// The unique identifier of the group associated with the audit log. | ||
pub group_id: String, | ||
/// The unique identifier of the actor who performed the action. | ||
pub actor_id: User, | ||
/// The display name of the actor. | ||
pub actor_displayname: Option<String>, | ||
/// The unique identifier of the target of the action. | ||
pub target_id: Option<User>, | ||
/// The type of event captured in the audit log. | ||
pub event_type: String, | ||
/// The description of the event captured in the audit log. | ||
pub description: String, | ||
/// Additional data associated with the audit log entry. | ||
pub data: Data, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents additional data associated with a group audit log entry. | ||
pub struct Data { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is just re-exported from |
||
/// The description change associated with the audit log entry. | ||
#[serde(default, with = "either::serde_untagged_optional")] | ||
pub description: Option<Either<DescriptionChange, String>>, | ||
/// The join state change associated with the audit log entry. | ||
#[serde(default, with = "either::serde_untagged_optional")] | ||
pub join_state: Option<Either<JoinStateChange, String>>, | ||
/// The order change associated with the audit log entry. | ||
#[serde(default, with = "either::serde_untagged_optional")] | ||
pub order: Option<Either<OrderChange, u32>>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents a change in description associated with a group audit log entry. | ||
pub struct DescriptionChange { | ||
/// The old description before the change. | ||
pub old: String, | ||
/// The new description after the change. | ||
pub new: String, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents a change in join state associated with a group audit log entry. | ||
pub struct JoinStateChange { | ||
/// The old join state before the change. | ||
pub old: String, | ||
/// The new join state after the change. | ||
pub new: String, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
/// Represents a change in order associated with a group audit log entry. | ||
pub struct OrderChange { | ||
/// The old order before the change. | ||
pub old: u32, | ||
/// The new order after the change. | ||
pub new: u32, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't these be unified under a common |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use racal::Queryable; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::Authentication; | ||
|
||
/// Gets information about a specific group | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] | ||
pub struct Group { | ||
/// The ID of the group to get information about | ||
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()) | ||
} | ||
} | ||
|
||
/// Gets audit logs from a specific group | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] | ||
pub struct GroupAuditLogs { | ||
/// The ID of the group to get audit logs from | ||
pub id: crate::id::Group, | ||
/// The count of how many logs to get (1 - 100) | ||
pub n: Option<u8>, | ||
/// The offset of how many logs to get | ||
pub offset: Option<usize>, | ||
// TODO: startDate & endDate | ||
} | ||
|
||
impl Queryable<Authentication, crate::model::GroupAuditLogs> | ||
for GroupAuditLogs | ||
{ | ||
fn url(&self, _: &Authentication) -> String { | ||
let mut query = | ||
format!("{}/groups/{}/auditLogs?", crate::API_BASE_URI, self.id.as_ref()); | ||
|
||
if let Some(n) = self.n { | ||
let param = format!("&n={n}"); | ||
query.push_str(¶m); | ||
} | ||
|
||
if let Some(offset) = self.offset { | ||
let param = format!("&offset={offset}"); | ||
query.push_str(¶m); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This'd result in |
||
|
||
query | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...I guess it indeed is better to support a case where the member counts are negative for whatever reason, even though on first thought it seemed wrong 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol I think that's just what Json -> Serde defaulted to