Skip to main content

crossref_lib/
models.rs

1use std::collections::BTreeMap;
2
3use derive_builder::Builder;
4use serde::{Deserialize, Serialize};
5
6/// Normalised metadata for a single publication, populated from the Crossref
7/// `Work` response and optionally enriched with Unpaywall OA data.
8#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
9#[builder(setter(into), default)]
10#[derive(Default)]
11pub struct WorkMeta {
12    pub doi: String,
13    pub title: Option<String>,
14    pub authors: Vec<String>,
15    pub year: Option<i32>,
16    /// Journal / book title (first element of `container-title`)
17    pub journal: Option<String>,
18    pub volume: Option<String>,
19    pub issue: Option<String>,
20    /// Page range, e.g. "123-145"
21    pub pages: Option<String>,
22    pub publisher: Option<String>,
23    /// Crossref type string, e.g. "journal-article"
24    pub work_type: Option<String>,
25    // Unpaywall OA fields
26    pub is_oa: Option<bool>,
27    pub oa_status: Option<String>,
28    pub pdf_url: Option<String>,
29}
30
31
32/// A single BibTeX entry in a format compatible with `serde_bibtex` serialization.
33/// Fields use `BTreeMap` so the output is deterministically ordered.
34#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
35#[builder(setter(into), default)]
36#[derive(Default)]
37pub struct BibRecord {
38    pub entry_type: String,
39    pub entry_key: String,
40    pub fields: BTreeMap<String, String>,
41}
42
43
44/// Parameters for a Crossref works search request.
45#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
46#[builder(setter(into), default)]
47pub struct SearchQuery {
48    pub query: Option<String>,
49    pub title: Option<String>,
50    pub author: Option<String>,
51    pub year_from: Option<i32>,
52    pub year_to: Option<i32>,
53    /// Crossref type filter, e.g. "journal-article"
54    pub work_type: Option<String>,
55    pub open_access: bool,
56    pub rows: u32,
57    pub sort: Option<String>,
58}
59
60impl Default for SearchQuery {
61    fn default() -> Self {
62        Self {
63            query: None,
64            title: None,
65            author: None,
66            year_from: None,
67            year_to: None,
68            work_type: None,
69            open_access: false,
70            rows: 10,
71            sort: None,
72        }
73    }
74}
75
76/// Paged result set returned by a search request.
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct SearchResult {
79    pub items: Vec<WorkMeta>,
80    pub total_results: u64,
81}