Refactored the whole code to a better structure
This commit is contained in:
parent
87cc8ac794
commit
12b865bf17
21 changed files with 473 additions and 257 deletions
1
project/src/handlers/authentication.rs
Normal file
1
project/src/handlers/authentication.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub fn login() {}
|
10
project/src/handlers/mod.rs
Normal file
10
project/src/handlers/mod.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
pub mod authentication;
|
||||
pub mod register;
|
||||
|
||||
use crate::db_connection::{DbPool, MyPooledConnection};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
pub fn pool_handler(pool: web::Data<DbPool>) -> Result<MyPooledConnection, HttpResponse> {
|
||||
pool.get()
|
||||
.map_err(|e| HttpResponse::InternalServerError().json(e.to_string()))
|
||||
}
|
19
project/src/handlers/register.rs
Normal file
19
project/src/handlers/register.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use crate::db_connection::DbPool;
|
||||
use crate::handlers::pool_handler;
|
||||
use crate::models::user::{RegisterUser, User};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
pub fn register(
|
||||
new_user: web::Json<RegisterUser>,
|
||||
pool: web::Data<DbPool>,
|
||||
) -> Result<HttpResponse, HttpResponse> {
|
||||
let my_pool = pool_handler(pool)?;
|
||||
let register_user = new_user
|
||||
.into_inner()
|
||||
.validation()
|
||||
.map_err(|e| HttpResponse::InternalServerError().json(e.to_string()))?;
|
||||
|
||||
User::create(register_user, &my_pool)
|
||||
.map(|user| HttpResponse::Ok().json(user))
|
||||
.map_err(|e| HttpResponse::InternalServerError().json(e.to_string()))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue