-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
719f0f1
commit 4310c72
Showing
14 changed files
with
294 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
application: | ||
host: 127.0.0.1 | ||
base_url: "http://127.0.0.1" | ||
database: | ||
require_ssl: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod health_check; | ||
mod subscriptions; | ||
mod subscriptions_confirm; | ||
|
||
pub use health_check::*; | ||
pub use subscriptions::*; | ||
pub use subscriptions_confirm::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use actix_web::{web, HttpResponse}; | ||
use sqlx::PgPool; | ||
use uuid::Uuid; | ||
|
||
#[derive(serde::Deserialize)] | ||
pub struct Parameters { | ||
subscription_token: String, | ||
} | ||
|
||
#[tracing::instrument(name = "confirming a pending subscriber", skip(parameters, pool))] | ||
pub async fn confirm(parameters: web::Query<Parameters>, pool: web::Data<PgPool>) -> HttpResponse { | ||
let id = match get_subscriber_id_from_token(&pool, ¶meters.subscription_token).await { | ||
Ok(subscriber_id) => subscriber_id, | ||
Err(_) => return HttpResponse::BadRequest().finish(), | ||
}; | ||
|
||
match id { | ||
None => HttpResponse::Unauthorized().finish(), | ||
Some(subscriber_id) => { | ||
if confirm_subscriber(&pool, subscriber_id).await.is_err() { | ||
return HttpResponse::InternalServerError().finish(); | ||
} | ||
HttpResponse::Ok().finish() | ||
} | ||
} | ||
} | ||
|
||
#[tracing::instrument(name = "Marking subscriber as confirmed", skip(subscriber_id, pool))] | ||
pub async fn confirm_subscriber(pool: &PgPool, subscriber_id: Uuid) -> Result<(), sqlx::Error> { | ||
sqlx::query!( | ||
r#" | ||
UPDATE subscriptions | ||
SET status = 'confirmed' | ||
WHERE id = $1 | ||
"#, | ||
subscriber_id | ||
) | ||
.execute(pool) | ||
.await | ||
.map_err(|e| { | ||
tracing::error!("Failed to execute query: {:?}", e); | ||
e | ||
})?; | ||
Ok(()) | ||
} | ||
|
||
#[tracing::instrument(name = "Get subscriber_id from token", skip(subscription_token, pool))] | ||
pub async fn get_subscriber_id_from_token( | ||
pool: &PgPool, | ||
subscription_token: &str, | ||
) -> Result<Option<Uuid>, sqlx::Error> { | ||
let result = sqlx::query!( | ||
r#"SELECT subscriber_id FROM subscription_tokens WHERE subscription_token = $1"#, | ||
subscription_token, | ||
) | ||
.fetch_optional(pool) | ||
.await | ||
.map_err(|e| { | ||
tracing::error!("Failed to execute query: {:?}", e); | ||
e | ||
})?; | ||
Ok(result.map(|r| r.subscriber_id)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod health_check; | ||
mod helpers; | ||
mod subscriptions; | ||
mod subscriptions_confirm; |
Oops, something went wrong.