mirror of
https://github.com/Blair-SGA-Dev-Team/blazerapp.git
synced 2024-11-24 21:51:16 -05:00
something
This commit is contained in:
parent
eab9749c72
commit
583b572b09
|
@ -6,7 +6,7 @@ use proc_macro2::*;
|
|||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Row(Ident, Ident, Ident, Ident);
|
||||
struct Row(Ident, TokenStream, TokenStream, TokenStream);
|
||||
|
||||
fn api_route_inner(item: TokenStream) -> TokenStream {
|
||||
let iterator = item.into_iter().clone().collect::<Vec<TokenTree>>();
|
||||
|
@ -72,11 +72,8 @@ fn api_route_inner(item: TokenStream) -> TokenStream {
|
|||
false
|
||||
}
|
||||
})
|
||||
.map(|x| match x.to_vec().get(0).unwrap().clone() {
|
||||
TokenTree::Ident(i) => i,
|
||||
n => panic!("Incorrect syntax at group => {:?}", n),
|
||||
})
|
||||
.collect::<Vec<Ident>>();
|
||||
.map(|x| x.into_iter().map(|x| x.clone()).collect::<TokenStream>())
|
||||
.collect::<Vec<TokenStream>>();
|
||||
rows.push(Row(
|
||||
name.clone(),
|
||||
vals.get(0).unwrap().clone(),
|
||||
|
@ -92,18 +89,18 @@ fn api_route_inner(item: TokenStream) -> TokenStream {
|
|||
|
||||
let schema_value = rows
|
||||
.iter()
|
||||
.map(|x| TokenTree::Ident(x.1.clone()))
|
||||
.collect::<Vec<TokenTree>>();
|
||||
.map(|x| x.1.clone())
|
||||
.collect::<Vec<TokenStream>>();
|
||||
|
||||
let get_value = rows
|
||||
.iter()
|
||||
.map(|x| TokenTree::Ident(x.2.clone()))
|
||||
.collect::<Vec<TokenTree>>();
|
||||
.map(|x| x.2.clone())
|
||||
.collect::<Vec<TokenStream>>();
|
||||
|
||||
let put_value = rows
|
||||
.iter()
|
||||
.map(|x| TokenTree::Ident(x.3.clone()))
|
||||
.collect::<Vec<TokenTree>>();
|
||||
.map(|x| x.3.clone())
|
||||
.collect::<Vec<TokenStream>>();
|
||||
|
||||
let impl_value = rows
|
||||
.iter()
|
||||
|
@ -116,7 +113,7 @@ fn api_route_inner(item: TokenStream) -> TokenStream {
|
|||
} else {
|
||||
let s = x.0.clone();
|
||||
quote! {
|
||||
#s: *self.#s,
|
||||
#s: self.#s.clone(),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -282,13 +279,15 @@ fn api_route_inner(item: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
#[get(#name_dir)]
|
||||
pub fn ui(_token: Token, pg: State<Mutex<PgConnection>>) -> Result<Template, Status> {
|
||||
pub fn eui(_token: Token, pg: State<Mutex<PgConnection>>) -> Result<Template, Status> {
|
||||
let mut hash: HashMap<&str, HashMap<i32, Get>> = HashMap::new();
|
||||
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(#name_literal, &ctx))
|
||||
hash.insert("ctx", ctx);
|
||||
Ok(Template::render(#name_literal, &hash))
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -13,3 +13,20 @@ CREATE TABLE events (
|
|||
location VARCHAR NOT NULL,
|
||||
event_date DATE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE teachers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
lang VARCHAR,
|
||||
name VARCHAR NOT NULL,
|
||||
emails VARCHAR[]
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE new (
|
||||
id SERIAL PRIMARY KEY,
|
||||
lang VARCHAR,
|
||||
image VARCHAR,
|
||||
name VARCHAR NOT NULL,
|
||||
new_date DATE
|
||||
);
|
||||
|
|
|
@ -23,9 +23,10 @@ impl<'a> FromParam<'a> for Lang<'a> {
|
|||
}
|
||||
|
||||
pub mod defs {
|
||||
use chrono::naive::NaiveDate;
|
||||
use chrono::naive::{NaiveDate, NaiveTime};
|
||||
use rocket::{http::RawStr, request::FromFormValue};
|
||||
use std::ops::Deref;
|
||||
use rocket::response::NamedFile;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DateForm(NaiveDate);
|
||||
|
@ -54,6 +55,92 @@ pub mod defs {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TimeForm(NaiveTime);
|
||||
|
||||
impl Deref for TimeForm {
|
||||
type Target = NaiveTime;
|
||||
|
||||
fn deref(&self) -> &NaiveTime {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'v> FromFormValue<'v> for TimeForm {
|
||||
type Error = ();
|
||||
|
||||
fn from_form_value(value: &'v RawStr) -> Result<TimeForm, ()> {
|
||||
let value_uri = match value.url_decode() {
|
||||
Ok(n) => n,
|
||||
Err(_) => return Err(()),
|
||||
};
|
||||
let naivedate = NaiveTime::parse_from_str(&value_uri[..], "%I:%M %p");
|
||||
match naivedate {
|
||||
Ok(n) => Ok(TimeForm(n)),
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EmailList(Vec<String>);
|
||||
|
||||
impl Deref for EmailList {
|
||||
type Target = Vec<String>;
|
||||
|
||||
fn deref(&self) -> &Vec<String> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'v> FromFormValue<'v> for EmailList {
|
||||
type Error = ();
|
||||
fn from_form_value(value: &'v RawStr) -> Result<EmailList, ()> {
|
||||
let mut value_uri = match value.url_decode() {
|
||||
Ok(n) => n,
|
||||
Err(_) => return Err(()),
|
||||
};
|
||||
|
||||
Ok(EmailList((&mut value_uri[..])
|
||||
.split(|x| x == ' ')
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>().clone()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Image(String);
|
||||
|
||||
impl Deref for Image {
|
||||
type Target = String;
|
||||
|
||||
fn deref(&self) -> &String {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'v> FromFormValue<'v> for Image {
|
||||
type Error = ();
|
||||
|
||||
fn from_form_value(value: &'v RawStr) -> Result<Image, ()> {
|
||||
/*
|
||||
println!("{:?}", value);
|
||||
let file = NamedFile::open(value.to_string());
|
||||
println!("{:?}", file);
|
||||
|
||||
Ok(Image(String::from("pepega")))
|
||||
*/
|
||||
|
||||
let mut value_uri = match value.url_decode() {
|
||||
Ok(n) => n,
|
||||
Err(_) => return Err(()),
|
||||
};
|
||||
Ok(Image(value_uri))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
api_route! {
|
||||
|
@ -65,14 +152,73 @@ api_route! {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
api_route! {
|
||||
teachers {
|
||||
name: (Text, String, String),
|
||||
emails: (Array<Text>, Vec<String>, Vec<String>),
|
||||
emails: (Array<Text>, Vec<String>, EmailList),
|
||||
}
|
||||
}
|
||||
*/
|
||||
//TODO: fix value parsing to read a TokenStream until the `,` to allow for containerized types in
|
||||
//the macro
|
||||
|
||||
api_route! {
|
||||
announcements {
|
||||
message: (Text, String, String),
|
||||
teacher: (Text, String, String),
|
||||
date: (Date, NaiveDate, DateForm),
|
||||
time: (Time, NaiveTime, TimeForm),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
clubs {
|
||||
name: (Text, String, String),
|
||||
meeting: (Text, String, String),
|
||||
link: (Text, String, String),
|
||||
sponsor: (Text, String, String),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
lunch_events {
|
||||
title: (Text, String, String),
|
||||
text: (Text, String, String),
|
||||
location: (Text, String, String),
|
||||
time: (Time, NaiveTime, TimeForm),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
ssl_ops {
|
||||
title: (Text, String, String),
|
||||
text: (Text, String, String),
|
||||
location: (Text, String, String),
|
||||
teacher: (Text, String, String),
|
||||
time: (Time, NaiveTime, TimeForm),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
calendar {
|
||||
time: (Time, NaiveTime, TimeForm),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
polls {
|
||||
url: (Text, String, String),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
new {
|
||||
image: (Text, String, Image),
|
||||
name: (Text, String, String),
|
||||
new_date: (Date, NaiveDate, DateForm),
|
||||
}
|
||||
}
|
||||
|
||||
api_route! {
|
||||
important {
|
||||
image: (Text, String, Image),
|
||||
text: (Text, String, String),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,14 +75,23 @@ fn rocket(port: u16, address: String, env: Environment, pg: PgConnection, sa: Se
|
|||
"/",
|
||||
routes![home, home_not_logged_in, login, auth::callback, auth::oauth, static_files],
|
||||
)
|
||||
.mount("/api", routes![data::events::api])
|
||||
.mount("/api", routes![
|
||||
data::events::api,
|
||||
data::teachers::api,
|
||||
data::announcements::api,
|
||||
data::clubs::api,
|
||||
data::lunch_events::api,
|
||||
data::ssl_ops::api,
|
||||
data::calendar::api,
|
||||
data::polls::api,
|
||||
])
|
||||
.mount(
|
||||
"/ui",
|
||||
routes![
|
||||
data::events::ui,
|
||||
data::events::add,
|
||||
data::events::del,
|
||||
data::events::upd
|
||||
data::events::eui, data::teachers::eui, data::announcements::eui, data::clubs::eui, data::lunch_events::eui, data::ssl_ops::eui, data::calendar::eui, data::polls::eui, data::new::eui, data::important::eui,
|
||||
data::events::upd, data::teachers::upd, data::announcements::upd, data::clubs::upd, data::lunch_events::upd, data::ssl_ops::upd, data::calendar::upd, data::polls::upd, data::new::upd, data::important::upd,
|
||||
data::events::del, data::teachers::del, data::announcements::del, data::clubs::del, data::lunch_events::del, data::ssl_ops::del, data::calendar::del, data::polls::del, data::new::del, data::important::del,
|
||||
data::events::add, data::teachers::add, data::announcements::add, data::clubs::add, data::lunch_events::add, data::ssl_ops::add, data::calendar::add, data::polls::add, data::new::add, data::important::add,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
body {
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
<!-- vim: set ft=html: -->
|
||||
{{! vim: set ft=html: }}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<p>{{6.title}}</p>
|
||||
{{#each ctx}}
|
||||
<p>{{id}} {{lang}} {{title}} {{location}} {{text}} {{event_date}}</p>
|
||||
{{/each}}
|
||||
<br>
|
||||
<p>add</p>
|
||||
<form action="events/add" method="post">
|
||||
<input type="text", id="lang", name="lang">
|
||||
<input type="text", id="title", name="title">
|
||||
|
@ -15,11 +18,25 @@
|
|||
<input type="text", id="event_date", name="event_date">
|
||||
<input type="submit", value="Submit">
|
||||
</form>
|
||||
|
||||
<p>del</p>
|
||||
<form action="events/del" method="post">
|
||||
<input type="number", id="id", name="id">
|
||||
<input type="submit", value="Submit">
|
||||
</form>
|
||||
|
||||
|
||||
<p>upd</p>
|
||||
<form action="events/upd" method="post">
|
||||
<input type="number", id="id", name="id">
|
||||
<input type="text", id="lang", name="lang">
|
||||
<input type="text", id="title", name="title">
|
||||
<input type="text", id="location", name="location">
|
||||
<input type="text", id="text", name="text">
|
||||
<input type="text", id="event_date", name="event_date">
|
||||
<input type="submit", value="Submit">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</head>
|
||||
</html>
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<a href="/ui/events">Events</a>
|
||||
<a href="/ui/new">New</a>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<!-- vim: set ft=html: -->
|
||||
{{! vim: set ft=html: }}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
|
|
18
cms/templates/new.html.hbs
Normal file
18
cms/templates/new.html.hbs
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{! vim: set ft=html: }}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<p>add</p>
|
||||
<form action="new/add" method="post">
|
||||
<input type="text", id="lang", name="lang">
|
||||
<input type="file" name="image", id="image", accept="image/png">
|
||||
<input type="text", id="name", name="name">
|
||||
<input type="text", id="new_date", name="new_date">
|
||||
<input type="submit", value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</head>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user