2018-04-23 10:54:37 +00:00
|
|
|
use rocket::request::Form;
|
|
|
|
use rocket::response::Redirect;
|
|
|
|
use rocket_contrib::Template;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use utils;
|
|
|
|
use db_conn::DbConn;
|
|
|
|
use models::blogs::*;
|
|
|
|
use models::instance::Instance;
|
2018-04-23 11:10:15 +00:00
|
|
|
use models::user::User;
|
2018-04-23 10:54:37 +00:00
|
|
|
|
|
|
|
#[get("/~/<name>")]
|
|
|
|
fn details(name: String) -> String {
|
|
|
|
format!("Welcome on ~{}", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/blogs/new")]
|
2018-04-23 11:10:15 +00:00
|
|
|
fn new(_user: User) -> Template {
|
2018-04-23 10:54:37 +00:00
|
|
|
Template::render("blogs/new", HashMap::<String, i32>::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
struct NewBlogForm {
|
|
|
|
pub title: String
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/blogs/new", data = "<data>")]
|
2018-04-23 11:10:15 +00:00
|
|
|
fn create(conn: DbConn, data: Form<NewBlogForm>, _user: User) -> Redirect {
|
2018-04-23 10:54:37 +00:00
|
|
|
let inst = Instance::get_local(&*conn).unwrap();
|
|
|
|
let form = data.get();
|
|
|
|
let slug = utils::make_actor_id(form.title.to_string());
|
|
|
|
|
2018-04-23 13:12:59 +00:00
|
|
|
Blog::insert(&*conn, NewBlog::new_local(
|
|
|
|
slug.to_string(),
|
|
|
|
form.title.to_string(),
|
|
|
|
String::from(""),
|
|
|
|
inst.id
|
|
|
|
)).update_boxes(&*conn);
|
2018-04-23 10:54:37 +00:00
|
|
|
|
|
|
|
Redirect::to(format!("/~/{}", slug).as_str())
|
|
|
|
}
|