Initial commit
This commit is contained in:
commit
ec263707c7
80 changed files with 9928 additions and 0 deletions
3011
backend/Cargo.lock
generated
Normal file
3011
backend/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
backend/Cargo.toml
Normal file
13
backend/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "backend"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
actix-cors = "0.7.1"
|
||||
actix-governor = "0.8.0"
|
||||
actix-web = "4.11.0"
|
||||
dotenvy = "0.15.7"
|
||||
mysql = "26.0.1"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
sqlx = { version = "0.8.6", features = ["mysql", "macros", "runtime-tokio-rustls"] }
|
||||
43
backend/src/api.rs
Normal file
43
backend/src/api.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use actix_web::{HttpResponse, Responder, get, web::Data};
|
||||
use serde::Serialize;
|
||||
use sqlx::FromRow;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Serialize, FromRow)]
|
||||
struct Employee {
|
||||
employeeid: i32,
|
||||
employeename: String,
|
||||
uname: String,
|
||||
pword: String,
|
||||
password: String,
|
||||
ref_positionid: i32,
|
||||
ref_designationid: i32,
|
||||
is_approver: i32,
|
||||
is_finalapprover: i32,
|
||||
is_assessment: i32,
|
||||
is_reviewer: i32,
|
||||
is_evaluator: i32,
|
||||
is_inspector: i32,
|
||||
is_delete: i32,
|
||||
imagepath: String,
|
||||
sigimage: String,
|
||||
is_supervisor: i32,
|
||||
is_guest: i32,
|
||||
is_online: i32,
|
||||
is_head: i32,
|
||||
is_reset: i32
|
||||
}
|
||||
|
||||
#[get("/employee")]
|
||||
pub async fn sample(app_state: Data<AppState>) -> impl Responder {
|
||||
let query =
|
||||
sqlx::query_as::<_, Employee>("SELECT * FROM employee")
|
||||
.fetch_all(&app_state.pool)
|
||||
.await;
|
||||
|
||||
match query {
|
||||
Ok(result) => HttpResponse::Ok().json(result),
|
||||
Err(_) => HttpResponse::BadRequest().into(),
|
||||
}
|
||||
}
|
||||
50
backend/src/main.rs
Normal file
50
backend/src/main.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use actix_web::{App, http, HttpServer, web::Data};
|
||||
// use actix_cors::Cors;
|
||||
use actix_governor::{Governor, GovernorConfigBuilder};
|
||||
use dotenvy::dotenv;
|
||||
|
||||
use sqlx::mysql::{MySqlPool, MySqlPoolOptions};
|
||||
use std::env;
|
||||
|
||||
mod api;
|
||||
use api::{sample};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppState {
|
||||
pool: MySqlPool,
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv().ok();
|
||||
let db_connection = env::var("DATABASE_URL").unwrap();
|
||||
let pool: MySqlPool = MySqlPoolOptions::new()
|
||||
.connect(db_connection.as_str())
|
||||
.await
|
||||
.unwrap();
|
||||
let app_state = AppState { pool };
|
||||
|
||||
HttpServer::new(move || {
|
||||
// let cors = Cors::default()
|
||||
// .allowed_origin("localhost:*")
|
||||
// .allowed_methods(vec!["GET", "POST"])
|
||||
// .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
|
||||
// .allowed_header(http::header::CONTENT_TYPE)
|
||||
// .max_age(3600);
|
||||
|
||||
let governor_conf = GovernorConfigBuilder::default()
|
||||
.seconds_per_request(2)
|
||||
.burst_size(20)
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
App::new()
|
||||
.app_data(Data::new(app_state.pool.clone()))
|
||||
// .wrap(cors)
|
||||
.wrap(Governor::new(&governor_conf))
|
||||
.service(sample)
|
||||
})
|
||||
.bind(("127.0.0.1", 4320))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue