Here is my post request code, which was just modified from the boilerplate
#[post("/new-article", data = "<body>", format = "application/json")]
pub fn new_article(db: DbConn, body: Json<NewArticle>) -> Result<APIResponse, APIResponse>{
let new_article = NewArticle {
title: body.title.to_string(),
description: body.description.to_string(),
tag: body.tag.to_string()
};
println!("{}", &new_article);
let insert_result = diesel::insert_into(articles::table)
.values(&new_article)
.get_result::<ArticleModel>(&*db);
if let Err(diesel::result::Error::DatabaseError(
diesel::result::DatabaseErrorKind::UniqueViolation,
_,
)) = insert_result
{
return Err(conflict().message("Article already exists."));
}
let user = insert_result?;
Ok(created().data(json!(&user)))
}
The SQL table
CREATE TABLE articles
(
"id" SERIAL NOT NULL PRIMARY KEY,
"title" TEXT NOT NULL,
"tag" TEXT NOT NULL,
"description" TEXT NOT NULL,
"last_edited" TIMESTAMP DEFAULT current_timestamp NOT NULL,
"edit_count" INTEGER NOT NULL DEFAULT 0,
"status" BOOLEAN NOT NULL DEFAULT true,
"publicized" BOOLEAN NOT NULL DEFAULT false,
"featured" BOOLEAN NOT NULL DEFAULT false,
);
-- CreateIndex
CREATE UNIQUE INDEX articles.id_unique ON articles(id);
Here is my post request code, which was just modified from the boilerplate
The SQL table
And my Models
Any help? I dont know where else to go