Remove null constrain from variant and return newly created article.
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
|
||||||
|
-- Remove null constrain for variant
|
||||||
|
ALTER TABLE IF EXISTS public.variant
|
||||||
|
ALTER COLUMN description DROP NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.variant
|
||||||
|
ALTER COLUMN ingredients DROP NOT NULL;
|
||||||
+16
-11
@@ -111,21 +111,26 @@ async fn create_article(
|
|||||||
State(pool): State<PgPool>,
|
State(pool): State<PgPool>,
|
||||||
Json(payload): Json<Article>,
|
Json(payload): Json<Article>,
|
||||||
) -> (StatusCode, Json<Article>) {
|
) -> (StatusCode, Json<Article>) {
|
||||||
info!("Test");
|
info!("Create article");
|
||||||
|
|
||||||
|
match insert_article(&payload, pool).await {
|
||||||
|
Some(article) => {
|
||||||
|
(StatusCode::CREATED, Json(article))
|
||||||
|
}
|
||||||
|
None => {
|
||||||
let article = Article {
|
let article = Article {
|
||||||
id: payload.id,
|
id: 0,
|
||||||
name: payload.name,
|
name: "".to_string(),
|
||||||
bio: payload.bio,
|
bio: false,
|
||||||
origin: payload.origin,
|
origin: Origin::EU,
|
||||||
description: payload.description,
|
description: None,
|
||||||
ingredients: payload.ingredients,
|
ingredients: None,
|
||||||
variants: payload.variants,
|
variants: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
insert_article(&article, pool).await;
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
||||||
|
}
|
||||||
(StatusCode::CREATED, Json(article))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_variant(
|
async fn add_variant(
|
||||||
|
|||||||
Reference in New Issue
Block a user