routes: pastes: Finish impl of paste creation

Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2020-06-26 00:19:20 +05:30
1 parent 0e5abac774
commit 8e44b02235
15 files changed
+141 -22

No files matched your search

+3 -3
View File
@@ -1,10 +1,10 @@
use crate::schema::pastes;
#[table_name="pastes"]
#[table_name = "pastes"]
#[derive(AsChangeset, Serialize, Deserialize, Queryable, Insertable)]
pub struct Paste {
pub id: Option<String>,
pub belongs_to: String,
pub belongs_to: Option<String>,
pub is_url: bool,
pub content: String
pub content: String,
}
+1 -2
View File
@@ -1,4 +1,3 @@
pub mod entity;
pub mod repository;
pub mod diesel;
pub mod postgres;
pub mod service;
@@ -1,13 +1,14 @@
use diesel::{RunQueryDsl};
use anyhow::Result;
use diesel::pg::PgConnection;
use diesel::result::Error;
use diesel::RunQueryDsl;
use crate::schema::pastes;
use super::entity::Paste;
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize, Error> {
diesel::insert_into(pastes::table)
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize> {
let rows = diesel::insert_into(pastes::table)
.values(paste)
.execute(conn)
.execute(conn)?;
Ok(rows)
}
View File
Whitespace-only changes.
+9
View File
@@ -0,0 +1,9 @@
use anyhow::Result;
use diesel::pg::PgConnection;
use super::entity::Paste;
use super::postgres;
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize> {
postgres::create_paste(paste, conn)
}