- add: Character service can now actually create a character correctly in the database
- add: character db client to allow the character service to talk to the database service - update: character.proto to make character data shared
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
use std::sync::Arc;
|
||||
use tracing::debug;
|
||||
use tonic::{Request, Response, Status};
|
||||
use tracing::field::debug;
|
||||
use utils::null_string::NullTerminatedString;
|
||||
use crate::character_db_client::CharacterDbClient;
|
||||
use crate::character_service::character::character_service_server::CharacterService;
|
||||
use crate::character_service::character::{Character, CreateCharacterRequest, DeleteCharacterRequest, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest};
|
||||
use crate::character_service::character::{CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest};
|
||||
use crate::character_service::character_common::{Character, Looks, Stats};
|
||||
|
||||
pub mod character_common {
|
||||
tonic::include_proto!("character_common");
|
||||
}
|
||||
pub mod character {
|
||||
|
||||
tonic::include_proto!("character");
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MyCharacterService {}
|
||||
pub struct MyCharacterService {
|
||||
pub character_db_client: Arc<CharacterDbClient>,
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl CharacterService for MyCharacterService {
|
||||
@@ -19,30 +27,41 @@ impl CharacterService for MyCharacterService {
|
||||
let user_id = req.user_id;
|
||||
debug!("Character list for User ID: {}", user_id);
|
||||
|
||||
// todo: get the data from the database
|
||||
// self.character_db_client.as_ref();
|
||||
|
||||
// Simulated database fetch for characters
|
||||
let characters = vec![
|
||||
Character {
|
||||
character_id: "1".to_string(),
|
||||
name: "Warrior123".to_string(),
|
||||
level: 1,
|
||||
race: 1,
|
||||
job: 111,
|
||||
last_played: 1633017600, // Example timestamp
|
||||
last_played: 1633017600,
|
||||
delete_time: 0,
|
||||
face: 1,
|
||||
hair: 0,
|
||||
stats: Option::from(Stats {
|
||||
job: 0,
|
||||
level: 0,
|
||||
}),
|
||||
looks: Option::from(Looks {
|
||||
race: 0,
|
||||
hair: 0,
|
||||
face: 0,
|
||||
}),
|
||||
items: vec![],
|
||||
},
|
||||
Character {
|
||||
character_id: "2".to_string(),
|
||||
name: "Mage123".to_string(),
|
||||
level: 20,
|
||||
race: 0,
|
||||
job: 211,
|
||||
last_played: 1633017600, // Example timestamp
|
||||
last_played: 1633017600,
|
||||
delete_time: 0,
|
||||
face: 1,
|
||||
hair: 0,
|
||||
stats: Option::from(Stats {
|
||||
job: 211,
|
||||
level: 20,
|
||||
}),
|
||||
looks: Option::from(Looks {
|
||||
race: 1,
|
||||
hair: 0,
|
||||
face: 1,
|
||||
}),
|
||||
items: vec![],
|
||||
},
|
||||
];
|
||||
@@ -51,15 +70,30 @@ impl CharacterService for MyCharacterService {
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
async fn create_character(&self, request: Request<CreateCharacterRequest>) -> Result<Response<Empty>, Status> {
|
||||
todo!()
|
||||
async fn create_character(&self, request: Request<CreateCharacterRequest>) -> Result<Response<CreateCharacterResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
debug!("{:?}", req);
|
||||
|
||||
let create_character_response = self.character_db_client.as_ref().clone().create_character(&req.user_id, &req.name, req.race, req.face, req.hair, req.stone)
|
||||
.await
|
||||
.map_err(|_| Status::aborted("Unable to create character"))?;
|
||||
|
||||
let response = CreateCharacterResponse { result: create_character_response.result };
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
async fn delete_character(&self, request: Request<DeleteCharacterRequest>) -> Result<Response<Empty>, Status> {
|
||||
todo!()
|
||||
async fn delete_character(&self, request: Request<DeleteCharacterRequest>) -> Result<Response<DeleteCharacterResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
debug!("{:?}", req);
|
||||
|
||||
let delete_character_response = self.character_db_client.as_ref().clone().delete_character(&req.user_id, &req.char_id).await.map_err(|_| Status::not_found("Character not found"))?;
|
||||
let response = DeleteCharacterResponse { remaining_time: delete_character_response.remaining_time, name: delete_character_response.name };
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
async fn get_character(&self, request: Request<GetCharacterRequest>) -> Result<Response<Empty>, Status> {
|
||||
todo!()
|
||||
let req = request.into_inner();
|
||||
debug!("{:?}", req);
|
||||
Ok(Response::new(Empty{}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user