1+ use crate :: repository:: { DisplayOptions , Repository , Segment , Timer , TimerMetadata } ;
12use serde:: { Deserialize , Serialize } ;
2- use crate :: color:: Color ;
33use std:: sync:: Arc ;
4- use tokio:: sync:: broadcast;
5-
6- //main.rs
7- fn default_zero ( ) -> u32 {
8- 0
9- }
10-
11- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
12- pub struct Segment {
13- label : String ,
14- time : u32 ,
15- sound : bool ,
16- color : Option < Color > ,
17- #[ serde( default = "default_zero" ) ]
18- count_to : u32 ,
19- }
20-
21- #[ derive( Serialize , Deserialize , Clone , Debug ) ]
22- pub enum PreStartBehaviour {
23- ShowZero ,
24- RunNormally ,
25- }
26-
27- impl Default for PreStartBehaviour {
28- fn default ( ) -> Self {
29- PreStartBehaviour :: ShowZero
30- }
31- }
32-
33- #[ derive( Serialize , Deserialize , Clone , Default , Debug ) ]
34- pub struct DisplayOptions {
35- #[ serde( default ) ]
36- clock : bool ,
37- #[ serde( default ) ]
38- pre_start_behaviour : PreStartBehaviour ,
39- }
40-
41- #[ derive( Serialize , Deserialize , Clone , Default , Debug ) ]
42- pub struct Timer {
43- // Return after TimerRequest
44- pub segments : Vec < Segment > ,
45- pub repeat : bool ,
46- pub display_options : Option < DisplayOptions > ,
47- pub start_at : u64 ,
48- pub stop_at : Option < u64 > ,
49- pub password : String ,
50- pub id : String , // 5 random chars
51- }
524
535#[ derive( Serialize , Clone ) ]
546#[ serde( tag = "type" , content = "data" ) ]
@@ -60,17 +12,16 @@ pub enum DonationMethod {
6012pub struct InstanceProperties {
6113 pub demo : bool ,
6214 pub donation : Option < Vec < DonationMethod > > ,
15+ pub s3_host : String ,
6316}
6417
6518pub type SharedState = Arc < AppState > ;
6619pub struct AppState {
67- pub redis : redis :: aio :: ConnectionManager ,
20+ pub repository : Repository ,
6821 pub jwt_key : String ,
6922 pub instance_properties : InstanceProperties ,
70- pub redis_task_rx : broadcast:: Receiver < Timer > ,
7123}
7224
73-
7425//timer.rs
7526
7627#[ derive( Serialize , Deserialize , Debug ) ]
@@ -81,6 +32,7 @@ pub struct TimerResponse {
8132 pub display_options : DisplayOptions ,
8233 pub start_at : u64 ,
8334 pub stop_at : Option < u64 > ,
35+ pub metadata : TimerMetadata ,
8436}
8537
8638impl Into < TimerResponse > for Timer {
@@ -89,9 +41,10 @@ impl Into<TimerResponse> for Timer {
8941 segments : self . segments ,
9042 id : self . id ,
9143 repeat : self . repeat ,
92- display_options : self . display_options . unwrap_or ( DisplayOptions :: default ( ) ) ,
44+ display_options : self . display_options ,
9345 start_at : self . start_at ,
9446 stop_at : self . stop_at ,
47+ metadata : self . metadata ,
9548 }
9649 }
9750}
@@ -104,20 +57,36 @@ pub struct TimerCreationResponse {
10457
10558#[ derive( Serialize , Deserialize ) ]
10659pub struct TimerCreationRequest {
107- // Get from User
10860 pub segments : Vec < Segment > ,
10961 pub id : String ,
11062 pub password : String ,
11163 pub repeat : bool ,
11264 pub start_at : u64 ,
65+ pub metadata : TimerMetadata ,
66+ pub display_options : DisplayOptions ,
67+ }
68+
69+ impl TimerCreationRequest {
70+ pub fn into ( self , hashed_password : String ) -> Timer {
71+ Timer {
72+ segments : self . segments ,
73+ repeat : self . repeat ,
74+ display_options : self . display_options ,
75+ start_at : self . start_at ,
76+ stop_at : None ,
77+ password : hashed_password,
78+ id : self . id ,
79+ metadata : self . metadata ,
80+ }
81+ }
11382}
11483
11584#[ derive( Serialize , Deserialize ) ]
11685pub struct TimerUpdateRequest {
117- // Get from User
11886 pub segments : Vec < Segment > ,
11987 pub repeat : bool ,
120- pub display_options : Option < DisplayOptions > ,
88+ pub display_options : DisplayOptions ,
89+ pub metadata : TimerMetadata ,
12190 pub start_at : u64 ,
12291 pub stop_at : Option < u64 > ,
12392}
@@ -139,3 +108,30 @@ pub struct Claims {
139108pub struct TokenResponse {
140109 pub token : String ,
141110}
111+
112+ ///
113+ /// Websocket
114+ ///
115+
116+ #[ derive( Serialize , Deserialize , Debug ) ]
117+ pub struct WsTimerResponse {
118+ pub segments : Vec < Segment > ,
119+ pub id : String ,
120+ pub repeat : bool ,
121+ pub display_options : DisplayOptions ,
122+ pub start_at : u64 ,
123+ pub stop_at : Option < u64 > ,
124+ }
125+
126+ impl Into < WsTimerResponse > for Timer {
127+ fn into ( self ) -> WsTimerResponse {
128+ WsTimerResponse {
129+ segments : self . segments ,
130+ id : self . id ,
131+ repeat : self . repeat ,
132+ display_options : self . display_options ,
133+ start_at : self . start_at ,
134+ stop_at : self . stop_at ,
135+ }
136+ }
137+ }
0 commit comments