Skip to main content

tmdb_rs/endpoints/
list.rs

1use serde::Deserialize;
2
3use crate::common::StatusResponse;
4use crate::endpoints::search::MultiResult;
5use crate::{Language, Poster, SessionId};
6
7/// the kind of items a v3 list holds
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum ListType {
11    Movie,
12    Tv,
13}
14
15/// one list in a list-of-lists response
16#[derive(Debug, Clone, Deserialize)]
17pub struct ListShort {
18    pub id: u64,
19    pub name: String,
20    pub description: String,
21    pub item_count: u32,
22    #[serde(rename = "iso_639_1")]
23    pub language: Option<Language>,
24    pub list_type: Option<ListType>,
25    #[serde(rename = "poster_path")]
26    pub poster: Option<Poster>,
27    pub favorite: Option<bool>,
28}
29
30/// a v3 list and its items
31#[derive(Debug, Clone, Deserialize)]
32pub struct ListDetails {
33    pub id: String,
34    pub name: String,
35    pub description: String,
36    pub item_count: u32,
37    #[serde(rename = "iso_639_1")]
38    pub language: Option<Language>,
39    pub list_type: Option<ListType>,
40    #[serde(rename = "poster_path")]
41    pub poster: Option<Poster>,
42    pub favorite: bool,
43    #[serde(default)]
44    pub items: Vec<MultiResult>,
45    #[serde(default)]
46    pub total_pages: u32,
47    #[serde(default)]
48    pub total_results: u64,
49    #[serde(default)]
50    pub page: u32,
51}
52
53/// the answer of `item_status`
54#[derive(Debug, Clone, Deserialize)]
55pub struct ItemStatus {
56    pub id: String,
57    pub item_present: bool,
58    pub media_type: Option<String>,
59    pub media_id: Option<u64>,
60}
61
62/// the answer of a list creation
63#[derive(Debug, Clone, Deserialize)]
64pub struct CreateListResponse {
65    pub success: bool,
66    pub status_code: i32,
67    pub status_message: String,
68    pub list_id: Option<u64>,
69}
70
71endpoint! {
72    /// a list and its items
73    list(id: u64, session_id: SessionId): GET "/list/{id}" => ListDetails {
74        params { language: Language, page: u32 }
75    }
76}
77
78endpoint! {
79    /// whether a title is on a list
80    list_item_status(id: u64, session_id: SessionId): GET "/list/{id}/item_status" => ItemStatus {
81        params { movie_id: u64 }
82    }
83}
84
85endpoint! {
86    /// create a list
87    create_list(session_id: SessionId): POST "/list" => CreateListResponse {
88        body { name: &str, description: &str, language: &str }
89    }
90}
91
92endpoint! {
93    /// add a title to a list
94    list_add_item(id: u64, session_id: SessionId): POST "/list/{id}/add_item" => StatusResponse {
95        body { media_id: u64 }
96    }
97}
98
99endpoint! {
100    /// remove a title from a list
101    list_remove_item(id: u64, session_id: SessionId): POST "/list/{id}/remove_item" => StatusResponse {
102        body { media_id: u64 }
103    }
104}
105
106endpoint! {
107    /// remove every title from a list
108    list_clear(id: u64, session_id: SessionId): POST "/list/{id}/clear" => StatusResponse {
109        body { confirm: bool }
110    }
111}
112
113endpoint! {
114    /// delete a list
115    list_delete(id: u64, session_id: SessionId): DELETE "/list/{id}" => StatusResponse
116}