Files
Arkendro/server/src/routes/machines.rs

39 lines
1.1 KiB
Rust

use crate::utils::{auth::*, error::*, models::*, DbPool};
use crate::controllers::machines::MachinesController;
use axum::{
extract::{Path, State},
response::Json,
};
pub async fn register_machine(
State(pool): State<DbPool>,
Json(request): Json<RegisterMachineRequest>,
) -> Result<Json<Machine>, AppError> {
let machine = MachinesController::register_machine(
&pool,
&request.code,
&request.uuid,
&request.name,
)
.await?;
Ok(success_response(machine))
}
pub async fn get_machines(
auth_user: AuthUser,
State(pool): State<DbPool>,
) -> Result<Json<Vec<Machine>>, AppError> {
let machines = MachinesController::get_machines_for_user(&pool, &auth_user.user).await?;
Ok(success_response(machines))
}
pub async fn delete_machine(
auth_user: AuthUser,
State(pool): State<DbPool>,
Path(machine_id): Path<i64>,
) -> Result<Json<serde_json::Value>, AppError> {
MachinesController::delete_machine(&pool, machine_id, &auth_user.user).await?;
Ok(success_message("Machine deleted successfully"))
}