feat: Make text_content nullable

This commit is contained in:
2026-06-02 12:34:49 +02:00
parent 0f3c29d7d4
commit fdcacc738d
3 changed files with 14 additions and 7 deletions
+3 -3
View File
@@ -40,7 +40,7 @@ impl std::fmt::Display for AnnouncementFlag {
pub struct Announcement {
pub id: i64,
pub author: String,
pub text_content: String,
pub text_content: Option<String>,
pub start_date: String,
pub end_date: String,
pub created_at: String,
@@ -53,7 +53,7 @@ pub fn open(db_path: &str) -> Result<Connection> {
"CREATE TABLE IF NOT EXISTS announcements (
id INTEGER PRIMARY KEY AUTOINCREMENT,
author TEXT NOT NULL,
text_content TEXT NOT NULL,
text_content TEXT,
start_date TEXT NOT NULL,
end_date TEXT NOT NULL,
flags TEXT NOT NULL DEFAULT '[]',
@@ -138,7 +138,7 @@ pub fn count_all(conn: &Connection, filter_date: Option<&str>) -> Result<u64> {
pub fn create(
conn: &Connection,
author: &str,
text_content: &str,
text_content: Option<&str>,
start_date: &str,
end_date: &str,
flags: &[AnnouncementFlag],
+10 -3
View File
@@ -109,11 +109,16 @@ async fn management_page(
})
.collect::<Vec<_>>()
.join(" ");
let text_display = a
.text_content
.as_ref()
.map(|t| escape_html(t))
.unwrap_or_else(|| "".to_string());
format!(
include_str!("../../templates/announcement_row.html"),
id = a.id,
author = escape_html(&a.author),
text = escape_html(&a.text_content),
text = text_display,
start = a.start_date,
end = a.end_date,
flags_display = flags_display,
@@ -236,7 +241,7 @@ fn render_pagination(current: u32, total: u32, count: u64, filter_param: &str) -
#[derive(Deserialize)]
struct CreateInput {
author: String,
text_content: String,
text_content: Option<String>,
start_date: String,
end_date: String,
#[serde(default, deserialize_with = "one_or_many")]
@@ -258,8 +263,10 @@ async fn create_announcement(
.filter_map(|s| s.parse::<AnnouncementFlag>().ok())
.collect();
let text = input.text_content.filter(|s| !s.is_empty());
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 (
StatusCode::INTERNAL_SERVER_ERROR,
[("location", "/")],
+1 -1
View File
@@ -115,7 +115,7 @@
</label>
<label>
Text
<textarea name="text_content" placeholder="Announcement text&hellip;" required></textarea>
<textarea name="text_content" placeholder="Announcement text&hellip;"></textarea>
</label>
<label>
Start date