shared/domain/
pdf.rs

1//! Types for Pdf files.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::api::endpoints::PathPart;
7
8/// Types for user Pdf library.
9pub mod user {
10    use crate::api::endpoints::PathPart;
11    use macros::make_path_parts;
12    use serde::{Deserialize, Serialize};
13
14    use super::PdfId;
15
16    make_path_parts!(UserPdfListPath => "/v1/user/me/pdf");
17
18    /// Response for listing.
19    #[derive(Serialize, Deserialize, Debug)]
20    pub struct UserPdfListResponse {
21        /// the Pdf files returned.
22        pub pdf_files: Vec<UserPdfResponse>,
23    }
24
25    make_path_parts!(UserPdfGetPath => "/v1/user/me/pdf/{}" => PdfId);
26
27    /// Response for getting a single Pdf file.
28    #[derive(Serialize, Deserialize, Debug)]
29    pub struct UserPdfResponse {
30        /// The Pdf file's metadata.
31        pub metadata: UserPdf,
32    }
33
34    /// Over the wire representation of an Pdf file's metadata.
35    #[derive(Serialize, Deserialize, Debug)]
36    pub struct UserPdf {
37        /// The Pdf file's ID.
38        pub id: PdfId,
39        // more fields to be added
40    }
41
42    make_path_parts!(UserPdfCreatePath => "/v1/user/me/pdf");
43
44    make_path_parts!(UserPdfUploadPath => "/v1/user/me/pdf/{}/raw" => PdfId);
45
46    /// Request indicating the size of an image for upload.
47    #[derive(Serialize, Deserialize, Debug)]
48    pub struct UserPdfUploadRequest {
49        /// The size of the Pdf to be uploaded in bytes. Allows the API server to check that the file size is
50        /// within limits and as a verification at GCS that the entire file was uploaded
51        pub file_size: usize,
52    }
53
54    /// URL to upload an Pdf. Supports resumable uploading.
55    #[derive(Serialize, Deserialize, Debug)]
56    pub struct UserPdfUploadResponse {
57        /// The session URI used for uploading, including the query for uploader ID
58        pub session_uri: String,
59    }
60
61    make_path_parts!(UserPdfDeletePath => "/v1/user/me/pdf/{}" => PdfId);
62}
63
64wrap_uuid! {
65    /// Wrapper type around [`Uuid`](Uuid), represents the ID of an Pdf file.
66    pub struct PdfId
67}
68
69/// Response for getting a single Pdf file.
70#[derive(Serialize, Deserialize, Debug)]
71pub struct PdfResponse {
72    /// The Pdf's metadata.
73    pub metadata: PdfMetadata,
74}
75
76/// Over the wire representation of an Pdf file's metadata.
77#[derive(Serialize, Deserialize, Debug)]
78pub struct PdfMetadata {
79    /// The Pdf's ID.
80    pub id: PdfId,
81
82    /// The name of the Pdf.
83    pub name: String,
84
85    /// The description of the Pdf file.
86    pub description: String,
87
88    /// When the Pdf should be considered published (if at all).
89    pub publish_at: Option<DateTime<Utc>>,
90
91    /// When the Pdf was originally created.
92    pub created_at: DateTime<Utc>,
93
94    /// When the Pdf was last updated.
95    pub updated_at: Option<DateTime<Utc>>,
96}