blob: 06b74fbeaebde10a780b74f0659eaae21b22e7bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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))),
);
}
|