Skip to content

Commit

Permalink
refactor: list email api response type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Januar committed Sep 16, 2024
1 parent d4e6da8 commit b5ddd04
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::state::AppState;
use aws_sdk_dynamodb as dynamodb;
use aws_sdk_s3 as s3;
use axum::{
Expand All @@ -9,13 +10,12 @@ use dynamodb::types::AttributeValue;
use mail_parser::Message;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use crate::state::AppState;
// use leptos::*;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Test {
mail_db: String,
id: String
id: String,
}

// #[server(GetEmailHtml, "/api_fn", "GetJson", "email")]
Expand All @@ -42,7 +42,10 @@ pub async fn get_email_html(
State(state): State<AppState>,
) -> Html<String> {
let client = s3::Client::new(&state.aws_config);
let call = client.get_object().bucket(&state.mail_config.mail_bucket).key(key_id);
let call = client
.get_object()
.bucket(&state.mail_config.mail_bucket)
.key(key_id);

let response = call.clone().send().await.unwrap();
let data = response.body.collect().await.expect("error reading data");
Expand All @@ -62,7 +65,12 @@ pub struct Mail {
from: Vec<String>,
}

pub async fn list_email(State(state): State<AppState>) -> Json<Value> {
#[derive(Debug, Serialize, Deserialize)]
pub struct ListEmailResponse {
data: Vec<Mail>,
}

pub async fn list_email(State(state): State<AppState>) -> Json<ListEmailResponse> {
// let client = s3::Client::new(&state.aws_config);
// let call = client.list_objects_v2().bucket(&state.mail_bucket);
//
Expand Down Expand Up @@ -111,5 +119,6 @@ pub async fn list_email(State(state): State<AppState>) -> Json<Value> {
.collect::<Vec<String>>(),
})
.collect();
Json(json!({ "data": mails }))
let response = ListEmailResponse { data: mails };
Json(response)
}

0 comments on commit b5ddd04

Please sign in to comment.