Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Commit d0a5d73

Browse files
authored
Merge pull request #12 from TeamPractical/niklas
Pull me
2 parents 479fb9a + 8640b1c commit d0a5d73

File tree

8 files changed

+52
-2
lines changed

8 files changed

+52
-2
lines changed

API_doc.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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

393408
Returns leaderboard data (currently up to rank 30).

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smartbeans-backend"
3-
version = "1.1.1"
3+
version = "1.2.0"
44
authors = ["Niklas Birth <[email protected]>"]
55
edition = "2018"
66
default-run = "backend"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE error_messages
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
)

src/bin/backend.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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,

src/routes/misc.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/schema.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
2836
table! {
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,

0 commit comments

Comments
 (0)