From 4a183b68207762fb6307ff12a2ce41a91dcb28da Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Mon, 10 Apr 2023 11:18:57 -0500 Subject: [PATCH] work on events endpoint --- src/events.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/events.rs diff --git a/src/events.rs b/src/events.rs new file mode 100644 index 0000000..a37adc8 --- /dev/null +++ b/src/events.rs @@ -0,0 +1,48 @@ +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use serde::{Deserialize, Serialize}; +use serde_json::json; +use sqlx::query; + +use crate::AppState; + +#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +pub struct EventsPreviewQuery { + count: u32, +} + +pub async fn get_events_preview( + State(app_state): State, + Query(query): Query, +) -> impl IntoResponse { + let result = query!( + r#" +SELECT + id, + title, + description, + time_start, + time_end, + event_type, + points, + place, + attending, + price, + created_by +FROM + events +WHERE + time_start BETWEEN now() AND now() + interval '1 week' +ORDER BY + time_start +LIMIT + 10; + "# + ); + + (StatusCode::OK, Json(json!({}))) +} diff --git a/src/main.rs b/src/main.rs index dd84c16..877001c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,6 @@ pub struct AppState { #[tokio::main] async fn main() { - // initialize tracing tracing_subscriber::fmt::init(); // Ex. @@ -41,6 +40,7 @@ async fn main() { .route("/", get(root)) .route("/user/signup", post(signup)) .route("/user/signin", post(signin)) + .route("/event/prview", get(events::get_events_preview)) .with_state(AppState { db_pool, jwt_key }); // run our app with hyper @@ -53,7 +53,6 @@ async fn main() { .unwrap(); } -// basic handler that responds with a static string async fn root() -> &'static str { "Hello, World!" }