DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

649b9135c6bcd91598c7935349a7c4effcf8be15 — Jonni Liljamo 1 year, 9 months ago a69dd4f
fix(api, server, shared): dont do drugs and api
M api/src/handlers/user/info.rs => api/src/handlers/user/info.rs +8 -4
@@ 12,19 12,23 @@ use laurelin_shared::error::api::APIError;

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

#[get("/api/user")]
pub(crate) async fn info(pool: web::Data<PgPool>, session: Session) -> impl Responder {
#[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) => {
        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, &user_id)
                actions::user::info(&mut conn, &id)
            })
            .await;
            match user_details {

M server/src/systems/event/message/mod.rs => server/src/systems/event/message/mod.rs +5 -2
@@ 119,8 119,11 @@ pub(crate) fn message_events(
                DataRequestType::PubUserDetails => {
                    // TODO: handle
                    let cookie = global.user_to_session_map.get(&user_key).unwrap();
                    let wrapped =
                        user::info(&config.api_address, &request.data.unwrap_or("".to_string()));
                    let wrapped = user::info(
                        &config.api_address,
                        &request.data.unwrap_or("".to_string()),
                        cookie,
                    );
                    let user_details = match wrapped.response {
                        ResponseInfo::Error(_err) => {
                            panic!("I can't be bothered to handle this right now.")

M shared/src/api/user/mod.rs => shared/src/api/user/mod.rs +7 -3
@@ 6,7 6,7 @@
 * See LICENSE for licensing information.
 */

use reqwest;
use reqwest::{self, header::COOKIE};
use serde::{Deserialize, Serialize};

use crate::{error::api::APIError, types::user::UserPub};


@@ 26,10 26,14 @@ pub struct ResponseInfoWrapper {
    pub cookie: String,
}

pub fn info(api_address: &str, user_id: &str) -> ResponseInfoWrapper {
pub fn info(api_address: &str, user_id: &str, cookie: &str) -> ResponseInfoWrapper {
    let client = reqwest::blocking::Client::new();

    let resp = client.get(&format!("{}/user", api_address)).send().unwrap();
    let resp = client
        .get(&format!("{}/user/{}", api_address, user_id))
        .header(COOKIE, &format!("id={}", cookie))
        .send()
        .unwrap();

    ResponseInfoWrapper {
        cookie: extract_cookie!(resp),