Create routing functions
This commit is contained in:
38
server/src/routes/machines.rs
Normal file
38
server/src/routes/machines.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
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"))
|
||||
}
|
Reference in New Issue
Block a user