Skip to main content

handle_get_messages

Function handle_get_messages 

Source
pub(crate) async fn handle_get_messages(
    db: &DatabaseConnection,
    email: &str,
    cognito_id: Uuid,
    cors_origin: &str,
) -> Result<Response, Error>
Expand description

認証済みユーザーのお問い合わせ一覧を取得する

JWTクレームから取得した emailcognito_sub でデータベースをフィルタリングし、 当該ユーザーが送信したお問い合わせを作成日時の降順(新しい順)で返します。

§データベースクエリ

SELECT cognito_id, is_from_user, body, created_at
FROM messages
WHERE cognito_id = $1
ORDER BY created_at DESC

§Arguments

  • db - SeaORM データベース接続。Aurora DSQL への接続が確立済みである必要があります。
  • email - JWTクレームから取得した認証済みユーザーのメールアドレス。
  • cognito_id - JWTクレームの sub フィールドから取得した Cognito ユーザーの UUID。
  • cors_origin - レスポンスの Access-Control-Allow-Origin ヘッダーに設定するオリジン。

§Returns

  • Ok(Response) - HTTP 200 と MessageListResponse のJSON(email, count, messages フィールドを含む)
  • Err(Error) - データベースクエリエラーまたはJSONシリアライズエラー

§Errors

  • データベースクエリ失敗時: "Database query failed: ..." をログに記録し Err を返します。
  • JSONシリアライズ失敗時: serde_json::to_value のエラーを ? で伝播します。