mirror of
https://github.com/oxen-io/session-open-group-server.git
synced 2023-12-13 20:30:35 +01:00
Clean
This commit is contained in:
parent
b858892049
commit
fc04766f0a
|
@ -13,10 +13,10 @@ pub async fn insert_message(mut message: models::Message, pool: storage::Databas
|
|||
let tx = storage::tx(&mut conn)?;
|
||||
// Insert the message
|
||||
storage::exec("INSERT INTO messages (text) VALUES (?1)", params![message.text], &tx)?;
|
||||
let id = tx.last_insert_rowid(); // TODO: Is there a risk of the `execute()` above and this call not being sync?
|
||||
let id = tx.last_insert_rowid();
|
||||
message.server_id = Some(id);
|
||||
// Commit
|
||||
tx.commit(); // TODO: Unwrap?
|
||||
tx.commit(); // TODO: Unwrap
|
||||
// Return
|
||||
return Ok(warp::reply::json(&message));
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ pub async fn delete_message(row_id: i64, pool: storage::DatabaseConnectionPool)
|
|||
storage::exec("INSERT INTO deletions (id) VALUES (?1)", params![row_id], &tx)?;
|
||||
}
|
||||
// Commit
|
||||
tx.commit(); // TODO: Unwrap?
|
||||
tx.commit(); // TODO: Unwrap
|
||||
// Return
|
||||
return Ok(StatusCode::OK);
|
||||
}
|
|
@ -4,14 +4,6 @@ use super::handlers;
|
|||
use super::models;
|
||||
use super::storage;
|
||||
|
||||
pub fn get_all(
|
||||
db_pool: &storage::DatabaseConnectionPool
|
||||
) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
|
||||
return send_message(db_pool.clone())
|
||||
.or(get_messages(db_pool.clone()))
|
||||
.or(delete_message(db_pool.clone()));
|
||||
}
|
||||
|
||||
/// POST /messages
|
||||
pub fn send_message(
|
||||
db_pool: storage::DatabaseConnectionPool
|
||||
|
@ -50,6 +42,16 @@ pub fn delete_message(
|
|||
.recover(handle_error);
|
||||
}
|
||||
|
||||
// Utilities
|
||||
|
||||
pub fn get_all(
|
||||
db_pool: &storage::DatabaseConnectionPool
|
||||
) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
|
||||
return send_message(db_pool.clone())
|
||||
.or(get_messages(db_pool.clone()))
|
||||
.or(delete_message(db_pool.clone()));
|
||||
}
|
||||
|
||||
async fn handle_error(e: Rejection) -> Result<impl warp::Reply, Rejection> {
|
||||
let reply = warp::reply::reply();
|
||||
if let Some(models::ValidationError) = e.find() {
|
||||
|
|
|
@ -39,7 +39,7 @@ pub fn conn(pool: &DatabaseConnectionPool) -> Result<DatabaseConnection, Rejecti
|
|||
match pool.get() {
|
||||
Ok(conn) => return Ok(conn),
|
||||
Err(e) => {
|
||||
println!("Couldn't get database connection from pool due to error: {:?}.", e);
|
||||
println!("Couldn't get database connection due to error: {:?}.", e);
|
||||
return Err(warp::reject::custom(DatabaseError));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue