backbone_bucket/domain/entity/
file_status.rs1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "file_status", rename_all = "snake_case")]
11pub enum FileStatus {
12 Uploading,
13 Processing,
14 Active,
15 Quarantined,
16 Deleted,
17 Purged,
18}
19
20impl std::fmt::Display for FileStatus {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 Self::Uploading => write!(f, "uploading"),
24 Self::Processing => write!(f, "processing"),
25 Self::Active => write!(f, "active"),
26 Self::Quarantined => write!(f, "quarantined"),
27 Self::Deleted => write!(f, "deleted"),
28 Self::Purged => write!(f, "purged"),
29 }
30 }
31}
32
33impl FromStr for FileStatus {
34 type Err = String;
35
36 fn from_str(s: &str) -> Result<Self, Self::Err> {
37 match s.to_lowercase().as_str() {
38 "uploading" => Ok(Self::Uploading),
39 "processing" => Ok(Self::Processing),
40 "active" => Ok(Self::Active),
41 "quarantined" => Ok(Self::Quarantined),
42 "deleted" => Ok(Self::Deleted),
43 "purged" => Ok(Self::Purged),
44 _ => Err(format!("Unknown FileStatus variant: {}", s)),
45 }
46 }
47}
48
49impl Default for FileStatus {
50 fn default() -> Self {
51 Self::Active
52 }
53}