Add actual templates for everything

This commit is contained in:
Bat
2018-05-09 20:09:52 +01:00
parent ae60d5961c
commit 292f4d6b27
12 changed files with 77 additions and 12 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ use models::instance::Instance;
use schema::blogs;
#[derive(Queryable, Identifiable)]
#[derive(Queryable, Identifiable, Serialize)]
pub struct Blog {
pub id: i32,
pub actor_id: String,
+1 -1
View File
@@ -5,7 +5,7 @@ use std::iter::Iterator;
use models::users::User;
use schema::{instances, users};
#[derive(Identifiable, Queryable)]
#[derive(Identifiable, Queryable, Serialize)]
pub struct Instance {
pub id: i32,
pub public_domain: String,
+1 -1
View File
@@ -12,7 +12,7 @@ use models::users::User;
use models::post_authors::PostAuthor;
use schema::posts;
#[derive(Queryable, Identifiable)]
#[derive(Queryable, Identifiable, Serialize)]
pub struct Post {
pub id: i32,
pub blog_id: i32,
+5 -2
View File
@@ -14,8 +14,11 @@ use models::users::User;
use utils;
#[get("/~/<name>", rank = 2)]
fn details(name: String) -> String {
format!("Welcome on ~{}", name)
fn details(name: String, conn: DbConn) -> Template {
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
Template::render("blogs/details", json!({
"blog": blog
}))
}
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
+7 -3
View File
@@ -8,13 +8,17 @@ use db_conn::DbConn;
use models::instance::*;
#[get("/")]
fn index(conn: DbConn) -> String {
fn index(conn: DbConn) -> Template {
match Instance::get_local(&*conn) {
Some(inst) => {
format!("Welcome on {}", inst.name)
Template::render("instance/index", json!({
"instance": inst
}))
}
None => {
String::from("Not initialized")
Template::render("errors/500", json!({
"error_message": "You need to configure your instance before using it."
}))
}
}
}
+5 -2
View File
@@ -16,10 +16,13 @@ use models::users::User;
use utils;
#[get("/~/<blog>/<slug>", rank = 4)]
fn details(blog: String, slug: String, conn: DbConn) -> String {
fn details(blog: String, slug: String, conn: DbConn) -> Template {
let blog = Blog::find_by_actor_id(&*conn, blog).unwrap();
let post = Post::find_by_slug(&*conn, slug).unwrap();
format!("{} in {}", post.title, blog.title)
Template::render("posts/details", json!({
"post": post,
"blog": blog
}))
}
#[get("/~/<_blog>/<slug>", rank = 3, format = "application/activity+json")]
+2 -2
View File
@@ -14,8 +14,8 @@ use models::instance::Instance;
use models::users::*;
#[get("/me")]
fn me(user: User) -> String {
format!("Logged in as {}", user.username.to_string())
fn me(user: User) -> Redirect {
Redirect::to(format!("/@/{}", user.username).as_ref())
}
#[get("/@/<name>", rank = 2)]