restructured, added db connection pool

This commit is contained in:
Andre Heber
2024-02-15 13:00:04 +01:00
parent b6679e2436
commit bb94bde843
14 changed files with 1400 additions and 38 deletions

20
src/startup.rs Normal file
View File

@ -0,0 +1,20 @@
use actix_web::dev::Server;
use actix_web::{web, App, HttpServer};
use sqlx::{Pool, Postgres};
use std::net::TcpListener;
use crate::routes::{health_check, subscribe};
pub fn run(listener: TcpListener, connection: Pool<Postgres>) -> Result<Server, std::io::Error> {
let connection = web::Data::new(connection);
let server = HttpServer::new(move || {
App::new()
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
.app_data(connection.clone())
})
.listen(listener)?
.run();
Ok(server)
}