various cleanups

This commit is contained in:
Cadey Ratio 2020-11-04 15:21:12 -05:00
parent c310891743
commit 4bf2aa6f01
3 changed files with 35 additions and 0 deletions

View File

@ -6,6 +6,7 @@ use crate::{
};
use diesel::prelude::*;
use rocket::State;
use rocket_contrib::json::Json;
use serde::Deserialize;
use std::fmt::Write;
@ -78,6 +79,20 @@ fn posse(item: Item, dw: &DiscordWebhook, tw: &Twitter, ma: &Mastodon) -> WebRes
pub static BLOG_FEED_URL: &'static str = "https://christine.website/blog.json";
#[post("/posse", format = "json", data = "<item>")]
#[instrument(skip(dw, tw, ma), err)]
pub fn notify(
item: Json<Item>,
tok: paseto::Token,
dw: State<DiscordWebhook>,
tw: State<Twitter>,
ma: State<Mastodon>,
) -> Result {
posse(item.into_inner(), &dw, &tw, &ma)?;
Ok(())
}
#[post("/blog/refresh")]
#[instrument(skip(conn, dw, tw, ma), err)]
pub fn refresh_blog(

View File

@ -81,6 +81,24 @@ pub fn current_front(conn: MainDatabase, tok: paseto::Token) -> Result<Json<Fron
}
}
#[get("/switches/current/text")]
#[instrument(skip(conn), err)]
pub fn current_front_text(conn: MainDatabase, tok: paseto::Token) -> Result<String> {
use schema::{members, switches};
let mut front: Vec<(models::Switch, models::Member)> = switches::table
.inner_join(members::table)
.order_by(switches::dsl::started_at.desc())
.limit(1)
.load(&*conn)
.map_err(Error::Database)?;
match front.pop() {
Some((_, member)) => Ok(member.cmene),
None => Err(Error::NotFound),
}
}
#[post("/switches/switch", data = "<who>")]
#[instrument(skip(conn, sc, pk), err)]
pub fn switch(

View File

@ -53,8 +53,10 @@ fn main() -> Result<()> {
.mount(
"/api",
routes![
api::posse::notify,
api::posse::refresh_blog,
api::switch::current_front,
api::switch::current_front_text,
api::switch::get,
api::switch::list,
api::switch::switch,