1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{
auth::Auth,
dev::controller,
dev::controller::{HealthCheckResponse, MyQueryResult, MySqlQuery},
Database,
};
use actix_web::{
get, post,
web::{Data, Json},
HttpResponse, Scope,
};
use std::ops::Deref;
#[post("/db/query")]
async fn query_db(db: Data<Database>, body: Json<MySqlQuery>) -> HttpResponse {
match controller::query_db(&db, body.deref()) {
Ok(result) => HttpResponse::Ok().body(result),
Err(t) => HttpResponse::InternalServerError().finish(),
}
}
#[get("/auth/has-system-role")]
async fn check_system_role(auth: Auth) -> HttpResponse {
HttpResponse::Ok().json(controller::check_system_role(&auth))
}
#[get("/auth/add-system-role")]
async fn add_system_role(db: Data<Database>, auth: Auth) -> HttpResponse {
HttpResponse::Ok().json(controller::add_system_role(&db, &auth))
}
#[get("/db/is-connected")]
async fn is_connected(db: Data<Database>) -> HttpResponse {
HttpResponse::Ok().json(controller::is_connected(&db))
}
#[get("/db/needs-migration")]
async fn needs_migration(db: Data<Database>) -> HttpResponse {
HttpResponse::Ok().json(controller::needs_migration(&db))
}
#[get("/db/migrate")]
async fn migrate_db(db: Data<Database>) -> HttpResponse {
HttpResponse::Ok().json(controller::migrate_db(&db))
}
#[get("/health")]
async fn health() -> HttpResponse {
controller::health();
HttpResponse::Ok().json(HealthCheckResponse {
message: "healthy".to_string(),
})
}
pub fn endpoints(scope: Scope) -> Scope {
scope
.service(query_db)
.service(check_system_role)
.service(add_system_role)
.service(is_connected)
.service(needs_migration)
.service(migrate_db)
.service(health)
}