2022-11-10 17:27:10 -05:00
|
|
|
pub enum EventResultStatus {
|
|
|
|
Saved,
|
|
|
|
Duplicate,
|
|
|
|
Invalid,
|
|
|
|
Blocked,
|
|
|
|
RateLimited,
|
|
|
|
Error,
|
2023-06-25 05:02:44 -04:00
|
|
|
Restricted,
|
2022-11-10 17:27:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct EventResult {
|
|
|
|
pub id: String,
|
|
|
|
pub msg: String,
|
|
|
|
pub status: EventResultStatus,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Notice {
|
|
|
|
Message(String),
|
|
|
|
EventResult(EventResult),
|
2023-02-25 15:49:35 -05:00
|
|
|
AuthChallenge(String),
|
2022-11-10 17:27:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EventResultStatus {
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn to_bool(&self) -> bool {
|
2022-11-10 17:27:10 -05:00
|
|
|
match self {
|
2023-01-22 10:49:49 -05:00
|
|
|
Self::Duplicate | Self::Saved => true,
|
2023-06-25 05:02:44 -04:00
|
|
|
Self::Invalid | Self::Blocked | Self::RateLimited | Self::Error | Self::Restricted => false,
|
2022-11-10 17:27:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn prefix(&self) -> &'static str {
|
2022-11-10 17:27:10 -05:00
|
|
|
match self {
|
|
|
|
Self::Saved => "saved",
|
|
|
|
Self::Duplicate => "duplicate",
|
|
|
|
Self::Invalid => "invalid",
|
|
|
|
Self::Blocked => "blocked",
|
|
|
|
Self::RateLimited => "rate-limited",
|
|
|
|
Self::Error => "error",
|
2023-06-25 05:02:44 -04:00
|
|
|
Self::Restricted => "restricted",
|
2022-11-10 17:27:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Notice {
|
|
|
|
//pub fn err(err: error::Error, id: String) -> Notice {
|
|
|
|
// Notice::err_msg(format!("{}", err), id)
|
|
|
|
//}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn message(msg: String) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::Message(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn prefixed(id: String, msg: &str, status: EventResultStatus) -> Notice {
|
|
|
|
let msg = format!("{}: {}", status.prefix(), msg);
|
|
|
|
Notice::EventResult(EventResult { id, msg, status })
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn invalid(id: String, msg: &str) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::prefixed(id, msg, EventResultStatus::Invalid)
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn blocked(id: String, msg: &str) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::prefixed(id, msg, EventResultStatus::Blocked)
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn rate_limited(id: String, msg: &str) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::prefixed(id, msg, EventResultStatus::RateLimited)
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn duplicate(id: String) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::prefixed(id, "", EventResultStatus::Duplicate)
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn error(id: String, msg: &str) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::prefixed(id, msg, EventResultStatus::Error)
|
|
|
|
}
|
|
|
|
|
2023-06-25 05:02:44 -04:00
|
|
|
#[must_use]
|
|
|
|
pub fn restricted(id: String, msg: &str) -> Notice {
|
|
|
|
Notice::prefixed(id, msg, EventResultStatus::Restricted)
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:55:17 -05:00
|
|
|
#[must_use]
|
|
|
|
pub fn saved(id: String) -> Notice {
|
2022-11-10 17:27:10 -05:00
|
|
|
Notice::EventResult(EventResult {
|
|
|
|
id,
|
|
|
|
msg: "".into(),
|
|
|
|
status: EventResultStatus::Saved,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|