Project compiles now
This commit is contained in:
parent
07f25219d6
commit
b99d9faa04
10 changed files with 93 additions and 91 deletions
|
|
@ -1,12 +1,10 @@
|
|||
use chrono::NaiveDate;
|
||||
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
|
||||
use rb::errors::{RbError, RbOption, RbResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
errors::{RbError, RbOption, RbResult},
|
||||
schema::{posts, posts::dsl::*},
|
||||
};
|
||||
use crate::schema::{posts, posts::dsl::*};
|
||||
|
||||
#[derive(Queryable, Serialize)]
|
||||
pub struct Post
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
|
||||
use rb::errors::{RbError, RbResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
errors::{RbError, RbResult},
|
||||
schema::{sections, sections::dsl::*},
|
||||
};
|
||||
use crate::schema::{sections, sections::dsl::*};
|
||||
|
||||
#[derive(Queryable, Serialize)]
|
||||
pub struct Section
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
pub mod db;
|
||||
pub(crate) mod schema;
|
||||
40
src/main.rs
40
src/main.rs
|
|
@ -1,17 +1,13 @@
|
|||
// This needs to be explicitely included before diesel is imported to make sure
|
||||
// compilation succeeds in the release Docker image.
|
||||
extern crate openssl;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use figment::{
|
||||
providers::{Env, Format, Yaml},
|
||||
Figment,
|
||||
};
|
||||
use rb::auth::JwtConf;
|
||||
use rocket::{
|
||||
fairing::AdHoc,
|
||||
http::Status,
|
||||
|
|
@ -21,16 +17,9 @@ use rocket::{
|
|||
use rocket_sync_db_pools::database;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod db;
|
||||
pub mod errors;
|
||||
pub mod guards;
|
||||
pub mod posts;
|
||||
pub(crate) mod schema;
|
||||
pub mod sections;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
#[database("postgres_rb")]
|
||||
pub struct RbDbConn(diesel::PgConnection);
|
||||
|
||||
|
|
@ -54,35 +43,12 @@ async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocke
|
|||
.await
|
||||
}
|
||||
|
||||
// async fn create_admin_user<'a>(rocket: &'a Rocket<Orbit>)
|
||||
// {
|
||||
// let config = rocket.state::<RbConfig>().expect("RbConfig instance");
|
||||
// let admin_user = config.admin_user.clone();
|
||||
// let admin_pass = config.admin_pass.clone();
|
||||
|
||||
// let conn = RbDbConn::get_one(&rocket)
|
||||
// .await
|
||||
// .expect("database connection");
|
||||
// conn.run(move |c| {
|
||||
// admin::create_admin_user(c, &admin_user, &admin_pass).expect("failed to create admin user")
|
||||
// })
|
||||
// .await;
|
||||
// }
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct RbJwtConf
|
||||
{
|
||||
key: String,
|
||||
refresh_token_size: usize,
|
||||
refresh_token_expire: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct RbConfig
|
||||
{
|
||||
admin_user: String,
|
||||
admin_pass: String,
|
||||
jwt: RbJwtConf,
|
||||
jwt: JwtConf,
|
||||
}
|
||||
|
||||
#[launch]
|
||||
|
|
@ -101,7 +67,7 @@ fn rocket() -> _
|
|||
run_db_migrations,
|
||||
))
|
||||
// .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user))
|
||||
.attach(AdHoc::config::<RbConfig>())
|
||||
.attach(AdHoc::config::<JwtConf>())
|
||||
.register("/", catchers![default_catcher])
|
||||
.mount("/sections", routes![sections::create_section])
|
||||
.mount("/posts", routes![posts::get, posts::create])
|
||||
|
|
|
|||
10
src/posts.rs
10
src/posts.rs
|
|
@ -1,11 +1,11 @@
|
|||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::{
|
||||
db,
|
||||
use rb::{
|
||||
errors::{RbOption, RbResult},
|
||||
guards::Admin,
|
||||
RbDbConn,
|
||||
};
|
||||
use rb_blog::db;
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::RbDbConn;
|
||||
|
||||
#[get("/?<offset>&<limit>")]
|
||||
pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
table! {
|
||||
posts (id) {
|
||||
id -> Uuid,
|
||||
section_id -> Uuid,
|
||||
title -> Nullable<Varchar>,
|
||||
publish_date -> Date,
|
||||
content -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
sections (id) {
|
||||
id -> Uuid,
|
||||
title -> Varchar,
|
||||
shortname -> Varchar,
|
||||
description -> Nullable<Text>,
|
||||
is_default -> Bool,
|
||||
has_titles -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
joinable!(posts -> sections (section_id));
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
posts,
|
||||
sections,
|
||||
);
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
//! This module handles management of site sections (aka blogs).
|
||||
|
||||
use rb::{
|
||||
errors::{RbOption, RbResult},
|
||||
guards::Admin,
|
||||
};
|
||||
use rb_blog::db;
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::{db, errors::RbResult, guards::Admin, RbDbConn};
|
||||
use crate::RbDbConn;
|
||||
|
||||
/// Route for creating a new section.
|
||||
///
|
||||
|
|
|
|||
Reference in a new issue