Skip to content

Commit

Permalink
refactor: Rename services to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hampfh committed Oct 1, 2024
1 parent b93eac2 commit d31a6d4
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod db;
pub mod models;
pub mod routes;
#[allow(non_snake_case)]
pub mod schema;
pub mod server;
pub mod services;
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,32 @@ pub async fn submit_challenge(
fn valid_request(action: &String, labels: &Vec<Label>) -> bool {
return action == "opened" && labels.iter().any(|current| current.name == "challenger");
}

#[cfg(test)]
mod tests {
use super::*;
use actix_web::{test, App};

#[actix_web::test]
async fn test_valid_request() {
let action = "opened".to_string();
let labels = vec![Label {
name: "challenger".to_string(),
node_id: todo!(),
url: todo!(),
color: todo!(),
default: todo!(),
description: todo!(),
}];
assert_eq!(valid_request(&action, &labels), true);
}

/* #[actix_web::test]
async fn test_invalid_request() {
let action = "closed".to_string();
let labels = vec![Label {
name: "challenger".to_string(),
}];
assert_eq!(valid_request(&action, &labels), false);
} */
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) struct HttpResponseStruct {
}

#[get("/api/matches/{id}")]
pub(super) async fn get_match_route(
pub(routes) async fn get_match_route(
path: web::Path<String>,
) -> actix_web::Result<Json<HttpResponseStruct>> {
let conn = api::db::establish_connection().get().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) struct HttpResponseStruct {
}

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

let matches = Match::list_ids(&conn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod core;
pub(crate) mod challenge;
pub(crate) mod match_data;
pub(crate) mod matches;
pub(crate) mod ping;
Expand Down
22 changes: 22 additions & 0 deletions apps/server/src/api/routes/ping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use actix_web::get;

#[get("/api/ping")]
pub(routes) async fn get_api_ping() -> actix_web::Result<String> {
return Ok("pong".to_string());
}

#[cfg(test)]
mod tests {
use super::*;
use actix_web::{test, App};

#[actix_web::test]
async fn test_ping_route() {
let app = test::init_service(App::new().service(get_api_ping)).await;
let req = test::TestRequest::get().uri("/api/ping").to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
let body = test::read_body(resp).await;
assert_eq!(body, "pong");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::web;

use super::{
core::submit_challenge, match_data::get_match_route, matches::get_matches_route,
challenge::submit_challenge, match_data::get_match_route, matches::get_matches_route,
ping::get_api_ping,
};

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/api/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use actix_web::{web::Data, App, HttpServer};

use crate::api::{self, db::run_migrations, services::routes::routes};
use crate::api::{self, db::run_migrations, routes::routes::routes};

pub(crate) async fn start_server(port: u16, host: String) -> Result<(), std::io::Error> {
migrations();
Expand Down
6 changes: 0 additions & 6 deletions apps/server/src/api/services/ping.rs

This file was deleted.

0 comments on commit d31a6d4

Please sign in to comment.