Do not change struct name.

This commit is contained in:
LukeMathWalker 2020-10-18 14:22:22 +01:00
parent ff99488030
commit 1a4ead9b74
2 changed files with 5 additions and 8 deletions

View file

@ -4,13 +4,13 @@ use sqlx::PgPool;
use uuid::Uuid; use uuid::Uuid;
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
pub struct SubscribeRequest { pub struct FormData {
email: String, email: String,
name: String, name: String,
} }
pub async fn subscribe( pub async fn subscribe(
payload: web::Form<SubscribeRequest>, payload: web::Form<FormData>,
pool: web::Data<PgPool>, pool: web::Data<PgPool>,
) -> Result<HttpResponse, HttpResponse> { ) -> Result<HttpResponse, HttpResponse> {
sqlx::query!( sqlx::query!(

View file

@ -4,7 +4,7 @@ use sqlx::PgPool;
use uuid::Uuid; use uuid::Uuid;
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
pub struct SubscribeRequest { pub struct FormData {
email: String, email: String,
name: String, name: String,
} }
@ -18,7 +18,7 @@ pub struct SubscribeRequest {
) )
)] )]
pub async fn subscribe( pub async fn subscribe(
payload: web::Form<SubscribeRequest>, payload: web::Form<FormData>,
pool: web::Data<PgPool>, pool: web::Data<PgPool>,
) -> Result<HttpResponse, HttpResponse> { ) -> Result<HttpResponse, HttpResponse> {
insert_subscriber(&pool, &payload) insert_subscriber(&pool, &payload)
@ -31,10 +31,7 @@ pub async fn subscribe(
name = "Saving new subscriber details in the database", name = "Saving new subscriber details in the database",
skip(payload, pool) skip(payload, pool)
)] )]
pub async fn insert_subscriber( pub async fn insert_subscriber(pool: &PgPool, payload: &FormData) -> Result<(), sqlx::Error> {
pool: &PgPool,
payload: &SubscribeRequest,
) -> Result<(), sqlx::Error> {
sqlx::query!( sqlx::query!(
r#" r#"
INSERT INTO subscriptions (id, email, name, subscribed_at) INSERT INTO subscriptions (id, email, name, subscribed_at)