Skip to main content

open_library_api_rs/models/
work.rs

1// v0.0.1
2use serde::{Deserialize, Serialize};
3
4use super::common::{Key, Link, TextOrValue};
5
6/// A Work is a top-level creative entity (e.g. a novel).
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Work {
9    pub key: String,
10    #[serde(default)]
11    pub title: Option<String>,
12    #[serde(default)]
13    pub subtitle: Option<String>,
14    #[serde(default)]
15    pub description: Option<TextOrValue>,
16    #[serde(default)]
17    pub authors: Option<Vec<WorkAuthorRef>>,
18    #[serde(default)]
19    pub subjects: Option<Vec<String>>,
20    #[serde(default)]
21    pub subject_places: Option<Vec<String>>,
22    #[serde(default)]
23    pub subject_people: Option<Vec<String>>,
24    #[serde(default)]
25    pub subject_times: Option<Vec<String>>,
26    #[serde(default)]
27    pub covers: Option<Vec<i64>>,
28    #[serde(default)]
29    pub links: Option<Vec<Link>>,
30    #[serde(default)]
31    pub first_publish_date: Option<String>,
32    #[serde(default)]
33    pub created: Option<DateValue>,
34    #[serde(default)]
35    pub last_modified: Option<DateValue>,
36    #[serde(default)]
37    pub latest_revision: Option<i64>,
38    #[serde(default)]
39    pub revision: Option<i64>,
40}
41
42/// Author reference inside a Work.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct WorkAuthorRef {
45    pub author: Key,
46    #[serde(rename = "type")]
47    #[serde(default)]
48    pub role: Option<Key>,
49}
50
51/// Timestamp wrapper used by the Open Library API for `created` / `last_modified`.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct DateValue {
54    #[serde(rename = "type")]
55    pub kind: String,
56    pub value: String,
57}
58
59/// Response from `GET /works/{id}/editions.json`.
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct WorkEditions {
62    #[serde(default)]
63    pub entries: Vec<WorkEditionEntry>,
64    #[serde(default)]
65    pub size: Option<u64>,
66    #[serde(default)]
67    pub links: Option<super::common::PaginationLinks>,
68}
69
70/// A minimal edition entry returned in the work editions list.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct WorkEditionEntry {
73    pub key: String,
74    #[serde(default)]
75    pub title: Option<String>,
76    #[serde(default)]
77    pub covers: Option<Vec<i64>>,
78    #[serde(default)]
79    pub languages: Option<Vec<Key>>,
80    #[serde(default)]
81    pub publish_date: Option<String>,
82    #[serde(default)]
83    pub publishers: Option<Vec<String>>,
84    #[serde(default)]
85    pub isbn_10: Option<Vec<String>>,
86    #[serde(default)]
87    pub isbn_13: Option<Vec<String>>,
88}
89
90/// Response from `GET /works/{id}/ratings.json`.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct WorkRatings {
93    #[serde(default)]
94    pub summary: Option<RatingsSummary>,
95    #[serde(default)]
96    pub counts: Option<RatingsCounts>,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct RatingsSummary {
101    #[serde(default)]
102    pub average: Option<f64>,
103    #[serde(default)]
104    pub count: Option<u64>,
105    #[serde(default)]
106    pub sortable: Option<f64>,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct RatingsCounts {
111    #[serde(rename = "1", default)]
112    pub one: Option<u64>,
113    #[serde(rename = "2", default)]
114    pub two: Option<u64>,
115    #[serde(rename = "3", default)]
116    pub three: Option<u64>,
117    #[serde(rename = "4", default)]
118    pub four: Option<u64>,
119    #[serde(rename = "5", default)]
120    pub five: Option<u64>,
121}
122
123/// Response from `GET /works/{id}/bookshelves.json`.
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct WorkBookshelves {
126    #[serde(default)]
127    pub counts: Option<BookshelfCounts>,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct BookshelfCounts {
132    #[serde(default)]
133    pub want_to_read: Option<u64>,
134    #[serde(default)]
135    pub currently_reading: Option<u64>,
136    #[serde(default)]
137    pub already_read: Option<u64>,
138}