soar_core/database/packages/
models.rs1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone)]
6pub enum FilterCondition {
7 Eq(String),
8 Ne(String),
9 Gt(String),
10 Gte(String),
11 Lt(String),
12 Lte(String),
13 Like(String),
14 ILike(String),
15 In(Vec<String>),
16 NotIn(Vec<String>),
17 Between(String, String),
18 IsNull,
19 IsNotNull,
20 None,
21}
22
23#[derive(Debug, Default, Clone)]
24pub enum SortDirection {
25 #[default]
26 Asc,
27 Desc,
28}
29
30#[derive(Clone, Debug)]
31pub enum LogicalOp {
32 And,
33 Or,
34}
35
36#[derive(Clone, Debug)]
37pub struct QueryFilter {
38 pub field: String,
39 pub condition: FilterCondition,
40 pub logical_op: Option<LogicalOp>,
41}
42
43#[derive(Debug)]
44pub struct PaginatedResponse<T> {
45 pub items: Vec<T>,
46 pub page: u32,
47 pub limit: Option<u32>,
48 pub total: u64,
49 pub has_next: bool,
50}
51
52#[derive(Debug, Clone, Deserialize, Serialize)]
53pub enum ProvideStrategy {
54 KeepTargetOnly,
55 KeepBoth,
56 Alias,
57}
58
59impl Display for ProvideStrategy {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 let msg = match self {
62 ProvideStrategy::KeepTargetOnly => "=>",
63 ProvideStrategy::KeepBoth => "==",
64 ProvideStrategy::Alias => ":",
65 };
66 write!(f, "{msg}")
67 }
68}
69
70#[derive(Debug, Default, Deserialize, Serialize, Clone)]
71pub struct PackageProvide {
72 pub name: String,
73 pub target: Option<String>,
74 pub strategy: Option<ProvideStrategy>,
75}
76
77impl PackageProvide {
78 pub fn from_string(provide: &str) -> Self {
79 if let Some((name, target_name)) = provide.split_once("==") {
80 Self {
81 name: name.to_string(),
82 target: Some(target_name.to_string()),
83 strategy: Some(ProvideStrategy::KeepBoth),
84 }
85 } else if let Some((name, target_name)) = provide.split_once("=>") {
86 Self {
87 name: name.to_string(),
88 target: Some(target_name.to_string()),
89 strategy: Some(ProvideStrategy::KeepTargetOnly),
90 }
91 } else if let Some((name, target_name)) = provide.split_once(":") {
92 Self {
93 name: name.to_string(),
94 target: Some(target_name.to_string()),
95 strategy: Some(ProvideStrategy::Alias),
96 }
97 } else {
98 Self {
99 name: provide.to_string(),
100 target: None,
101 strategy: None,
102 }
103 }
104 }
105}