- add: ability to refresh the current session

- add: delete type to delete character request
- add: ability to update key in redis
- add: handle alive packet to refresh the session
- fix: delete now actually returns the time remaining correctly
- fix: character list now has the correct time until character deletion
This commit is contained in:
2025-01-08 02:03:27 -05:00
parent 584892ab97
commit 6d35d15ac3
16 changed files with 158 additions and 25 deletions

View File

@@ -1,3 +1,4 @@
use serde_json::Value::Null;
use crate::grpc::{Character, CharacterRequest, CharacterListRequest, CharacterListResponse, CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty};
use crate::grpc::character_service_server::CharacterService;
use crate::grpc::database_service::MyDatabaseService;
@@ -17,6 +18,11 @@ impl CharacterService for MyDatabaseService {
.await
.map_err(|_| Status::not_found("Character not found"))?;
let mut deleted_at= "".to_string();
if character.deleted_at.is_some() {
deleted_at = character.deleted_at.unwrap().to_string();
}
let response = Character {
id: character.id,
user_id: character.user_id,
@@ -27,6 +33,7 @@ impl CharacterService for MyDatabaseService {
position: character.position.to_string(),
created_at: character.created_at.to_string(),
updated_at: character.updated_at.to_string(),
deleted_at,
is_active: character.is_active,
};
@@ -46,8 +53,13 @@ impl CharacterService for MyDatabaseService {
.map_err(|_| Status::not_found("Character not found"))?;
let mut character_list: Vec<Character> = Vec::new();
for character in characters {
let mut deleted_at= "".to_string();
if character.deleted_at.is_some() {
deleted_at = character.deleted_at.unwrap_or_default().to_string();
}
let character = Character {
id: character.id,
user_id: character.user_id,
@@ -58,6 +70,7 @@ impl CharacterService for MyDatabaseService {
position: character.position.to_string(),
created_at: character.created_at.to_string(),
updated_at: character.updated_at.to_string(),
deleted_at,
is_active: character.is_active,
};
character_list.push(character);
@@ -111,12 +124,12 @@ impl CharacterService for MyDatabaseService {
let req = request.into_inner();
let repo = &self.db.character_repo;
repo.delete_character(req.character_id)
let time_left_in_seconds = repo.delete_character(req.character_id, req.delete_type)
.await
.map_err(|_| Status::internal("Failed to delete character"))?;
let response = DeleteCharacterResponse {
remaining_time: 0,
remaining_time: time_left_in_seconds,
name: "".to_string(),
};
Ok(Response::new(response))