19 lines
458 B
Rust
19 lines
458 B
Rust
|
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))
|
||
|
}
|