mirror of https://github.com/raftario/filite.git
Added highlight field to texts
This commit is contained in:
parent
9924925911
commit
342182da72
|
@ -1,5 +1,6 @@
|
|||
CREATE TABLE texts (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
contents TEXT NOT NULL,
|
||||
highlight INTEGER NOT NULL,
|
||||
created INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);
|
||||
|
|
|
@ -280,6 +280,7 @@ pub mod texts {
|
|||
#[derive(Deserialize)]
|
||||
pub struct PutText {
|
||||
pub contents: String,
|
||||
pub highlight: bool,
|
||||
}
|
||||
|
||||
/// PUT a new text entry
|
||||
|
@ -291,6 +292,7 @@ pub mod texts {
|
|||
Either::A(put_then!(web::block(move || queries::texts::replace(
|
||||
id,
|
||||
&body.contents,
|
||||
body.highlight,
|
||||
pool
|
||||
))))
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ pub mod texts {
|
|||
pub id: i32,
|
||||
/// Text contents
|
||||
pub contents: String,
|
||||
/// Whether to use syntax highlighting or not when serving that text
|
||||
pub highlight: i32,
|
||||
/// Creation date and time as a UNIX timestamp
|
||||
pub created: i32,
|
||||
}
|
||||
|
@ -73,7 +75,9 @@ pub mod texts {
|
|||
pub struct NewText<'a> {
|
||||
/// Primary key, its radix 36 value is used as an url
|
||||
pub id: i32,
|
||||
/// Text to serve
|
||||
/// Text contents
|
||||
pub contents: &'a str,
|
||||
/// Whether to use syntax highlighting or not when serving that text
|
||||
pub highlight: i32,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,11 +177,20 @@ pub mod texts {
|
|||
find!(texts, Text);
|
||||
|
||||
/// REPLACE a text entry
|
||||
pub fn replace(r_id: i32, r_contents: &str, pool: Data<Pool>) -> QueryResult<Text> {
|
||||
pub fn replace(
|
||||
r_id: i32,
|
||||
r_contents: &str,
|
||||
r_highlight: bool,
|
||||
pool: Data<Pool>,
|
||||
) -> QueryResult<Text> {
|
||||
let conn: &SqliteConnection = &pool.get().unwrap();
|
||||
let new_text = NewText {
|
||||
id: r_id,
|
||||
contents: r_contents,
|
||||
highlight: match r_highlight {
|
||||
true => 1,
|
||||
false => 2,
|
||||
},
|
||||
};
|
||||
diesel::replace_into(table)
|
||||
.values(&new_text)
|
||||
|
|
|
@ -18,6 +18,7 @@ table! {
|
|||
texts (id) {
|
||||
id -> Integer,
|
||||
contents -> Text,
|
||||
highlight -> Integer,
|
||||
created -> Integer,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue