mirror of
https://github.com/Blair-SGA-Dev-Team/blazerapp.git
synced 2024-11-21 04:21:16 -05:00
first for re-cms
This commit is contained in:
parent
6fd0056c89
commit
2afba79e02
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -57,3 +57,9 @@ buck-out/
|
|||
|
||||
# CocoaPods
|
||||
/ios/Pods/
|
||||
|
||||
# Rust
|
||||
/target/
|
||||
|
||||
# Environment
|
||||
*.env
|
||||
|
|
1782
Cargo.lock
generated
Normal file
1782
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
5
Cargo.toml
Normal file
5
Cargo.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
[workspace]
|
||||
|
||||
members = [
|
||||
"cms",
|
||||
]
|
16
cms/Cargo.toml
Normal file
16
cms/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "cms"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.5.0-rc.1"
|
||||
dotenv = "0.15.0"
|
||||
oauth2 = { version = "4.1.0", default-features = false }
|
||||
clap = "2.33.3"
|
||||
ansi_term = "0.12.1"
|
||||
chrono = "0.4.19"
|
||||
diesel = { version = "1.4.4", features = ["postgres", "extras"] }
|
||||
|
0
cms/auth.rs
Normal file
0
cms/auth.rs
Normal file
0
cms/migrations/.gitkeep
Normal file
0
cms/migrations/.gitkeep
Normal file
2
cms/migrations/setup/down.sql
Normal file
2
cms/migrations/setup/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
DROP TABLE events;
|
||||
|
7
cms/migrations/setup/up.sql
Normal file
7
cms/migrations/setup/up.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE events (
|
||||
id SERIAL PRIMARY KEY,
|
||||
title VARCHAR NOT NULL,
|
||||
text VARCHAR,
|
||||
location VARCHAR NOT NULL,
|
||||
event_date DATE
|
||||
);
|
3
cms/src/auth.rs
Normal file
3
cms/src/auth.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub fn auth() {
|
||||
|
||||
}
|
20
cms/src/data/events/mod.rs
Normal file
20
cms/src/data/events/mod.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use diesel::prelude::*;
|
||||
use super::models::{Event, NewEvent};
|
||||
use super::super::utils::{exit_with_error};
|
||||
|
||||
pub fn create_event(conn: &PgConnection, event: NewEvent) -> Event {
|
||||
|
||||
use super::schema::events;
|
||||
diesel::insert_into(events::table)
|
||||
.values(&event)
|
||||
.get_result(conn)
|
||||
.unwrap_or_else(|_| exit_with_error("Error saving new post"))
|
||||
|
||||
}
|
||||
|
||||
pub fn get_all(conn: &PgConnection) -> Result<Vec<Event>, diesel::result::Error> {
|
||||
|
||||
use super::schema::events::dsl::*;
|
||||
|
||||
events.load::<Event>(conn)
|
||||
}
|
3
cms/src/data/mod.rs
Normal file
3
cms/src/data/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod events;
|
||||
pub mod schema;
|
||||
pub mod models;
|
22
cms/src/data/models.rs
Normal file
22
cms/src/data/models.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use super::schema::events;
|
||||
use diesel::Insertable;
|
||||
use diesel::Queryable;
|
||||
use chrono::naive::NaiveDate;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Event {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub location: String,
|
||||
pub text: String,
|
||||
pub event_date: NaiveDate,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name="events"]
|
||||
pub struct NewEvent<'a> {
|
||||
pub title: &'a str,
|
||||
pub location: &'a str,
|
||||
pub text: &'a str,
|
||||
pub event_date: &'a NaiveDate
|
||||
}
|
12
cms/src/data/schema.rs
Normal file
12
cms/src/data/schema.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
table! {
|
||||
use diesel::sql_types::*;
|
||||
|
||||
events (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
text -> Text,
|
||||
location -> Text,
|
||||
event_date -> Date,
|
||||
}
|
||||
}
|
53
cms/src/main.rs
Normal file
53
cms/src/main.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
#[macro_use] extern crate diesel;
|
||||
#[macro_use] extern crate rocket;
|
||||
|
||||
mod utils;
|
||||
mod data;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use rocket::{Build, Rocket};
|
||||
use utils::{exit_with_error, db_conn};
|
||||
use dotenv::dotenv;
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> &'static str {
|
||||
"Hello, world!"
|
||||
}
|
||||
|
||||
|
||||
fn rocket(port: u32) -> Rocket<Build> {
|
||||
let figment = rocket::Config::figment()
|
||||
.merge(("port", port));
|
||||
rocket::custom(figment)
|
||||
.mount("/", routes![index])
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
|
||||
let postgres = db_conn("/postgres")
|
||||
.unwrap_or_else(|_| exit_with_error("Error connecting to database. "));
|
||||
|
||||
|
||||
let matches = App::new("blazercms")
|
||||
.version("1.0")
|
||||
.arg(Arg::with_name("port")
|
||||
.short("p")
|
||||
.long("port")
|
||||
.default_value("8080"))
|
||||
.get_matches();
|
||||
|
||||
let port = matches
|
||||
.value_of("port")
|
||||
.unwrap()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_else(|_| exit_with_error("Port must be an integer! "));
|
||||
|
||||
if let Err(_) = rocket(port).launch().await {
|
||||
exit_with_error(&format!("Error binding port {}. ", port));
|
||||
}
|
||||
}
|
||||
|
21
cms/src/utils.rs
Normal file
21
cms/src/utils.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use ansi_term::Colour::Red;
|
||||
use diesel::prelude::*;
|
||||
use diesel::pg::{PgConnection};
|
||||
use std::{env};
|
||||
|
||||
pub fn exit_with_error(msg: &str) -> ! {
|
||||
eprintln!("{}", Red.paint(msg));
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn db_conn(dbname: &str) -> Result<PgConnection, ConnectionError> {
|
||||
|
||||
let mut database_url = env::var("BLAZERCMS_DATABASE_URL")
|
||||
.unwrap_or_else(|_| exit_with_error("BLAZERCMS_DATABASE_URL must be set"));
|
||||
|
||||
database_url.push_str(dbname);
|
||||
|
||||
PgConnection::establish(&database_url)
|
||||
}
|
10
login.html
Normal file
10
login.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
<input type="text" id="token" name="token">
|
||||
<input type="submit" name="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user