Add trait for db_model to model conversion
This commit is contained in:
parent
8dab4b9a50
commit
cb47dcda5c
5 changed files with 92 additions and 59 deletions
emgauwa-lib/src/handlers/v1
|
@ -6,7 +6,7 @@ use sqlx::{Pool, Sqlite};
|
|||
use crate::db::DbRelay;
|
||||
|
||||
use crate::handlers::errors::ApiError;
|
||||
use crate::models::Relay;
|
||||
use crate::models::{convert_db_list, Relay};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RequestRelay {
|
||||
|
@ -18,14 +18,11 @@ pub struct RequestRelay {
|
|||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, ApiError> {
|
||||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let relays = DbRelay::get_all(&mut pool_conn).await?;
|
||||
let db_relays = DbRelay::get_all(&mut pool_conn).await?;
|
||||
|
||||
let return_relays: Vec<Relay> = relays
|
||||
.into_iter()
|
||||
.map(|s| Relay::from_db_relay(s, &mut pool_conn))
|
||||
.collect();
|
||||
let relays: Vec<Relay> = convert_db_list(&mut pool_conn, db_relays)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(return_relays))
|
||||
Ok(HttpResponse::Ok().json(relays))
|
||||
}
|
||||
|
||||
//#[get("/api/v1/tags/tag/{tag}")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue