Confirm subscription endpoint
This commit is contained in:
@@ -16,6 +16,13 @@ pub struct Application {
|
||||
router: Router,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub connection_pool: PgPool,
|
||||
pub email_client: Arc<EmailClient>,
|
||||
pub base_url: String,
|
||||
}
|
||||
|
||||
impl Application {
|
||||
pub async fn build(configuration: Settings) -> Result<Self, std::io::Error> {
|
||||
let address = format!(
|
||||
@@ -26,7 +33,11 @@ impl Application {
|
||||
let connection_pool =
|
||||
PgPoolOptions::new().connect_lazy_with(configuration.database.with_db());
|
||||
let email_client = EmailClient::new(configuration.email_client);
|
||||
let router = app(connection_pool, email_client);
|
||||
let router = app(
|
||||
connection_pool,
|
||||
email_client,
|
||||
configuration.application.base_url,
|
||||
);
|
||||
Ok(Self { listener, router })
|
||||
}
|
||||
|
||||
@@ -35,15 +46,21 @@ impl Application {
|
||||
axum::serve(self.listener, self.router).await
|
||||
}
|
||||
|
||||
pub fn address(&self) -> String {
|
||||
pub fn local_addr(&self) -> String {
|
||||
self.listener.local_addr().unwrap().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn app(connection_pool: PgPool, email_client: EmailClient) -> Router {
|
||||
pub fn app(connection_pool: PgPool, email_client: EmailClient, base_url: String) -> Router {
|
||||
let app_state = AppState {
|
||||
connection_pool,
|
||||
email_client: Arc::new(email_client),
|
||||
base_url,
|
||||
};
|
||||
Router::new()
|
||||
.route("/health_check", get(health_check))
|
||||
.route("/subscriptions", post(subscribe))
|
||||
.route("/subscriptions/confirm", get(confirm))
|
||||
.layer(
|
||||
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
|
||||
let matched_path = request
|
||||
@@ -61,6 +78,5 @@ pub fn app(connection_pool: PgPool, email_client: EmailClient) -> Router {
|
||||
)
|
||||
}),
|
||||
)
|
||||
.with_state(connection_pool)
|
||||
.with_state(Arc::new(email_client))
|
||||
.with_state(app_state)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user