work on events endpoint
This commit is contained in:
parent
a93704f998
commit
4a183b6820
48
src/events.rs
Normal file
48
src/events.rs
Normal file
@ -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<AppState>,
|
||||
Query(query): Query<EventsPreviewQuery>,
|
||||
) -> 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!({})))
|
||||
}
|
||||
@ -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!"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user