mirror of
https://github.com/Blair-SGA-Dev-Team/blazerapp.git
synced 2024-11-22 04:51:15 -05:00
ok fixed the pepepga problem
This commit is contained in:
parent
a512542ca5
commit
f081c56c28
|
@ -309,3 +309,19 @@ fn api_route_inner(item: TokenStream) -> TokenStream {
|
||||||
pub fn api_route(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn api_route(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
api_route_inner(TokenStream::from(item)).into()
|
api_route_inner(TokenStream::from(item)).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test() {
|
||||||
|
let val = quote! {
|
||||||
|
events {
|
||||||
|
title: (Text, String, String),
|
||||||
|
location: (Text, String, String),
|
||||||
|
text: (Text, String, String),
|
||||||
|
event_date: (Text, NaiveDate, DateForm),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let macr = api_route_inner(val);
|
||||||
|
|
||||||
|
println!("{}", macr);
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#[macro_use]
|
|
||||||
use cms_macro::api_route;
|
use cms_macro::api_route;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::{RawStr, Status},
|
http::{RawStr, Status},
|
||||||
|
@ -60,179 +59,7 @@ api_route! {
|
||||||
title: (Text, String, String),
|
title: (Text, String, String),
|
||||||
location: (Text, String, String),
|
location: (Text, String, String),
|
||||||
text: (Text, String, String),
|
text: (Text, String, String),
|
||||||
event_date: (Text, NaiveDate, DateForm),
|
event_date: (Date, NaiveDate, DateForm),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub mod events {
|
|
||||||
|
|
||||||
use crate::data::{defs::*, Lang};
|
|
||||||
use crate::auth::Token;
|
|
||||||
use ::chrono::naive::*;
|
|
||||||
use ::diesel::{prelude::*, Insertable, Queryable};
|
|
||||||
use ::rocket::{http::Status, request::Form, response::Redirect, State};
|
|
||||||
use ::rocket_contrib::{json::Json, templates::Template};
|
|
||||||
use ::serde::Serialize;
|
|
||||||
use ::std::{collections::*, sync::Mutex};
|
|
||||||
|
|
||||||
pub mod schema {
|
|
||||||
table! {
|
|
||||||
use diesel::sql_types::*;
|
|
||||||
|
|
||||||
events (id) {
|
|
||||||
id -> Integer,
|
|
||||||
lang -> Text,
|
|
||||||
title -> Text,
|
|
||||||
location -> Text,
|
|
||||||
text -> Text,
|
|
||||||
event_date -> Date,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use schema::events;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Queryable, Serialize)]
|
|
||||||
pub struct Get {
|
|
||||||
pub id: i32,
|
|
||||||
pub lang: String,
|
|
||||||
pub title: String,
|
|
||||||
pub location: String,
|
|
||||||
pub text: String,
|
|
||||||
pub event_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, AsChangeset, Insertable)]
|
|
||||||
#[table_name = "events"]
|
|
||||||
pub struct Create {
|
|
||||||
pub lang: String,
|
|
||||||
pub title: String,
|
|
||||||
pub location: String,
|
|
||||||
pub text: String,
|
|
||||||
pub event_date: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, FromForm)]
|
|
||||||
pub struct Post {
|
|
||||||
pub lang: String,
|
|
||||||
pub title: String,
|
|
||||||
pub location: String,
|
|
||||||
pub text: String,
|
|
||||||
pub event_date: DateForm,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, FromForm)]
|
|
||||||
pub struct Update {
|
|
||||||
pub id: i32,
|
|
||||||
pub lang: String,
|
|
||||||
pub title: String,
|
|
||||||
pub location: String,
|
|
||||||
pub text: String,
|
|
||||||
pub event_date: DateForm,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, FromForm)]
|
|
||||||
pub struct Delete {
|
|
||||||
pub id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Post {
|
|
||||||
fn convert(self) -> Create {
|
|
||||||
Create {
|
|
||||||
lang: self.lang,
|
|
||||||
title: self.title,
|
|
||||||
location: self.location,
|
|
||||||
text: self.text,
|
|
||||||
event_date: *self.event_date,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Update {
|
|
||||||
fn convert(self) -> Create {
|
|
||||||
Create {
|
|
||||||
lang: self.lang,
|
|
||||||
title: self.title,
|
|
||||||
location: self.location,
|
|
||||||
text: self.text,
|
|
||||||
event_date: *self.event_date,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create(conn: &PgConnection, event: Create) -> Result<Get, diesel::result::Error> {
|
|
||||||
diesel::insert_into(events::table)
|
|
||||||
.values(&event)
|
|
||||||
.get_result(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(conn: &PgConnection, lg: Lang) -> Result<Vec<Get>, diesel::result::Error> {
|
|
||||||
use schema::events::dsl::*;
|
|
||||||
|
|
||||||
events.filter(lang.eq(lg.0)).load::<Get>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_all(conn: &PgConnection) -> Result<Vec<Get>, diesel::result::Error> {
|
|
||||||
use schema::events::dsl::*;
|
|
||||||
events.load::<Get>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(
|
|
||||||
conn: &PgConnection,
|
|
||||||
idn: i32,
|
|
||||||
event: Create,
|
|
||||||
) -> Result<Get, diesel::result::Error> {
|
|
||||||
use schema::events::dsl::*;
|
|
||||||
diesel::update(events.find(idn))
|
|
||||||
.set(&event)
|
|
||||||
.get_result::<Get>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete(conn: &PgConnection, idn: i32) -> Result<usize, diesel::result::Error> {
|
|
||||||
use schema::events::dsl::*;
|
|
||||||
diesel::delete(events.find(idn)).execute(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/<lang>/events")]
|
|
||||||
pub fn api(pg: State<Mutex<PgConnection>>, lang: Lang) -> Result<Json<Vec<Get>>, Status> {
|
|
||||||
Ok(Json(
|
|
||||||
get(&*(pg.lock().unwrap()), lang).map_err(|_| Status::InternalServerError)?,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/events/add", data = "<form>")]
|
|
||||||
pub fn add(pg: State<Mutex<PgConnection>>, form: Form<Post>) -> Result<Redirect, Status> {
|
|
||||||
match create(&*(pg.lock().unwrap()), form.into_inner().convert()) {
|
|
||||||
Ok(_) => Ok(Redirect::to("/ui/events")),
|
|
||||||
Err(_) => Err(Status::InternalServerError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/events/del", data = "<form>")]
|
|
||||||
pub fn del(pg: State<Mutex<PgConnection>>, form: Form<Delete>) -> Result<Redirect, Status> {
|
|
||||||
match delete(&*(pg.lock().unwrap()), form.id) {
|
|
||||||
Ok(_) => Ok(Redirect::to("/ui/events")),
|
|
||||||
Err(_) => Err(Status::InternalServerError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/events/upd", data = "<form>")]
|
|
||||||
pub fn upd(pg: State<Mutex<PgConnection>>, form: Form<Update>) -> Result<Redirect, Status> {
|
|
||||||
match update(&*(pg.lock().unwrap()), form.id, form.into_inner().convert()) {
|
|
||||||
Ok(_) => Ok(Redirect::to("/ui/events")),
|
|
||||||
Err(_) => Err(Status::InternalServerError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/events")]
|
|
||||||
pub fn ui(_token: Token, pg: State<Mutex<PgConnection>>) -> Result<Template, Status> {
|
|
||||||
let ctx = get_all(&*(pg.lock().unwrap()))
|
|
||||||
.map_err(|_| Status::InternalServerError)?
|
|
||||||
.iter()
|
|
||||||
.map(|x| (x.id, x.clone()))
|
|
||||||
.collect::<HashMap<i32, Get>>();
|
|
||||||
Ok(Template::render("events", &ctx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -30,6 +30,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use utils::{db_conn, exit_with_error};
|
use utils::{db_conn, exit_with_error};
|
||||||
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Template {
|
fn index() -> Template {
|
||||||
let context: HashMap<&str, &str> = [("oauth", "/oauth")].iter().cloned().collect();
|
let context: HashMap<&str, &str> = [("oauth", "/oauth")].iter().cloned().collect();
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
pub mod events {
|
pub mod events {
|
||||||
use super::{defs::DateForm, Lang};
|
use crate::{
|
||||||
use crate::auth::Token;
|
auth::Token,
|
||||||
use chrono::naive::NaiveDate;
|
data::{defs::*, Lang},
|
||||||
|
};
|
||||||
|
use chrono::naive::*;
|
||||||
use diesel::{prelude::*, Insertable, Queryable};
|
use diesel::{prelude::*, Insertable, Queryable};
|
||||||
use rocket::{http::Status, request::Form, response::Redirect, State};
|
use rocket::{http::Status, request::Form, response::Redirect, State};
|
||||||
use rocket_contrib::{json::Json, templates::Template};
|
use rocket_contrib::{json::Json, templates::Template};
|
||||||
|
@ -35,7 +37,7 @@ pub mod events {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub location: String,
|
pub location: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub event_date: FormDate,
|
pub event_date: DateForm,
|
||||||
}
|
}
|
||||||
#[derive(Debug, FromForm)]
|
#[derive(Debug, FromForm)]
|
||||||
pub struct Update {
|
pub struct Update {
|
||||||
|
@ -44,7 +46,7 @@ pub mod events {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub location: String,
|
pub location: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub event_date: FormDate,
|
pub event_date: DateForm,
|
||||||
}
|
}
|
||||||
#[derive(Debug, FromForm)]
|
#[derive(Debug, FromForm)]
|
||||||
pub struct Delete {
|
pub struct Delete {
|
Loading…
Reference in New Issue
Block a user