week: Add week number to the DisplayTruth

In order to have all the relevant information for displaying a truth everywhere, add
its week number.
Fetch it during the week rendering and use it for the link back.
This commit is contained in:
trotFunky 2024-07-29 22:53:36 +01:00
parent 4e1e9facc6
commit 072889173f
3 changed files with 3 additions and 2 deletions

View file

@ -31,6 +31,7 @@ pub struct Truth {
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
pub struct DisplayTruth { pub struct DisplayTruth {
id: u32, id: u32,
week: u8,
number: u8, number: u8,
author_id: u16, author_id: u16,
rendered_text: String, rendered_text: String,

View file

@ -64,7 +64,7 @@ pub async fn week(week_number: u8, mut db: Connection<Db>, cookies: &CookieJar<'
vote_data: vote_data vote_data: vote_data
}) })
} else { } else {
let truths: Vec<DisplayTruth> = match sqlx::query_as("SELECT id, number, author_id, rendered_text FROM Truths WHERE week == $1 ORDER BY number") let truths: Vec<DisplayTruth> = match sqlx::query_as("SELECT id, week, number, author_id, rendered_text FROM Truths WHERE week == $1 ORDER BY number")
.bind(week_number) .bind(week_number)
.fetch_all(&mut **db).await { .fetch_all(&mut **db).await {
Ok(v) => v, Ok(v) => v,

View file

@ -5,7 +5,7 @@
{%- endif -%} {%- endif -%}
<div class="individual_truth"> <div class="individual_truth">
<a href="#{{ truth.number }}"><h3 id="{{ truth.number }}">Vérité {{ truth.number }}</h3></a> <a href="/{{ truth.week }}/#{{ truth.number }}"><h3 id="{{ truth.number }}">Vérité {{ truth.number }}</h3></a>
<p>{{ truth.rendered_text | safe }}</p> <p>{{ truth.rendered_text | safe }}</p>
{% if user.logged_in %} {% if user.logged_in %}
<hr/> <hr/>