File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ mod admin;
23
23
mod byond;
24
24
mod connections;
25
25
mod logging;
26
+ mod new_players;
26
27
mod player;
27
28
mod stickyban;
28
29
mod ticket;
@@ -99,7 +100,7 @@ fn rocket() -> _ {
99
100
player:: new_note,
100
101
player:: applied_notes,
101
102
player:: get_playtime,
102
- player:: get_recent_playtime
103
+ player:: get_recent_playtime,
103
104
] ,
104
105
)
105
106
. mount (
@@ -137,4 +138,8 @@ fn rocket() -> _ {
137
138
format ! ( "{base_url}/Whitelist" ) ,
138
139
routes ! [ whitelist:: get_all_whitelistees] ,
139
140
)
141
+ . mount (
142
+ format ! { "{}/NewPlayers" , base_url} ,
143
+ routes ! [ new_players:: get_new_players] ,
144
+ )
140
145
}
Original file line number Diff line number Diff line change
1
+ use rocket:: serde:: json:: Json ;
2
+ use rocket_db_pools:: Connection ;
3
+ use sqlx:: query_as;
4
+
5
+ use crate :: { player:: Player , Cmdb } ;
6
+
7
+ #[ get( "/<minutes>" ) ]
8
+ pub async fn get_new_players ( mut db : Connection < Cmdb > , minutes : i64 ) -> Json < Vec < Player > > {
9
+ let time_ago = format ! (
10
+ "{}" ,
11
+ ( chrono:: Utc :: now( ) - chrono:: Duration :: minutes( minutes) ) . format( "%Y-%m-%d %H:%M:%S" )
12
+ ) ;
13
+
14
+ match query_as ( "SELECT * FROM players WHERE first_join_date <> \" UNKNOWN\" AND first_join_date > ? ORDER BY first_join_date ASC" )
15
+ . bind ( time_ago)
16
+ . fetch_all ( & mut * * db)
17
+ . await
18
+ {
19
+ Ok ( result) => Json ( result) ,
20
+ Err ( _) => {
21
+ Json ( Vec :: new ( ) )
22
+ }
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments