DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 8db41b3a1e2ad2024db3d194fa35b4c231b2f3b5 deck-builder/api/src/handlers/user/info.rs -rw-r--r-- 1.4 KiB
8db41b3aJonni Liljamo feat(client): revamp user details event, send it when needed 1 year, 9 months ago
                                                                                
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * This file is part of laurelin/api
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use actix_session::Session;
use actix_web::{get, web, HttpResponse, Responder};
use laurelin_shared::error::api::APIError;

use crate::{actions, session, PgPool};

#[get("/api/user/{id}")]
pub(crate) async fn info(
    pool: web::Data<PgPool>,
    session: Session,
    id: web::Path<String>,
) -> impl Responder {
    let session_validation = session::validate_session(&session);

    match session_validation {
        Err(err) => err,
        Ok(_user_id) => {
            let user_details = web::block(move || {
                let mut conn = match pool.get() {
                    Err(_) => return Err(APIError::DatabasePoolGetFailed),
                    Ok(conn) => conn,
                };
                actions::user::info(&mut conn, &id)
            })
            .await;
            match user_details {
                Err(_err) => {
                    return HttpResponse::InternalServerError().json(APIError::Undefined);
                }
                Ok(user_details_res) => match user_details_res {
                    Err(err) => HttpResponse::InternalServerError().body(err.to_string()),
                    Ok(user_details) => HttpResponse::Ok().json(user_details),
                },
            }
        }
    }
}