pastes: Add schema and some db ops
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
		
							parent
							
								
									e782e6640f
								
							
						
					
					
						commit
						0556a03396
					
				@ -1,11 +1,9 @@
 | 
			
		||||
use rocket::Rocket;
 | 
			
		||||
use rocket::{Rocket};
 | 
			
		||||
 | 
			
		||||
#[get("/health")]
 | 
			
		||||
fn check() -> &'static str {
 | 
			
		||||
    "OK"
 | 
			
		||||
}
 | 
			
		||||
#[get("/")]
 | 
			
		||||
fn check() -> &'static str { "OK" }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
pub fn fuel(rocket: Rocket) -> Rocket {
 | 
			
		||||
    rocket.mount("/api", routes![check])
 | 
			
		||||
    rocket.mount("/api/health", routes![check])
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										0
									
								
								src/api/routes/paste.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/api/routes/paste.rs
									
									
									
									
									
										Normal file
									
								
							@ -1 +1,2 @@
 | 
			
		||||
pub mod paste;
 | 
			
		||||
pub mod paste;
 | 
			
		||||
pub mod users;
 | 
			
		||||
@ -0,0 +1,11 @@
 | 
			
		||||
use diesel::pg::PgConnection;
 | 
			
		||||
use diesel::result::Error;
 | 
			
		||||
use super::entity::Paste;
 | 
			
		||||
use crate::schema::pastes;
 | 
			
		||||
use diesel::{RunQueryDsl, QueryResult};
 | 
			
		||||
 | 
			
		||||
pub fn create(paste: &Paste, conn: &PgConnection) -> Result<usize, Error> {
 | 
			
		||||
    diesel::insert_into(pastes::table)
 | 
			
		||||
        .values(paste)
 | 
			
		||||
        .execute(conn)
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
use crate::schema::pastes;
 | 
			
		||||
 | 
			
		||||
#[table_name="pastes"]
 | 
			
		||||
#[derive(AsChangeset, Serialize, Deserialize, Queryable, Insertable)]
 | 
			
		||||
pub struct Paste {
 | 
			
		||||
    id: String,
 | 
			
		||||
    belongs_to: String,
 | 
			
		||||
    is_url: bool,
 | 
			
		||||
    content: String
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										0
									
								
								src/core/users/diesel.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/core/users/diesel.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								src/core/users/entity.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/core/users/entity.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										4
									
								
								src/core/users/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/core/users/mod.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
pub mod diesel;
 | 
			
		||||
pub mod entity;
 | 
			
		||||
pub mod repository;
 | 
			
		||||
pub mod service;
 | 
			
		||||
							
								
								
									
										0
									
								
								src/core/users/repository.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/core/users/repository.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								src/core/users/service.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/core/users/service.rs
									
									
									
									
									
										Normal file
									
								
							@ -16,6 +16,7 @@ extern crate slog;
 | 
			
		||||
pub mod api;
 | 
			
		||||
pub mod core;
 | 
			
		||||
pub mod utils;
 | 
			
		||||
pub mod schema;
 | 
			
		||||
 | 
			
		||||
use slog_term;
 | 
			
		||||
use slog_async;
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,3 @@
 | 
			
		||||
table! {
 | 
			
		||||
    games (id) {
 | 
			
		||||
        id -> Int4,
 | 
			
		||||
        name -> Text,
 | 
			
		||||
        developer -> Text,
 | 
			
		||||
        is_goty -> Bool,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
table! {
 | 
			
		||||
    pastes (id) {
 | 
			
		||||
        id -> Varchar,
 | 
			
		||||
@ -28,7 +19,6 @@ table! {
 | 
			
		||||
joinable!(pastes -> users (belongs_to));
 | 
			
		||||
 | 
			
		||||
allow_tables_to_appear_in_same_query!(
 | 
			
		||||
    games,
 | 
			
		||||
    pastes,
 | 
			
		||||
    users,
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user