#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModerationCategory {
pub id: String,
pub flagged: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModerationResponse {
pub flagged: bool,
pub categories: Vec<ModerationCategory>,
}
impl ModerationResponse {
pub fn is_flagged(&self, category: &str) -> bool {
self.categories
.iter()
.any(|c| c.id == category && c.flagged)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_flagged() {
let response = ModerationResponse {
flagged: true,
categories: vec![
ModerationCategory {
id: "harassment".into(),
flagged: false,
},
ModerationCategory {
id: "violence".into(),
flagged: true,
},
],
};
assert!(response.is_flagged("violence"));
assert!(!response.is_flagged("harassment"));
assert!(!response.is_flagged("missing"));
}
}