GeneIT/geneit_backend/src/main.rs

296 lines
12 KiB
Rust
Raw Normal View History

2023-06-06 13:47:30 +00:00
use actix_cors::Cors;
2023-08-05 17:15:52 +00:00
use actix_multipart::form::tempfile::TempFileConfig;
2023-05-24 14:19:46 +00:00
use actix_remote_ip::RemoteIPConfig;
use actix_web::middleware::Logger;
2023-05-24 12:38:18 +00:00
use actix_web::{web, App, HttpServer};
use geneit_backend::app_config::AppConfig;
use geneit_backend::connections::{db_connection, s3_connection};
2023-06-16 15:51:51 +00:00
use geneit_backend::controllers::{
2024-05-31 19:41:58 +00:00
accommodations_list_controller, accommodations_reservations_calendars_controller,
accommodations_reservations_controller, auth_controller, couples_controller, data_controller,
families_controller, members_controller, photos_controller, server_controller,
users_controller,
2023-06-16 15:51:51 +00:00
};
2023-05-24 12:38:18 +00:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("Start to listen on {}", AppConfig::get().listen_address);
2023-08-05 12:49:17 +00:00
// Initialize bucket
log::info!("Initialize bucket");
s3_connection::create_bucket_if_required()
.await
.expect("Failed to initialize S3 bucket!");
// Initialize database connection
log::debug!("Initialize database connection");
db_connection::initialize_conn().expect("Failed to initialize database connection!");
2023-05-24 12:38:18 +00:00
HttpServer::new(|| {
App::new()
2023-06-06 13:47:30 +00:00
.wrap(
Cors::default()
.allowed_origin(&AppConfig::get().website_origin)
.allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE"])
2023-06-06 13:47:30 +00:00
.allowed_header("X-Auth-Token")
2023-06-09 08:45:01 +00:00
.allow_any_header()
2023-06-06 13:47:30 +00:00
.supports_credentials()
.max_age(3600),
)
2023-05-24 14:19:46 +00:00
.wrap(Logger::default())
.app_data(web::Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))
2023-08-05 17:15:52 +00:00
// Uploaded files
.app_data(TempFileConfig::default().directory(&AppConfig::get().temp_dir))
2023-05-24 12:38:18 +00:00
// Config controller
.route("/", web::get().to(server_controller::home))
2023-05-24 12:38:18 +00:00
.route(
"/server/config",
web::get().to(server_controller::server_config),
2023-05-24 12:38:18 +00:00
)
2023-05-24 14:19:46 +00:00
// Auth controller
.route(
"/auth/create_account",
web::post().to(auth_controller::create_account),
)
2023-05-31 11:56:18 +00:00
.route(
"/auth/request_reset_password",
web::post().to(auth_controller::request_reset_password),
)
.route(
"/auth/check_reset_password_token",
web::post().to(auth_controller::check_reset_password_token),
)
2023-05-31 11:33:26 +00:00
.route(
"/auth/reset_password",
web::post().to(auth_controller::reset_password),
)
2023-05-31 13:17:00 +00:00
.route(
"/auth/password_login",
web::post().to(auth_controller::password_login),
)
2023-06-02 09:49:18 +00:00
.route(
"/auth/start_openid_login",
web::post().to(auth_controller::start_openid_login),
)
2023-06-02 13:04:49 +00:00
.route(
"/auth/finish_openid_login",
web::post().to(auth_controller::finish_openid_login),
)
2023-06-02 13:35:07 +00:00
.route("/auth/logout", web::get().to(auth_controller::logout))
2023-05-31 13:52:49 +00:00
// User controller
2023-06-16 15:51:51 +00:00
.route("/user/info", web::get().to(users_controller::auth_info))
2023-06-05 16:52:00 +00:00
.route(
"/user/update_profile",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::update_profile),
2023-06-05 16:52:00 +00:00
)
2023-06-05 17:02:51 +00:00
.route(
"/user/replace_password",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::replace_password),
2023-06-05 17:02:51 +00:00
)
2023-06-06 07:47:52 +00:00
.route(
"/user/request_delete",
2023-06-16 15:51:51 +00:00
web::get().to(users_controller::request_delete_account),
2023-06-06 07:47:52 +00:00
)
2023-06-06 08:02:41 +00:00
.route(
"/user/check_delete_token",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::check_delete_token),
2023-06-06 08:02:41 +00:00
)
2023-06-06 08:19:54 +00:00
.route(
"/user/delete_account",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::delete_account),
)
// Families controller
.route(
"/family/create",
web::post().to(families_controller::create),
2023-06-06 08:19:54 +00:00
)
2023-06-17 16:55:07 +00:00
.route("/family/join", web::post().to(families_controller::join))
2023-06-20 16:55:14 +00:00
.route("/family/list", web::get().to(families_controller::list))
2023-06-21 14:36:46 +00:00
.route(
2023-06-21 16:15:20 +00:00
"/family/{id}",
2023-06-21 14:36:46 +00:00
web::get().to(families_controller::single_info),
)
2023-06-21 15:35:07 +00:00
.route(
"/family/{id}/leave",
web::post().to(families_controller::leave),
)
2023-06-22 12:37:48 +00:00
.route("/family/{id}", web::patch().to(families_controller::update))
2023-06-21 16:15:20 +00:00
.route(
"/family/{id}",
web::delete().to(families_controller::delete),
)
.route(
"/family/{id}/renew_invitation_code",
web::post().to(families_controller::renew_invitation_code),
)
2023-06-21 15:01:52 +00:00
.route(
"/family/{id}/users",
web::get().to(families_controller::users),
)
2023-06-22 14:03:11 +00:00
.route(
"/family/{id}/user/{user_id}",
web::patch().to(families_controller::update_membership),
)
.route(
"/family/{id}/user/{user_id}",
web::delete().to(families_controller::delete_membership),
)
// [GENEALOGY] Members controller
2023-08-04 17:03:46 +00:00
.route(
"/family/{id}/genealogy/member/create",
2023-08-04 17:03:46 +00:00
web::post().to(members_controller::create),
)
2023-08-05 08:38:10 +00:00
.route(
"/family/{id}/genealogy/members",
2023-08-05 08:38:10 +00:00
web::get().to(members_controller::get_all),
)
.route(
"/family/{id}/genealogy/member/{member_id}",
web::get().to(members_controller::get_single),
)
.route(
"/family/{id}/genealogy/member/{member_id}",
web::put().to(members_controller::update),
)
.route(
"/family/{id}/genealogy/member/{member_id}",
web::delete().to(members_controller::delete),
)
2023-08-05 17:15:52 +00:00
.route(
"/family/{id}/genealogy/member/{member_id}/photo",
2023-08-05 17:15:52 +00:00
web::put().to(members_controller::set_photo),
)
2023-08-07 09:07:24 +00:00
.route(
"/family/{id}/genealogy/member/{member_id}/photo",
2023-08-07 09:07:24 +00:00
web::delete().to(members_controller::remove_photo),
)
// [GENEALOGY] Couples controller
2023-08-07 14:50:22 +00:00
.route(
"/family/{id}/genealogy/couple/create",
2023-08-07 14:50:22 +00:00
web::post().to(couples_controller::create),
)
2023-08-07 15:16:00 +00:00
.route(
"/family/{id}/genealogy/couples",
2023-08-07 15:16:00 +00:00
web::get().to(couples_controller::get_all),
)
.route(
"/family/{id}/genealogy/couple/{couple_id}",
2023-08-07 15:16:00 +00:00
web::get().to(couples_controller::get_single),
)
2023-08-07 17:28:44 +00:00
.route(
"/family/{id}/genealogy/couple/{couple_id}",
2023-08-07 17:28:44 +00:00
web::put().to(couples_controller::update),
)
2023-08-07 17:31:05 +00:00
.route(
"/family/{id}/genealogy/couple/{couple_id}",
2023-08-07 17:31:05 +00:00
web::delete().to(couples_controller::delete),
)
2023-08-08 08:33:12 +00:00
.route(
"/family/{id}/genealogy/couple/{couple_id}/photo",
2023-08-08 08:33:12 +00:00
web::put().to(couples_controller::set_photo),
)
.route(
"/family/{id}/genealogy/couple/{couple_id}/photo",
2023-08-08 08:33:12 +00:00
web::delete().to(couples_controller::remove_photo),
)
// [GENEALOGY] Data controller
2023-08-17 15:37:44 +00:00
.route(
"/family/{id}/genealogy/data/export",
2023-08-17 15:37:44 +00:00
web::get().to(data_controller::export_family),
)
2023-08-18 09:05:32 +00:00
.route(
"/family/{id}/genealogy/data/import",
2023-08-18 09:05:32 +00:00
web::put().to(data_controller::import_family),
)
2024-05-23 17:28:29 +00:00
// [ACCOMODATIONS] List controller
.route(
"/family/{id}/accommodations/list/create",
web::post().to(accommodations_list_controller::create),
)
2024-05-25 05:50:11 +00:00
.route(
"/family/{id}/accommodations/list/list",
web::get().to(accommodations_list_controller::get_full_list),
)
2024-05-23 19:30:51 +00:00
.route(
"/family/{id}/accommodations/list/{accommodation_id}",
2024-05-25 05:54:34 +00:00
web::get().to(accommodations_list_controller::get_single),
2024-05-23 19:30:51 +00:00
)
2024-05-25 05:57:50 +00:00
.route(
"/family/{id}/accommodations/list/{accommodation_id}",
web::put().to(accommodations_list_controller::update),
)
2024-05-25 05:54:34 +00:00
.route(
"/family/{id}/accommodations/list/{accommodation_id}",
web::delete().to(accommodations_list_controller::delete),
)
2024-05-23 17:28:29 +00:00
// [ACCOMODATIONS] Reservations controller
.route(
"/family/{id}/accommodations/reservations/accommodation/{accommodation_id}",
web::get()
.to(accommodations_reservations_controller::get_accommodation_reservations),
)
.route(
"/family/{id}/accommodations/reservations/accommodation/{accommodation_id}/for_interval",
web::get()
.to(accommodations_reservations_controller::get_accommodation_reservations_for_interval),
)
.route(
"/family/{id}/accommodations/reservations/full_list",
web::get().to(accommodations_reservations_controller::full_list),
)
2024-05-29 20:16:50 +00:00
.route(
"/family/{id}/accommodations/reservations/accommodation/{accommodation_id}/create",
web::post().to(accommodations_reservations_controller::create_reservation),
)
.route(
"/family/{id}/accommodations/reservation/{reservation_id}",
web::get().to(accommodations_reservations_controller::get_single),
)
2024-05-30 17:54:05 +00:00
.route(
"/family/{id}/accommodations/reservation/{reservation_id}",
web::patch().to(accommodations_reservations_controller::update_single),
)
2024-05-29 20:28:38 +00:00
.route(
"/family/{id}/accommodations/reservation/{reservation_id}",
web::delete().to(accommodations_reservations_controller::delete),
)
2024-05-30 19:43:27 +00:00
.route(
"/family/{id}/accommodations/reservation/{reservation_id}/validate",
web::post().to(accommodations_reservations_controller::validate_or_reject),
)
2024-05-28 20:14:34 +00:00
// [ACCOMMODATIONS] Calendars controller
2024-05-31 19:41:58 +00:00
.route(
"/family/{id}/accommodations/reservations_calendars/create",
web::post().to(accommodations_reservations_calendars_controller::create),
)
.route(
"/family/{id}/accommodations/reservations_calendars/list",
web::get().to(accommodations_reservations_calendars_controller::get_list),
)
2024-05-31 20:31:23 +00:00
.route(
"/family/{id}/accommodations/reservations_calendars/{cal_id}",
web::delete().to(accommodations_reservations_calendars_controller::delete),
)
2024-06-03 20:47:39 +00:00
.route(
"/acccommodations_calendar/{token}",
web::get().to(accommodations_reservations_calendars_controller::anonymous_access),
)
2023-08-07 14:50:22 +00:00
// Photos controller
2023-08-07 12:53:44 +00:00
.route(
"/photo/{id}",
web::get().to(photos_controller::get_full_size),
)
.route(
"/photo/{id}/thumbnail",
web::get().to(photos_controller::get_thumbnail),
)
2023-05-24 12:38:18 +00:00
})
.bind(AppConfig::get().listen_address.as_str())?
.run()
.await
2023-05-24 09:37:02 +00:00
}