summaryrefslogtreecommitdiffstats
path: root/crates/profile-service/src/server/manager.rs
blob: bd7e149221501e44a3a97a6624aa534dfcfb58e5 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use prost::Message;
use sellershut_core::profile::{
    CompleteUserRequest, CreateUserRequest, CreateUserResponse, User, profile_server::Profile,
};
use stack_up::redis::AsyncCommands;
use tonic::{Request, Response, Status, async_trait};
use tracing::trace;
use uuid::Uuid;

use crate::state::AppHandle;

#[async_trait]
impl Profile for AppHandle {
    #[doc = " Create a new user profile"]
    async fn create_user(
        &self,
        request: Request<CreateUserRequest>,
    ) -> Result<Response<CreateUserResponse>, Status> {
        trace!("creating user");
        let data = request.into_inner();
        let id = Uuid::now_v7().to_string();

        let bytes = data.encode_to_vec();
        let mut cache = self
            .services
            .cache
            .get()
            .await
            .map_err(|e| Status::internal("storage not ready"))?;
        cache
            .set_ex::<_, _, ()>(&id, &bytes, self.local_config.temp_ttl)
            .await
            .map_err(|e| Status::internal("storage not ready"))?;

        Ok(Response::new(CreateUserResponse { temp_id: id }))
    }

    #[doc = " Complete Profile"]
    async fn complete_profile(
        &self,
        request: Request<CompleteUserRequest>,
    ) -> Result<Response<User>, Status> {
        todo!()
    }
}