View services
This commit is contained in:
parent
b7b6b63173
commit
c168bca044
@ -1,7 +1,7 @@
|
|||||||
use realtor_lp_types::domain::view::View;
|
use realtor_lp_types::domain::view::View;
|
||||||
use sqlx::PgPool;
|
use sqlx::{PgPool, Transaction, Postgres};
|
||||||
|
|
||||||
pub async fn insert_view(conn: &PgPool, view: View) -> Result<View, sqlx::Error> {
|
pub async fn insert_view<'a>(transaction: &mut Transaction<'a, Postgres>, view: View) -> Result<View, sqlx::Error> {
|
||||||
sqlx::query_file_as!(
|
sqlx::query_file_as!(
|
||||||
View,
|
View,
|
||||||
"sql/view/insert.sql",
|
"sql/view/insert.sql",
|
||||||
@ -11,6 +11,6 @@ pub async fn insert_view(conn: &PgPool, view: View) -> Result<View, sqlx::Error>
|
|||||||
view.trackable_id,
|
view.trackable_id,
|
||||||
view.time_created
|
view.time_created
|
||||||
)
|
)
|
||||||
.fetch_one(conn)
|
.fetch_one(transaction)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -1 +1,12 @@
|
|||||||
|
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
||||||
|
use realtor_lp_types::dto::payloads::view::ViewForCreationPayload;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::{dao, handle_tx, handle_db_write_op, success};
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn new_view(conn: &PgPool, view: ViewForCreationPayload) -> TypedHttpResponse<()> {
|
||||||
|
let mut transaction = handle_tx!(conn.begin());
|
||||||
|
handle_db_write_op!(dao::view::insert_view(&mut transaction, view.into()), transaction);
|
||||||
|
success!(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user