-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change all db pool in `Campaign` to transactions * move extracting user_id from request to helper function * add slugs to `Campaign` and `Organisation` * add endpoints to check slug availability * slug utility functions and checks * email templating and offer CRUD * fix email_template auth service join * offer CRUD * ran `cargo fmt` & remove unused imports
- Loading branch information
1 parent
088a48e
commit 2ec5c18
Showing
26 changed files
with
1,119 additions
and
272 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE email_templates ( | ||
id BIGINT PRIMARY KEY, | ||
organisation_id BIGINT NOT NULL, | ||
name TEXT NOT NULL, | ||
template TEXT NOT NULL, | ||
CONSTRAINT FK_email_templates_organisations | ||
FOREIGN KEY(organisation_id) | ||
REFERENCES organisations(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
UNIQUE (organisation_id, name) | ||
); |
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,32 @@ | ||
CREATE TYPE offer_status AS ENUM ('Draft', 'Sent', 'Accepted', 'Declined'); | ||
|
||
CREATE TABLE offers ( | ||
id BIGINT PRIMARY KEY, | ||
campaign_id BIGINT NOT NULL, | ||
application_id BIGINT NOT NULL, | ||
email_template_id BIGINT NOT NULL, | ||
role_id BIGINT NOT NULL, | ||
expiry TIMESTAMPTZ NOT NULL, | ||
status offer_status NOT NULL DEFAULT 'Draft', | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT FK_offers_campaigns | ||
FOREIGN KEY(campaign_id) | ||
REFERENCES campaigns(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
CONSTRAINT FK_offers_applications | ||
FOREIGN KEY(application_id) | ||
REFERENCES applications(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
CONSTRAINT FK_offers_email_templates | ||
FOREIGN KEY(email_template_id) | ||
REFERENCES email_templates(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE, | ||
CONSTRAINT FK_offers_roles | ||
FOREIGN KEY(role_id) | ||
REFERENCES campaign_roles(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); |
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 |
---|---|---|
|
@@ -26,4 +26,4 @@ rust-s3 = "0.34.0" | |
rs-snowflake = "0.6" | ||
jsonwebtoken = "9.1" | ||
dotenvy = "0.15" | ||
|
||
handlebars = "6.2" |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::models::app::AppState; | ||
use crate::models::auth::EmailTemplateAdmin; | ||
use crate::models::email_template::EmailTemplate; | ||
use crate::models::error::ChaosError; | ||
use crate::models::transaction::DBTransaction; | ||
use axum::extract::{Json, Path, State}; | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
|
||
pub struct EmailTemplateHandler; | ||
impl EmailTemplateHandler { | ||
pub async fn get( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: EmailTemplateAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let email_template = EmailTemplate::get(id, &mut transaction.tx).await?; | ||
|
||
Ok((StatusCode::OK, Json(email_template))) | ||
} | ||
|
||
pub async fn update( | ||
_user: EmailTemplateAdmin, | ||
Path(id): Path<i64>, | ||
State(state): State<AppState>, | ||
Json(request_body): Json<EmailTemplate>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
EmailTemplate::update(id, request_body.name, request_body.template, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Successfully updated email template")) | ||
} | ||
|
||
pub async fn delete( | ||
_user: EmailTemplateAdmin, | ||
Path(id): Path<i64>, | ||
State(state): State<AppState>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
EmailTemplate::delete(id, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Successfully delete email template")) | ||
} | ||
} |
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,66 @@ | ||
use crate::models::auth::{OfferAdmin, OfferRecipient}; | ||
use crate::models::error::ChaosError; | ||
use crate::models::offer::{Offer, OfferReply}; | ||
use crate::models::transaction::DBTransaction; | ||
use axum::extract::{Json, Path}; | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
|
||
pub struct OfferHandler; | ||
impl OfferHandler { | ||
pub async fn get( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: OfferAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let offer = Offer::get(id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
|
||
Ok((StatusCode::OK, Json(offer))) | ||
} | ||
|
||
pub async fn delete( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: OfferAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Offer::delete(id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
|
||
Ok((StatusCode::OK, "Successfully deleted offer")) | ||
} | ||
|
||
pub async fn reply( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: OfferRecipient, | ||
Json(reply): Json<OfferReply>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Offer::reply(id, reply.accept, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
|
||
Ok((StatusCode::OK, "Successfully accepted offer")) | ||
} | ||
|
||
pub async fn preview_email( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: OfferAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let string = Offer::preview_email(id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
|
||
Ok((StatusCode::OK, string)) | ||
} | ||
|
||
pub async fn send_offer( | ||
mut transaction: DBTransaction<'_>, | ||
Path(id): Path<i64>, | ||
_user: OfferAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Offer::send_offer(id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
|
||
Ok((StatusCode::OK, "Successfully sent offer")) | ||
} | ||
} |
Oops, something went wrong.