|
@@ -6,8 +6,8 @@ use rocket_contrib::templates::Template;
|
6
|
6
|
use std::collections::HashMap;
|
7
|
7
|
|
8
|
8
|
use crate::connection::DbConn;
|
9
|
|
-use crate::gists;
|
10
|
|
-use crate::gists::{Gist, InsertableGist};
|
|
9
|
+use crate::snippet;
|
|
10
|
+use crate::snippet::{InsertableSnippet, Snippet};
|
11
|
11
|
|
12
|
12
|
fn error_response(error: Error) -> Status {
|
13
|
13
|
match error {
|
|
@@ -22,34 +22,34 @@ pub fn index() -> Template {
|
22
|
22
|
Template::render("index", &context)
|
23
|
23
|
}
|
24
|
24
|
|
25
|
|
-#[get("/gists/<id>")]
|
26
|
|
-pub fn show_gist(id: i32, connection: DbConn) -> Template {
|
27
|
|
- let result = match gists::get(&connection, id) {
|
28
|
|
- Ok(gist) => Some(gist),
|
|
25
|
+#[get("/snippets/<id>")]
|
|
26
|
+pub fn show_snippet(id: i32, connection: DbConn) -> Template {
|
|
27
|
+ let result = match snippet::get(&connection, id) {
|
|
28
|
+ Ok(snippet) => Some(snippet),
|
29
|
29
|
Err(_) => None,
|
30
|
30
|
};
|
31
|
31
|
|
32
|
32
|
let (title, body) = result.map_or(
|
33
|
33
|
(
|
34
|
|
- String::from("404 - Gist not found"),
|
35
|
|
- format!("<h3'>{}</h3>", "Gist not found"),
|
|
34
|
+ String::from("404 - Snippet not found"),
|
|
35
|
+ format!("<h3'>{}</h3>", "Snippet not found"),
|
36
|
36
|
),
|
37
|
|
- |gist| (gist.title, gist.formatted_body),
|
|
37
|
+ |snippet| (snippet.title, snippet.formatted_body),
|
38
|
38
|
);
|
39
|
39
|
|
40
|
40
|
let mut context: HashMap<&str, String> = HashMap::new();
|
41
|
41
|
context.insert("title", title);
|
42
|
42
|
context.insert("body", body);
|
43
|
43
|
|
44
|
|
- Template::render("gists/show", &context)
|
|
44
|
+ Template::render("snippets/show", &context)
|
45
|
45
|
}
|
46
|
46
|
|
47
|
|
-#[post("/api/gists", format = "application/json", data = "<gist>")]
|
48
|
|
-pub fn create_gist<'a>(
|
49
|
|
- gist: Json<InsertableGist>,
|
|
47
|
+#[post("/api/snippets", format = "application/json", data = "<snippet>")]
|
|
48
|
+pub fn create_snippet<'a>(
|
|
49
|
+ snippet: Json<InsertableSnippet>,
|
50
|
50
|
connection: DbConn,
|
51
|
|
-) -> Result<status::Created<Json<Gist>>, Status> {
|
52
|
|
- gists::insert(gist.into_inner(), &connection)
|
53
|
|
- .map(|gist| status::Created(String::from(""), Some(Json(gist))))
|
|
51
|
+) -> Result<status::Created<Json<Snippet>>, Status> {
|
|
52
|
+ snippet::insert(snippet.into_inner(), &connection)
|
|
53
|
+ .map(|snippet| status::Created(String::from(""), Some(Json(snippet))))
|
54
|
54
|
.map_err(|error| error_response(error))
|
55
|
55
|
}
|