diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-16 13:00:38 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-16 13:00:38 +0100 |
commit | 9e9d01c1332db5130a271db9882cb37418dc3f9b (patch) | |
tree | 94ea8bf29cb826d6335e6a3bb082c03fa6c9e48f /src/email/routes.rs | |
parent | b950072a3109d2c13881611a3950baa191caf097 (diff) |
feat: get all emails
Diffstat (limited to 'src/email/routes.rs')
-rw-r--r-- | src/email/routes.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/email/routes.rs b/src/email/routes.rs new file mode 100644 index 0000000..06b74fb --- /dev/null +++ b/src/email/routes.rs @@ -0,0 +1,26 @@ +use crate::config::AppState; +use crate::email::models::Email; +use crate::errors::AppErrorResponse; +use actix_web::{web, HttpResponse, Responder}; +use slog::info; + +/// Endpoint used for retrieve all emails +async fn index(state: web::Data<AppState>) -> impl Responder { + let result = Email::find_all(state.pool.clone()).await; + info!(state.log, "GET /email/"); + + match result { + Ok(emails) => HttpResponse::Ok().json(emails), + _ => HttpResponse::BadRequest().json(AppErrorResponse { + detail: "Error trying to read all emails from database" + .to_string(), + }), + } +} + +pub fn config(cfg: &mut web::ServiceConfig) { + cfg.service( + web::scope("/email") + .service(web::resource("{_:/?}").route(web::get().to(index))), + ); +} |