kellnr_docs/
doc_queue_response.rs1use kellnr_db::DocQueueEntry;
2use serde::{Deserialize, Serialize};
3use utoipa::ToSchema;
4
5#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, ToSchema)]
7pub struct DocQueueResponse {
8 pub(crate) queue: Vec<DocQueueEntryResponse>,
10}
11
12#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, ToSchema)]
14pub struct DocQueueEntryResponse {
15 pub(crate) name: String,
17 pub(crate) version: String,
19}
20
21impl From<Vec<DocQueueEntry>> for DocQueueResponse {
22 fn from(entries: Vec<DocQueueEntry>) -> Self {
23 Self {
24 queue: entries
25 .into_iter()
26 .map(|e| DocQueueEntryResponse {
27 name: e.normalized_name.to_string(),
28 version: e.version,
29 })
30 .collect(),
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use std::path::PathBuf;
38
39 use kellnr_common::normalized_name::NormalizedName;
40
41 use super::*;
42
43 #[test]
44 fn doc_queue_response_from_doc_queue_entry() {
45 let doc_queue = vec![
46 DocQueueEntry {
47 id: 0,
48 normalized_name: NormalizedName::from_unchecked("crate1".to_string()),
49 version: "0.0.1".to_string(),
50 path: PathBuf::default(),
51 },
52 DocQueueEntry {
53 id: 1,
54 normalized_name: NormalizedName::from_unchecked("crate2".to_string()),
55 version: "0.0.2".to_string(),
56 path: PathBuf::default(),
57 },
58 ];
59
60 let doc_queue_response = DocQueueResponse::from(doc_queue);
61
62 assert_eq!(
63 DocQueueResponse {
64 queue: vec![
65 DocQueueEntryResponse {
66 name: "crate1".to_string(),
67 version: "0.0.1".to_string()
68 },
69 DocQueueEntryResponse {
70 name: "crate2".to_string(),
71 version: "0.0.2".to_string()
72 }
73 ]
74 },
75 doc_queue_response
76 );
77 }
78}