correlate 0.3.0

correlate is a standalone server that listens for Stripe webhook events and sends notification emails about successful orders.
use chrono::NaiveDateTime;
use rocket::{
    fairing::AdHoc,
    response::{status::Created, Debug},
    serde::{json::Json, Deserialize, Serialize},
};
// rocket macro imports
use rocket::{post, routes};
use rocket_db_pools::{
    diesel::{prelude::*, MysqlPool},
    Connection, Database,
};

use crate::schema::stripe_customers;

#[derive(Database)]
#[database("simply_sourdough")]
struct Db(MysqlPool);

#[derive(Debug, Deserialize, Serialize, Queryable, Insertable)]
#[serde(crate = "rocket::serde")]
#[diesel(table_name = stripe_customers)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
struct StripeCustomer {
    id: i64,
    user_id: String,
    email: String,
    #[serde(alias = "created")]
    created_at: NaiveDateTime,
    updated_at: Option<NaiveDateTime>,
    deleted_at: Option<NaiveDateTime>,
}

type Result<T, E = Debug<diesel::result::Error>> = std::result::Result<T, E>;

#[post("/", data = "<customer>")]
async fn create_customer(
    mut db: Connection<Db>,
    mut customer: Json<StripeCustomer>,
) -> Result<Created<Json<StripeCustomer>>> {
    diesel::sql_function!(fn last_insert_id() -> BigInt);

    let customer = db
        .transaction(|mut conn| {
            Box::pin(async move {
                diesel::insert_into(stripe_customers::table)
                    .values(&*customer)
                    .execute(&mut conn)
                    .await?;

                customer.id = stripe_customers::table
                    .select(last_insert_id())
                    .first(&mut conn)
                    .await?;

                Ok::<_, diesel::result::Error>(customer)
            })
        })
        .await?;

    Ok(Created::new("/").body(customer))
}

pub fn stage() -> AdHoc {
    AdHoc::on_ignite("Diesel MySQL Stage", |rocket| async {
        rocket
            .attach(Db::init())
            .mount("/api", routes![create_customer]) // routes![list, read, create, delete, destroy])
    })
}