relay_knowledge/domain/operations/software/
request.rs1use serde::{Deserialize, Serialize};
2
3use super::super::{CodeRepositorySelector, DomainError, FreshnessPolicy};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum SoftwareGlobalKind {
9 Dependencies,
10 Sdks,
11 Files,
12 Topics,
13 Relationships,
14 Build,
15 Iac,
16 Design,
17 All,
18}
19
20impl SoftwareGlobalKind {
21 pub const fn as_str(self) -> &'static str {
23 match self {
24 Self::Dependencies => "dependencies",
25 Self::Sdks => "sdks",
26 Self::Files => "files",
27 Self::Topics => "topics",
28 Self::Relationships => "relationships",
29 Self::Build => "build",
30 Self::Iac => "iac",
31 Self::Design => "design",
32 Self::All => "all",
33 }
34 }
35}
36
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39pub struct SoftwareGlobalRequest {
40 pub repository: CodeRepositorySelector,
41 pub kind: SoftwareGlobalKind,
42 pub freshness_policy: FreshnessPolicy,
43 pub limit: usize,
44}
45
46impl SoftwareGlobalRequest {
47 pub fn new(
49 repository: CodeRepositorySelector,
50 kind: SoftwareGlobalKind,
51 freshness_policy: FreshnessPolicy,
52 limit: usize,
53 ) -> Result<Self, DomainError> {
54 let limit = match limit {
55 1..=500 => limit,
56 0 => return Err(DomainError::invalid("limit", "must be greater than zero")),
57 _ => return Err(DomainError::invalid("limit", "must be 500 or less")),
58 };
59
60 Ok(Self {
61 repository,
62 kind,
63 freshness_policy,
64 limit,
65 })
66 }
67}
68
69#[cfg(test)]
70#[path = "request_tests.rs"]
71mod tests;