Files
gamenight/backend-actix/src/request/location.rs

28 lines
911 B
Rust

use crate::models::location::Location;
use crate::request::authorization::AuthUser;
use crate::request::error::ApiError;
use actix_web::http::header::ContentType;
use actix_web::{get, web, HttpResponse, Responder};
use gamenight_database::{DbPool, GetConnection};
use uuid::Uuid;
#[get("/location/{locationId}")]
pub async fn get_locations(
pool: web::Data<DbPool>,
_user: AuthUser,
location_id: web::Path<Uuid>,
) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
let location = gamenight_database::location::load_location(&mut conn, location_id.into_inner())?;
let model = Location {
id: location.id.to_string(),
name: location.name.clone(),
note: location.note.clone(),
address: location.address.clone(),
};
Ok(HttpResponse::Ok()
.content_type(ContentType::json())
.body(serde_json::to_string(&model)?))
}