Improve api schema
This commit is contained in:
parent
f23bb48fa1
commit
f9ad8f9399
9 changed files with 123 additions and 164 deletions
|
@ -8,6 +8,7 @@ use sqlx::{Pool, Sqlite};
|
|||
|
||||
use crate::app_state;
|
||||
use crate::app_state::AppState;
|
||||
use crate::handlers::EmgauwaMessage;
|
||||
|
||||
#[get("/controllers")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
|
||||
|
@ -88,5 +89,5 @@ pub async fn delete(
|
|||
.await??;
|
||||
|
||||
DbController::delete_by_uid(&mut pool_conn, uid).await?;
|
||||
Ok(HttpResponse::Ok().json("controller got deleted"))
|
||||
Ok(HttpResponse::Ok().emgauwa_message("controller got deleted"))
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use emgauwa_common::types::{
|
|||
|
||||
use crate::app_state;
|
||||
use crate::app_state::AppState;
|
||||
use crate::handlers::EmgauwaMessage;
|
||||
|
||||
#[get("/macros")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
|
||||
|
@ -98,7 +99,7 @@ pub async fn delete(
|
|||
let uid = EmgauwaUid::try_from(macro_uid.as_str())?;
|
||||
|
||||
DbMacro::delete_by_uid(&mut pool_conn, uid).await?;
|
||||
Ok(HttpResponse::Ok().json("macro got deleted"))
|
||||
Ok(HttpResponse::Ok().emgauwa_message("macro got deleted"))
|
||||
}
|
||||
|
||||
#[put("/macros/{macro_id}/execute")]
|
||||
|
@ -160,5 +161,5 @@ pub async fn execute(
|
|||
.await??;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().finish()) // TODO add a message?
|
||||
Ok(HttpResponse::Ok().emgauwa_message("macro got executed"))
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use sqlx::{Pool, Sqlite};
|
|||
|
||||
use crate::app_state;
|
||||
use crate::app_state::AppState;
|
||||
use crate::handlers::EmgauwaMessage;
|
||||
|
||||
#[get("/relays")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
|
||||
|
@ -181,5 +182,5 @@ pub async fn pulse(
|
|||
})
|
||||
.await??;
|
||||
|
||||
Ok(HttpResponse::Ok().finish()) // TODO add a message?
|
||||
Ok(HttpResponse::Ok().emgauwa_message("pulse sent"))
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use sqlx::{Pool, Sqlite};
|
|||
|
||||
use crate::app_state;
|
||||
use crate::app_state::AppState;
|
||||
use crate::handlers::EmgauwaMessage;
|
||||
|
||||
#[get("/schedules")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
|
||||
|
@ -190,7 +191,7 @@ pub async fn delete(
|
|||
ScheduleUid::On => Err(EmgauwaError::from(ApiError::ProtectedSchedule)),
|
||||
ScheduleUid::Any(_) => {
|
||||
DbSchedule::delete_by_uid(&mut pool_conn, uid).await?;
|
||||
Ok(HttpResponse::Ok().json("schedule got deleted"))
|
||||
Ok(HttpResponse::Ok().emgauwa_message("schedule got deleted"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use emgauwa_common::errors::{DatabaseError, EmgauwaError};
|
|||
use emgauwa_common::models::{FromDbModel, Tag};
|
||||
use emgauwa_common::types::RequestTagCreate;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use crate::handlers::EmgauwaMessage;
|
||||
|
||||
#[get("/tags")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
|
||||
|
@ -43,7 +44,7 @@ pub async fn delete(
|
|||
let (tag_name,) = path.into_inner();
|
||||
|
||||
DbTag::delete_by_tag(&mut pool_conn, &tag_name).await?;
|
||||
Ok(HttpResponse::Ok().json("tag got deleted"))
|
||||
Ok(HttpResponse::Ok().emgauwa_message("tag got deleted"))
|
||||
}
|
||||
|
||||
#[post("/tags")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue