Documentation: - Add detailed README files for all services (auth, character, database, launcher, packet, utils, world) - Create API documentation for the database service with detailed endpoint specifications - Document database schema and relationships - Add service architecture overviews and configuration instructions Unit Tests: - Implement comprehensive test suite for database repositories (user, character, session) - Add gRPC service tests for database interactions - Create tests for packet service components (bufferpool, connection, packets) - Add utility service tests (health check, logging, load balancer, redis cache, service discovery) - Implement auth service user tests - Add character service tests Code Structure: - Reorganize test files into a more consistent structure - Create a dedicated tests crate for integration testing - Add test helpers and mock implementations for easier testing
41 lines
1.5 KiB
Rust
41 lines
1.5 KiB
Rust
use crate::session::{
|
|
session_service_client::SessionServiceClient, GetSessionRequest, GetSessionResponse, RefreshSessionRequest,
|
|
RefreshSessionResponse,
|
|
};
|
|
use async_trait::async_trait;
|
|
use std::error::Error;
|
|
use tonic::transport::Channel;
|
|
|
|
#[async_trait]
|
|
pub trait SessionClientTrait: Sized {
|
|
async fn connect(endpoint: &str) -> Result<Self, Box<dyn std::error::Error>>;
|
|
async fn get_session(&mut self, session_id: String) -> Result<GetSessionResponse, Box<dyn std::error::Error>>;
|
|
async fn refresh_session(
|
|
&mut self,
|
|
session_id: String,
|
|
) -> Result<RefreshSessionResponse, Box<dyn std::error::Error>>;
|
|
}
|
|
#[derive(Clone)]
|
|
pub struct SessionClient {
|
|
client: SessionServiceClient<Channel>,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl SessionClientTrait for SessionClient {
|
|
async fn connect(endpoint: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
|
let client = SessionServiceClient::connect(endpoint.to_string()).await?;
|
|
Ok(Self { client })
|
|
}
|
|
|
|
async fn get_session(&mut self, session_id: String) -> Result<GetSessionResponse, Box<dyn Error>> {
|
|
let request = tonic::Request::new(GetSessionRequest { session_id });
|
|
let response = self.client.get_session(request).await?;
|
|
Ok(response.into_inner())
|
|
}
|
|
async fn refresh_session(&mut self, session_id: String) -> Result<RefreshSessionResponse, Box<dyn Error>> {
|
|
let request = tonic::Request::new(RefreshSessionRequest { session_id });
|
|
let response = self.client.refresh_session(request).await?;
|
|
Ok(response.into_inner())
|
|
}
|
|
}
|