Skip to content

Commit d31a6d4

Browse files
committed
refactor: Rename services to routes
1 parent b93eac2 commit d31a6d4

File tree

9 files changed

+57
-12
lines changed

9 files changed

+57
-12
lines changed

apps/server/src/api/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod db;
22
pub mod models;
3+
pub mod routes;
34
#[allow(non_snake_case)]
45
pub mod schema;
56
pub mod server;
6-
pub mod services;

apps/server/src/api/services/core.rs renamed to apps/server/src/api/routes/challenge.rs

+29
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,32 @@ pub async fn submit_challenge(
115115
fn valid_request(action: &String, labels: &Vec<Label>) -> bool {
116116
return action == "opened" && labels.iter().any(|current| current.name == "challenger");
117117
}
118+
119+
#[cfg(test)]
120+
mod tests {
121+
use super::*;
122+
use actix_web::{test, App};
123+
124+
#[actix_web::test]
125+
async fn test_valid_request() {
126+
let action = "opened".to_string();
127+
let labels = vec![Label {
128+
name: "challenger".to_string(),
129+
node_id: todo!(),
130+
url: todo!(),
131+
color: todo!(),
132+
default: todo!(),
133+
description: todo!(),
134+
}];
135+
assert_eq!(valid_request(&action, &labels), true);
136+
}
137+
138+
/* #[actix_web::test]
139+
async fn test_invalid_request() {
140+
let action = "closed".to_string();
141+
let labels = vec![Label {
142+
name: "challenger".to_string(),
143+
}];
144+
assert_eq!(valid_request(&action, &labels), false);
145+
} */
146+
}

apps/server/src/api/services/match_data.rs renamed to apps/server/src/api/routes/match_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) struct HttpResponseStruct {
3131
}
3232

3333
#[get("/api/matches/{id}")]
34-
pub(super) async fn get_match_route(
34+
pub(routes) async fn get_match_route(
3535
path: web::Path<String>,
3636
) -> actix_web::Result<Json<HttpResponseStruct>> {
3737
let conn = api::db::establish_connection().get().unwrap();

apps/server/src/api/services/matches.rs renamed to apps/server/src/api/routes/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) struct HttpResponseStruct {
99
}
1010

1111
#[get("/api/matches")]
12-
pub(super) async fn get_matches_route() -> actix_web::Result<Json<HttpResponseStruct>> {
12+
pub(routes) async fn get_matches_route() -> actix_web::Result<Json<HttpResponseStruct>> {
1313
let conn = api::db::establish_connection().get().unwrap();
1414

1515
let matches = Match::list_ids(&conn);

apps/server/src/api/services/mod.rs renamed to apps/server/src/api/routes/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub(crate) mod core;
1+
pub(crate) mod challenge;
22
pub(crate) mod match_data;
33
pub(crate) mod matches;
44
pub(crate) mod ping;

apps/server/src/api/routes/ping.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use actix_web::get;
2+
3+
#[get("/api/ping")]
4+
pub(routes) async fn get_api_ping() -> actix_web::Result<String> {
5+
return Ok("pong".to_string());
6+
}
7+
8+
#[cfg(test)]
9+
mod tests {
10+
use super::*;
11+
use actix_web::{test, App};
12+
13+
#[actix_web::test]
14+
async fn test_ping_route() {
15+
let app = test::init_service(App::new().service(get_api_ping)).await;
16+
let req = test::TestRequest::get().uri("/api/ping").to_request();
17+
let resp = test::call_service(&app, req).await;
18+
assert!(resp.status().is_success());
19+
let body = test::read_body(resp).await;
20+
assert_eq!(body, "pong");
21+
}
22+
}

apps/server/src/api/services/routes.rs renamed to apps/server/src/api/routes/routes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use actix_web::web;
22

33
use super::{
4-
core::submit_challenge, match_data::get_match_route, matches::get_matches_route,
4+
challenge::submit_challenge, match_data::get_match_route, matches::get_matches_route,
55
ping::get_api_ping,
66
};
77

apps/server/src/api/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use actix_web::{web::Data, App, HttpServer};
22

3-
use crate::api::{self, db::run_migrations, services::routes::routes};
3+
use crate::api::{self, db::run_migrations, routes::routes::routes};
44

55
pub(crate) async fn start_server(port: u16, host: String) -> Result<(), std::io::Error> {
66
migrations();

apps/server/src/api/services/ping.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)