Skip to content

Commit

Permalink
add map routes and handled all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vxcall committed Sep 2, 2024
1 parent fa002c0 commit df6a522
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use actix_web::{middleware::Logger, web, App, HttpServer};
use aws_sdk_dynamodb::Client;
use redis::aio::MultiplexedConnection;
use utils::{app_state::AppState, global_variables::DYNAMO_DB_TABLE_NAME};
use utils::app_state::AppState;

mod routes;
mod utils;
Expand Down Expand Up @@ -50,8 +50,6 @@ async fn main() -> Result<()> {

println!("dynamodb setup done");

let table_name = (DYNAMO_DB_TABLE_NAME).clone();
println!("DYNAMO_DB_TABLE_NAME: {table_name}");
println!("about to fire up web server!");

HttpServer::new(move || {
Expand All @@ -63,6 +61,7 @@ async fn main() -> Result<()> {
.wrap(Logger::default())
.configure(routes::auth_routes::config)
.configure(routes::user_routes::config)
.configure(routes::map_routes::config)
})
.bind((address, port))
.map_err(anyhow::Error::from)?
Expand Down
4 changes: 2 additions & 2 deletions src/routes/handlers/auth_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::collections::HashMap;
use crate::utils::{
api_response::{self, ApiResponse},
app_state::{self, AppState},
user::get_user_from_email,
global_variables::DYNAMO_DB_TABLE_NAME,
jwt::{add_to_blacklist, encode_jwt},
models::User,
user::get_user_from_email,
};
use actix_web::{post, web, HttpRequest};
use anyhow::Result;
Expand All @@ -23,6 +23,7 @@ struct RegisterRequest {
#[derive(serde::Deserialize)]
struct LoginRequest {
email: String,
#[allow(dead_code)]
password: String,
}

Expand Down Expand Up @@ -77,7 +78,6 @@ pub async fn login(
app_state: web::Data<app_state::AppState>,
request: web::Json<LoginRequest>,
) -> Result<ApiResponse, ApiResponse> {
println!("first");
let result = get_user_from_email(&app_state.dynamo_client, request.email.clone())
.await
.map_err(|err| ApiResponse::new(409, err.to_string()))?;
Expand Down
10 changes: 10 additions & 0 deletions src/routes/handlers/map_handlers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use actix_web::{get, web};

use crate::utils::{api_response::ApiResponse, app_state};

#[get("/index")]
pub async fn index(
#[allow(unused_variables)] app_state: web::Data<app_state::AppState>,
) -> Result<ApiResponse, ApiResponse> {
Ok(ApiResponse::new(200, format!("OK")))
}
1 change: 1 addition & 0 deletions src/routes/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod auth_handlers;
pub mod map_handlers;
pub mod user_handlers;
3 changes: 1 addition & 2 deletions src/routes/handlers/user_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use actix_web::{get, post, web, Responder};
use actix_web::{get, web};
use aws_sdk_dynamodb::types::AttributeValue;
use sha256::digest;

use crate::utils::{
api_response::{self, ApiResponse},
Expand Down
7 changes: 7 additions & 0 deletions src/routes/map_routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use actix_web::web;

use super::handlers;

pub fn config(config: &mut web::ServiceConfig) {
config.service(handlers::map_handlers::index);
}
1 change: 1 addition & 0 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod handlers;
pub mod middlewares;

pub mod auth_routes;
pub mod map_routes;
pub mod user_routes;
2 changes: 1 addition & 1 deletion src/routes/user_routes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use actix_web::middleware::from_fn;
use actix_web::web;
use actix_web::{middleware::from_fn, web::service};

use super::{handlers, middlewares};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod api_response;
pub mod app_state;
pub mod user;
pub mod environment_variables;
pub mod global_variables;
pub mod jwt;
pub mod models;
pub mod user;
1 change: 1 addition & 0 deletions src/utils/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub(crate) struct User {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) email: String,
#[allow(dead_code)]
pub(crate) password: String,
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use aws_sdk_dynamodb::{operation::query::QueryOutput, types::AttributeValue, Client};

use super::{api_response::ApiResponse, global_variables::DYNAMO_DB_TABLE_NAME};
use super::global_variables::DYNAMO_DB_TABLE_NAME;

pub(crate) async fn get_user_from_email(
dynamo_client: &Arc<Client>,
Expand Down

0 comments on commit df6a522

Please sign in to comment.