This repository was archived by the owner on Mar 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +52
-2
lines changed
migrations/2021-03-02-143159_add_table_error_messages Expand file tree Collapse file tree 8 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,21 @@ Input:
388388<String>
389389```
390390
391+ ### /error_notifications (GET)
392+
393+ Alerts that can be used to notify users if something is broken. Does not require Authorization header.
394+
395+ Output:
396+ ```
397+ [
398+ {
399+ 'title': <String>,
400+ 'content': <String>
401+ },
402+ ...
403+ ]
404+ ```
405+
391406### /leaderboard (GET)
392407
393408Returns leaderboard data (currently up to rank 30).
Original file line number Diff line number Diff line change 11[package ]
22name = " smartbeans-backend"
3- version = " 1.1.1 "
3+ version = " 1.2.0 "
44authors = [
" Niklas Birth <[email protected] >" ]
55edition = " 2018"
66default-run = " backend"
Original file line number Diff line number Diff line change 1+ DROP TABLE error_messages
Original file line number Diff line number Diff line change 1+ CREATE TABLE error_messages (
2+ id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
3+ title TEXT NOT NULL ,
4+ content TEXT NOT NULL
5+ )
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ fn main() {
8484 routes:: misc:: error,
8585 routes:: misc:: report_error,
8686 routes:: misc:: leaderboard,
87+ routes:: misc:: error_notifications,
8788 routes:: tasks:: get_tasks,
8889 routes:: tasks:: progress,
8990 routes:: tasks:: submit,
Original file line number Diff line number Diff line change @@ -96,4 +96,23 @@ pub fn leaderboard(user: guards::User) -> Json<Value> {
9696 . collect ( ) ;
9797
9898 Json ( serde_json:: to_value ( values) . unwrap ( ) )
99+ }
100+
101+ #[ get( "/error_notifications" ) ]
102+ pub fn error_notifications ( ) -> Json < Value > {
103+ use crate :: schema:: error_messages:: dsl:: * ;
104+
105+ let messages = error_messages. select ( ( title, content) )
106+ . load :: < ( String , String ) > ( & crate :: database:: establish_connection ( ) )
107+ . expect ( "Database error" )
108+ . into_iter ( )
109+ . map ( |message| {
110+ let mut val = json ! ( { } ) ;
111+ val[ "title" ] = Value :: String ( message. 0 ) ;
112+ val[ "content" ] = Value :: String ( message. 1 ) ;
113+ val
114+ } )
115+ . collect :: < Vec < _ > > ( ) ;
116+
117+ Json ( serde_json:: to_value ( messages) . unwrap ( ) )
99118}
Original file line number Diff line number Diff line change @@ -25,6 +25,14 @@ table! {
2525 }
2626}
2727
28+ table ! {
29+ error_messages ( id) {
30+ id -> Integer ,
31+ title -> Text ,
32+ content -> Text ,
33+ }
34+ }
35+
2836table ! {
2937 error_reports ( id) {
3038 id -> Integer ,
@@ -77,6 +85,7 @@ allow_tables_to_appear_in_same_query!(
7785 achievements,
7886 characters,
7987 charnames,
88+ error_messages,
8089 error_reports,
8190 route_log,
8291 sessions,
You can’t perform that action at this time.
0 commit comments