event endpoint tweaks

This commit is contained in:
Mitchell Marino 2023-04-16 13:38:07 -05:00
parent 2d7e39d69c
commit 9e6168b5e1
2 changed files with 23 additions and 3 deletions

View File

@ -10,7 +10,7 @@ use sqlx::{query, query_as};
use crate::{
jwt::handle_token,
models::{Event, EventType, GetEventQuery, NewEventRequestEntry, Role},
models::{Event, EventType, EventWithConfirmed, GetEventQuery, NewEventRequestEntry, Role},
AppState,
};
@ -120,7 +120,7 @@ pub async fn get_recent_events(
};
let result = query_as!(
Event,
EventWithConfirmed,
r#"
SELECT
e.id,
@ -132,7 +132,8 @@ pub async fn get_recent_events(
e.points,
e.place,
e.price,
e.created_by
e.created_by,
ea.confirmed
FROM events e
INNER JOIN event_attendees ea
ON ea.event_id = e.id

View File

@ -63,6 +63,25 @@ pub struct GetEventQuery {
pub id: i32,
}
/// The model for an Event in the db.
#[derive(Clone, Serialize, Debug)]
pub struct EventWithConfirmed {
pub id: i32,
pub title: String,
pub description: String,
#[serde(with = "serde_datetime")]
pub time_start: NaiveDateTime,
#[serde(with = "serde_datetime")]
pub time_end: NaiveDateTime,
pub event_type: EventType,
pub points: i32,
pub place: Option<String>,
#[serde(with = "serde_big_decimal")]
pub price: BigDecimal,
pub confirmed: bool,
pub created_by: Option<i32>,
}
/// The model for an Event in the db.
#[derive(Clone, Serialize, Debug)]
pub struct Event {