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;
|
2024-05-14 19:36:49 +00:00
|
|
|
use geneit_backend::connections::{db_connection, s3_connection};
|
2023-06-16 15:51:51 +00:00
|
|
|
use geneit_backend::controllers::{
|
2024-05-23 19:20:14 +00:00
|
|
|
accommodations_list_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!");
|
|
|
|
|
2024-05-14 19:36:49 +00:00
|
|
|
// 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)
|
2023-08-08 13:21:05 +00:00
|
|
|
.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
|
2023-06-01 15:01:57 +00:00
|
|
|
.route("/", web::get().to(server_controller::home))
|
2023-05-24 12:38:18 +00:00
|
|
|
.route(
|
2023-06-01 15:01:57 +00:00
|
|
|
"/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),
|
|
|
|
)
|
2023-05-31 09:36:14 +00:00
|
|
|
.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),
|
|
|
|
)
|
2023-06-22 13:18:49 +00:00
|
|
|
.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),
|
|
|
|
)
|
2023-06-23 13:33:16 +00:00
|
|
|
.route(
|
|
|
|
"/family/{id}/user/{user_id}",
|
|
|
|
web::delete().to(families_controller::delete_membership),
|
|
|
|
)
|
2024-05-16 19:15:15 +00:00
|
|
|
// [GENEALOGY] Members controller
|
2023-08-04 17:03:46 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/members",
|
2023-08-05 08:38:10 +00:00
|
|
|
web::get().to(members_controller::get_all),
|
|
|
|
)
|
2023-08-05 08:24:19 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/member/{member_id}",
|
2023-08-05 08:24:19 +00:00
|
|
|
web::get().to(members_controller::get_single),
|
|
|
|
)
|
2023-08-05 08:50:18 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/member/{member_id}",
|
2023-08-05 08:50:18 +00:00
|
|
|
web::put().to(members_controller::update),
|
|
|
|
)
|
2023-08-05 11:56:24 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/member/{member_id}",
|
2023-08-05 11:56:24 +00:00
|
|
|
web::delete().to(members_controller::delete),
|
|
|
|
)
|
2023-08-05 17:15:52 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/member/{member_id}/photo",
|
2023-08-07 09:07:24 +00:00
|
|
|
web::delete().to(members_controller::remove_photo),
|
|
|
|
)
|
2024-05-16 19:15:15 +00:00
|
|
|
// [GENEALOGY] Couples controller
|
2023-08-07 14:50:22 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/couples",
|
2023-08-07 15:16:00 +00:00
|
|
|
web::get().to(couples_controller::get_all),
|
|
|
|
)
|
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/couple/{couple_id}/photo",
|
2023-08-08 08:33:12 +00:00
|
|
|
web::put().to(couples_controller::set_photo),
|
|
|
|
)
|
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/family/{id}/genealogy/couple/{couple_id}/photo",
|
2023-08-08 08:33:12 +00:00
|
|
|
web::delete().to(couples_controller::remove_photo),
|
|
|
|
)
|
2024-05-16 19:15:15 +00:00
|
|
|
// [GENEALOGY] Data controller
|
2023-08-17 15:37:44 +00:00
|
|
|
.route(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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(
|
2024-05-16 19:15:15 +00:00
|
|
|
"/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
|
2024-05-23 19:20:14 +00:00
|
|
|
.route(
|
|
|
|
"/family/{id}/accommodations/list/create",
|
|
|
|
web::post().to(accommodations_list_controller::create),
|
|
|
|
)
|
2024-05-23 17:28:29 +00:00
|
|
|
// TODO : update
|
|
|
|
// TODO : delete
|
|
|
|
// TODO : list
|
|
|
|
// [ACCOMODATIONS] Reservations controller
|
|
|
|
// TODO : create
|
|
|
|
// TODO : update
|
|
|
|
// TODO : delete
|
|
|
|
// TODO : list
|
|
|
|
// TODO : validate or reject
|
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
|
|
|
}
|