Project compiles now
parent
07f25219d6
commit
b99d9faa04
|
@ -652,15 +652,6 @@ version = "0.2.108"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9636c194f9db483f4d0adf2f99a65011a99f904bd222bbd67fb4df4f37863c30"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.4"
|
||||
|
@ -687,9 +678,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "loom"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2b9df80a3804094bf49bb29881d18f6f05048db72127e84e09c26fc7c2324f5"
|
||||
checksum = "5df2c4aeb432e60c9e5ae517ca8ed8b63556ce23093b2758fc8837d75439c5ec"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"generator",
|
||||
|
@ -702,9 +693,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.0.1"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
|
||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
]
|
||||
|
@ -736,15 +727,6 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf5f78c1d9892fb5677a8b2f543f967ab891ac0f71feecd961435b74f877283a"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.16"
|
||||
|
@ -1045,6 +1027,23 @@ dependencies = [
|
|||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rb"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.hackbever.be/rusty-bever/common-rs.git#1ce6c47124533a9f6b9e276b7bae23f07db0bf68"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
"figment",
|
||||
"hmac",
|
||||
"jwt",
|
||||
"rand",
|
||||
"rocket",
|
||||
"serde",
|
||||
"sha2",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rb-blog"
|
||||
version = "0.1.0"
|
||||
|
@ -1056,9 +1055,9 @@ dependencies = [
|
|||
"figment",
|
||||
"hmac",
|
||||
"jwt",
|
||||
"mimalloc",
|
||||
"openssl",
|
||||
"rand",
|
||||
"rb",
|
||||
"rocket",
|
||||
"rocket_sync_db_pools",
|
||||
"rust-argon2",
|
||||
|
@ -1692,36 +1691,22 @@ dependencies = [
|
|||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-serde"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.25"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
|
||||
checksum = "7507ec620f809cdf07cccb5bc57b13069a88031b795efd4079b1c71b66c1613d"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
"matchers",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
"tracing-serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -14,6 +14,7 @@ path = "src/main.rs"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rb = { git = "https://git.hackbever.be/rusty-bever/common-rs.git" }
|
||||
# Backend web framework
|
||||
rocket = { version = "0.5.0-rc.1", features = [ "json", "uuid" ] }
|
||||
# Used to provide Rocket routes with database connections
|
||||
|
@ -39,4 +40,3 @@ chrono = { version = "*", features = [ "serde" ] }
|
|||
base64 = "0.13.0"
|
||||
# Reading in configuration files
|
||||
figment = { version = "*", features = [ "yaml" ] }
|
||||
mimalloc = { version = "0.1.26", default_features = false }
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# I just use this compose file to easily start up test databases
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
db-blog:
|
||||
image: 'postgres:14-alpine'
|
||||
restart: 'always'
|
||||
|
||||
environment:
|
||||
- 'POSTGRES_USER=rb'
|
||||
- 'POSTGRES_PASSWORD=rb'
|
||||
ports:
|
||||
- '5433:5432'
|
||||
# volumes:
|
||||
# - 'db-data:/var/lib/postgresql/data'
|
||||
|
||||
# volumes:
|
||||
# db-data:
|
|
@ -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 New Issue