Skip to main content

entrenar/research/archive/
result.rs

1//! Deposit result and error types.
2
3use serde::{Deserialize, Serialize};
4
5use super::provider::ArchiveProvider;
6use super::DOI_REGEX;
7
8/// Result of a successful deposit
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct DepositResult {
11    /// Assigned DOI
12    pub doi: String,
13    /// Provider-specific record ID
14    pub record_id: String,
15    /// URL to the deposited record
16    pub url: String,
17    /// Provider that received the deposit
18    pub provider: ArchiveProvider,
19}
20
21impl DepositResult {
22    /// Generate URL for the deposit
23    pub fn generate_url(&self) -> String {
24        self.url.clone()
25    }
26
27    /// Generate DOI URL
28    pub fn doi_url(&self) -> String {
29        format!("https://doi.org/{}", self.doi)
30    }
31}
32
33/// Deposit errors
34#[derive(Debug, Clone, thiserror::Error)]
35pub enum DepositError {
36    #[error("No files provided for deposit")]
37    NoFiles,
38    #[error("Authentication failed")]
39    AuthenticationFailed,
40    #[error("Invalid metadata: {0}")]
41    InvalidMetadata(String),
42    #[error("Upload failed: {0}")]
43    UploadFailed(String),
44    #[error("API error: {0}")]
45    ApiError(String),
46}
47
48/// Validate DOI format
49pub fn validate_doi(doi: &str) -> bool {
50    DOI_REGEX.is_match(doi)
51}