Add fmt options and move handlers
This commit is contained in:
parent
50bcac2a1b
commit
fdca5b7277
28 changed files with 85 additions and 70 deletions
emgauwa-core/src/handlers/v1
24
emgauwa-core/src/handlers/v1/relays.rs
Normal file
24
emgauwa-core/src/handlers/v1/relays.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use actix_web::{get, web, HttpResponse};
|
||||
use emgauwa_lib::db::DbRelay;
|
||||
use emgauwa_lib::models::{convert_db_list, Relay};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
use crate::handlers::errors::ApiError;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RequestRelay {
|
||||
name: String,
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[get("/api/v1/relays")]
|
||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, ApiError> {
|
||||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let db_relays = DbRelay::get_all(&mut pool_conn).await?;
|
||||
|
||||
let relays: Vec<Relay> = convert_db_list(&mut pool_conn, db_relays)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(relays))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue