1
Fork 0
holycow/holycow_backend/src/routes/matches.rs

19 lines
458 B
Rust
Raw Normal View History

2024-11-29 11:56:23 +00:00
use axum::http::StatusCode;
use axum::Json;
use diesel::{Connection, PgConnection};
use crate::config;
use crate::database::model::Match;
#[axum::debug_handler]
pub async fn get_all()
-> Result<Json<Vec<Match>>, StatusCode>
{
let mut conn = PgConnection::establish(config::DATABASE_URL())
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let matches = Match::all(&mut conn)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(matches))
}