feat: Make text_content nullable
This commit is contained in:
@@ -40,7 +40,7 @@ impl std::fmt::Display for AnnouncementFlag {
|
|||||||
pub struct Announcement {
|
pub struct Announcement {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub text_content: String,
|
pub text_content: Option<String>,
|
||||||
pub start_date: String,
|
pub start_date: String,
|
||||||
pub end_date: String,
|
pub end_date: String,
|
||||||
pub created_at: String,
|
pub created_at: String,
|
||||||
@@ -53,7 +53,7 @@ pub fn open(db_path: &str) -> Result<Connection> {
|
|||||||
"CREATE TABLE IF NOT EXISTS announcements (
|
"CREATE TABLE IF NOT EXISTS announcements (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
author TEXT NOT NULL,
|
author TEXT NOT NULL,
|
||||||
text_content TEXT NOT NULL,
|
text_content TEXT,
|
||||||
start_date TEXT NOT NULL,
|
start_date TEXT NOT NULL,
|
||||||
end_date TEXT NOT NULL,
|
end_date TEXT NOT NULL,
|
||||||
flags TEXT NOT NULL DEFAULT '[]',
|
flags TEXT NOT NULL DEFAULT '[]',
|
||||||
@@ -138,7 +138,7 @@ pub fn count_all(conn: &Connection, filter_date: Option<&str>) -> Result<u64> {
|
|||||||
pub fn create(
|
pub fn create(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
author: &str,
|
author: &str,
|
||||||
text_content: &str,
|
text_content: Option<&str>,
|
||||||
start_date: &str,
|
start_date: &str,
|
||||||
end_date: &str,
|
end_date: &str,
|
||||||
flags: &[AnnouncementFlag],
|
flags: &[AnnouncementFlag],
|
||||||
|
|||||||
+10
-3
@@ -109,11 +109,16 @@ async fn management_page(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
let text_display = a
|
||||||
|
.text_content
|
||||||
|
.as_ref()
|
||||||
|
.map(|t| escape_html(t))
|
||||||
|
.unwrap_or_else(|| "—".to_string());
|
||||||
format!(
|
format!(
|
||||||
include_str!("../../templates/announcement_row.html"),
|
include_str!("../../templates/announcement_row.html"),
|
||||||
id = a.id,
|
id = a.id,
|
||||||
author = escape_html(&a.author),
|
author = escape_html(&a.author),
|
||||||
text = escape_html(&a.text_content),
|
text = text_display,
|
||||||
start = a.start_date,
|
start = a.start_date,
|
||||||
end = a.end_date,
|
end = a.end_date,
|
||||||
flags_display = flags_display,
|
flags_display = flags_display,
|
||||||
@@ -236,7 +241,7 @@ fn render_pagination(current: u32, total: u32, count: u64, filter_param: &str) -
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct CreateInput {
|
struct CreateInput {
|
||||||
author: String,
|
author: String,
|
||||||
text_content: String,
|
text_content: Option<String>,
|
||||||
start_date: String,
|
start_date: String,
|
||||||
end_date: String,
|
end_date: String,
|
||||||
#[serde(default, deserialize_with = "one_or_many")]
|
#[serde(default, deserialize_with = "one_or_many")]
|
||||||
@@ -258,8 +263,10 @@ async fn create_announcement(
|
|||||||
.filter_map(|s| s.parse::<AnnouncementFlag>().ok())
|
.filter_map(|s| s.parse::<AnnouncementFlag>().ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let text = input.text_content.filter(|s| !s.is_empty());
|
||||||
|
|
||||||
let conn = db.lock().await;
|
let conn = db.lock().await;
|
||||||
if let Err(e) = db::create(&conn, &input.author, &input.text_content, &input.start_date, &input.end_date, &flags) {
|
if let Err(e) = db::create(&conn, &input.author, text.as_deref(), &input.start_date, &input.end_date, &flags) {
|
||||||
return (
|
return (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
[("location", "/")],
|
[("location", "/")],
|
||||||
|
|||||||
@@ -115,7 +115,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Text
|
Text
|
||||||
<textarea name="text_content" placeholder="Announcement text…" required></textarea>
|
<textarea name="text_content" placeholder="Announcement text…"></textarea>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Start date
|
Start date
|
||||||
|
|||||||
Reference in New Issue
Block a user