Backend done

This commit is contained in:
Franklin 2023-04-26 15:09:24 -04:00
parent 28303cb48f
commit 702a63825d
6 changed files with 216 additions and 33 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/target
.env
/dist
dist.zip

167
Cargo.lock generated
View File

@ -34,6 +34,29 @@ dependencies = [
"smallvec",
]
[[package]]
name = "actix-files"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d832782fac6ca7369a70c9ee9a20554623c5e51c76e190ad151780ebea1cf689"
dependencies = [
"actix-http",
"actix-service",
"actix-utils",
"actix-web",
"askama_escape",
"bitflags",
"bytes",
"derive_more",
"futures-core",
"http-range",
"log",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
]
[[package]]
name = "actix-http"
version = "3.3.1"
@ -236,6 +259,55 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "actix-web-lab"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9f49571dfcf49ed79c6e7a645e9554ae01925eb55fa6e3b2501ceeed24d7e7"
dependencies = [
"actix-files",
"actix-http",
"actix-router",
"actix-service",
"actix-utils",
"actix-web",
"actix-web-lab-derive",
"ahash 0.8.3",
"arc-swap",
"async-trait",
"bytes",
"bytestring",
"csv",
"derive_more",
"futures-core",
"futures-util",
"http",
"impl-more",
"itertools",
"local-channel",
"mediatype",
"mime",
"once_cell",
"pin-project-lite",
"regex",
"serde",
"serde_html_form",
"serde_json",
"tokio",
"tracing",
]
[[package]]
name = "actix-web-lab-derive"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16294584c7794939b1e5711f28e7cae84ef30e62a520db3f9af425f85269bcd2"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "actix-web-utils"
version = "0.2.21"
@ -310,6 +382,29 @@ dependencies = [
"libc",
]
[[package]]
name = "arc-swap"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6"
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "async-trait"
version = "0.1.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "atoi"
version = "1.0.0"
@ -957,6 +1052,27 @@ dependencies = [
"typenum",
]
[[package]]
name = "csv"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b015497079b9a9d69c02ad25de6c0a6edef051ea6360a327d0bd05802ef64ad"
dependencies = [
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "cxx"
version = "1.0.94"
@ -1428,6 +1544,12 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "httparse"
version = "1.8.0"
@ -1519,6 +1641,12 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "impl-more"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2697f323912b5b942f1ff43625c34895edcf3def901c11214ad92d41fa5c57da"
[[package]]
name = "indexmap"
version = "1.9.3"
@ -1577,6 +1705,7 @@ dependencies = [
"actix-cors",
"actix-multipart",
"actix-web",
"actix-web-lab",
"actix-web-utils",
"aws-config",
"aws-sdk-s3",
@ -1710,6 +1839,12 @@ dependencies = [
"digest",
]
[[package]]
name = "mediatype"
version = "0.19.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea6e62614ab2fc0faa58bb15102a0382d368f896a9fa4776592589ab55c4de7"
[[package]]
name = "memchr"
version = "2.5.0"
@ -1722,6 +1857,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@ -2253,6 +2398,19 @@ dependencies = [
"syn 2.0.15",
]
[[package]]
name = "serde_html_form"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53192e38d5c88564b924dbe9b60865ecbb71b81d38c4e61c817cffd3e36ef696"
dependencies = [
"form_urlencoded",
"indexmap",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_json"
version = "1.0.96"
@ -2740,6 +2898,15 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.13"

View File

@ -20,6 +20,7 @@ dotenv = { version = "0.15.0" }
actix-web = {version = "4.1.0"}
actix-cors = "0.6.2"
actix-multipart = "0.6.0"
actix-web-lab = { version = "0.19.1", features = [ "spa" ]}
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
actix-web-utils = { git = "https://git.franklinblanco.dev/franklinblanco/actix-web-utils.git" }

View File

@ -3,4 +3,5 @@ export CXX_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-g++
export AR_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
cargo build --release --target x86_64-unknown-linux-gnu
scp -i ~/Developer/kp/main-key-pair.pem $CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/jl-backend deploy/Dockerfile ubuntu@18.118.145.141:~/executables/jl-backend/
zip -r dist dist/
scp -i ~/Developer/kp/main-key-pair.pem $CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/jl-backend deploy/Dockerfile dist.zip ubuntu@proyectosenconstruccion.com:~/executables/jl-backend/

BIN
dist.zip Normal file

Binary file not shown.

View File

@ -1,10 +1,11 @@
use std::sync::Arc;
use std::{sync::Arc};
use actix_cors::Cors;
use actix_web::{
web::{self},
App, HttpServer,
};
use actix_web_lab::web::spa;
use chrono::Utc;
use reqwest::Client;
use sqlx::PgPool;
@ -12,7 +13,7 @@ use sqlx::PgPool;
use crate::utils::s3;
pub const HOST_ADDR: &str = "0.0.0.0";
pub const HOST_PORT: u16 = 8095;
pub const HOST_PORT: u16 = 8080;
pub async fn start_all_routes(start_time: i64, db_conn: Arc<PgPool>) -> Result<(), std::io::Error> {
let client_state = web::Data::new(Arc::new(Client::new()));
@ -26,36 +27,47 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc<PgPool>) -> Result<(
.app_data(web::Data::new(db_conn.clone()))
.app_data(aws_client.clone())
.service(
web::scope("/admin")
.service(super::admin::create_new_agent_profile)
.service(super::admin::create_new_location)
.service(super::admin::create_new_project)
.service(super::admin::create_new_unit)
.service(super::admin::update_agent)
.service(super::admin::update_project)
.service(super::admin::update_unit)
.service(super::admin::delete_agent)
.service(super::admin::delete_location)
.service(super::admin::delete_project)
.service(super::admin::delete_unit)
.service(super::admin::get_all_contacts)
.service(super::admin::get_contacts_count)
.service(super::admin::get_visits_count)
.service(super::admin::upload_image)
.service(super::admin::authenticate),
)
web::scope("/api")
.service(
web::scope("/admin")
.service(super::admin::create_new_agent_profile)
.service(super::admin::create_new_location)
.service(super::admin::create_new_project)
.service(super::admin::create_new_unit)
.service(super::admin::update_agent)
.service(super::admin::update_project)
.service(super::admin::update_unit)
.service(super::admin::delete_agent)
.service(super::admin::delete_location)
.service(super::admin::delete_project)
.service(super::admin::delete_unit)
.service(super::admin::get_all_contacts)
.service(super::admin::get_contacts_count)
.service(super::admin::get_visits_count)
.service(super::admin::upload_image)
.service(super::admin::authenticate),
)
.service(
web::scope("/read")
.service(super::read::get_all_agents)
.service(super::read::get_all_locations)
.service(super::read::get_locations_in_city)
.service(super::read::get_projects_paged)
.service(super::read::get_project_data)
.service(super::read::create_contact_request)
.service(super::read::get_agent_with_shortcode)
.service(super::read::get_location_with_city_and_district)
.service(super::read::get_agent_with_id)
.service(super::read::get_unit_with_id),
)
)
.service(
web::scope("/read")
.service(super::read::get_all_agents)
.service(super::read::get_all_locations)
.service(super::read::get_locations_in_city)
.service(super::read::get_projects_paged)
.service(super::read::get_project_data)
.service(super::read::create_contact_request)
.service(super::read::get_agent_with_shortcode)
.service(super::read::get_location_with_city_and_district)
.service(super::read::get_agent_with_id)
.service(super::read::get_unit_with_id),
spa()
.index_file("./dist/index.html")
.static_resources_mount("/")
.static_resources_location("./dist")
.finish()
)
})
.bind((HOST_ADDR, HOST_PORT))?