shared/api/
endpoints.rs

1use std::error::Error;
2
3use crate::api::Method;
4pub use macros::{make_path_parts, PathPart};
5use serde::{de::DeserializeOwned, Serialize};
6use url::Url;
7use uuid::Uuid;
8
9//  add something for auth required?
10
11/// Represents a A endpoint that the backend will support, and how to call it.
12pub trait ApiEndpoint {
13    /// The path type for this endpoint.
14    type Path: PathParts;
15
16    /// The request type for this endpoint.
17    type Req: Serialize;
18
19    /// The response type for this endpoint.
20    type Res: DeserializeOwned + Serialize + 'static;
21
22    /// The (inner) error type for this endpoint.
23    type Err: DeserializeOwned + Serialize + Error + 'static;
24
25    /// The method used to make a request to the endpoint.
26    const METHOD: Method;
27}
28
29/// Search endpoints.
30pub mod search;
31
32/// Animation endpoints.
33pub mod animation;
34
35/// Category endpoints.
36pub mod category;
37
38/// Image endpoints.
39pub mod image;
40
41/// Meta endpoints.
42pub mod meta;
43
44/// User endpoints.
45pub mod user;
46
47/// JIG endpoints.
48pub mod jig;
49
50/// Administrative endpoints.
51pub mod admin;
52
53/// Audio endpoints
54pub mod audio;
55
56/// Web Media library endpoints
57pub mod media;
58
59/// Session endpoints
60pub mod session;
61
62/// Locale endpoints
63pub mod locale;
64
65/// Pdf endpoints
66pub mod pdf;
67
68/// Playlist endpoints
69pub mod playlist;
70
71/// Additional Resource endpoints
72pub mod additional_resource;
73
74/// Resource endpoints
75pub mod resource;
76
77/// Circle endpoints
78pub mod circle;
79
80/// Module endpoints
81pub mod module;
82
83/// Course endpoints
84pub mod course;
85
86/// Billing endpoints
87pub mod billing;
88
89/// Account endpoints
90pub mod account;
91
92/// Item that can be part of PathParts
93pub trait PathPart {
94    /// string value to replace placeholder with
95    fn get_path_string(&self) -> String;
96}
97
98/// Path of ApiEndpoint
99pub trait PathParts {
100    /// API path
101    const PATH: &'static str;
102
103    /// path path with placeholders replaced with values
104    fn get_filled(&self) -> String;
105}
106
107// TODO: think we should try to get rid of all these impls, we should use NewTypes instead
108
109impl PathPart for Uuid {
110    fn get_path_string(&self) -> String {
111        self.to_string()
112    }
113}
114
115impl PathPart for Url {
116    fn get_path_string(&self) -> String {
117        // maybe use urlencoding crate
118        todo!();
119    }
120}
121
122impl PathPart for i32 {
123    fn get_path_string(&self) -> String {
124        self.to_string()
125    }
126}
127
128impl PathPart for u32 {
129    fn get_path_string(&self) -> String {
130        self.to_string()
131    }
132}
133
134impl PathPart for i16 {
135    fn get_path_string(&self) -> String {
136        self.to_string()
137    }
138}