Add Extra Logs For Status

Make Number Game Easier
Remove Endpoint `users-online`
This commit is contained in:
Alan Moon 2025-06-30 20:50:49 -07:00
parent abaa850016
commit 8dcd38cc83
3 changed files with 8 additions and 22 deletions

View File

@ -57,14 +57,6 @@ namespace qtc_api.Controllers
} }
} }
[HttpGet("users-online")]
[Authorize]
public async Task<ActionResult<ServiceResponse<List<UserInformationDto>>>> GetAllOnlineUsers()
{
var users = await _userService.GetAllOnlineUsers();
return Ok(users);
}
[HttpPut("update")] [HttpPut("update")]
[Authorize] [Authorize]
public async Task<ActionResult<ServiceResponse<UserInformationDto>>> UpdateUserInformation(UserUpdateInformationDto user) public async Task<ActionResult<ServiceResponse<UserInformationDto>>> UpdateUserInformation(UserUpdateInformationDto user)
@ -80,10 +72,6 @@ namespace qtc_api.Controllers
{ {
var updatedUser = await _userService.UpdateUserInfo(user); var updatedUser = await _userService.UpdateUserInfo(user);
// always try to overwrite cache when updating user info
string recordId = $"User_{user.Id}_{DateTime.Now.ToString("yyyyMMdd_hhmm")}";
await cache.SetRecordAsync(recordId, updatedUser);
return Ok(updatedUser); return Ok(updatedUser);
} else } else
{ {

View File

@ -7,8 +7,8 @@ namespace qtc_api.Hubs
{ {
private IUserService _userService; private IUserService _userService;
private ILogger<ChatHub> _logger; private ILogger<ChatHub> _logger;
private static List<UserConnectionDto> ConnectedUsers = new List<UserConnectionDto>(); private static List<UserConnectionDto> ConnectedUsers = new();
private static List<User> OnlineUsers = new List<User>(); private static List<User> OnlineUsers = new();
private static Dictionary<string, List<User>> GroupUsers = new(); private static Dictionary<string, List<User>> GroupUsers = new();
@ -32,7 +32,7 @@ namespace qtc_api.Hubs
{ {
ConnectedUsers.Remove(connection); ConnectedUsers.Remove(connection);
OnlineUsers.Remove(user); OnlineUsers.Remove(user);
await LogoutAsync(user!); await LogoutAsync(user);
} }
} }
@ -64,6 +64,8 @@ namespace qtc_api.Hubs
{ {
var statusDto = new UserStatusDto { Id = user.Id, Status = status }; var statusDto = new UserStatusDto { Id = user.Id, Status = status };
Log($"Updating Status\n{JsonSerializer.Serialize(statusDto)}");
await _userService.UpdateStatus(statusDto); await _userService.UpdateStatus(statusDto);
await Clients.All.SendAsync("RefreshUserLists"); await Clients.All.SendAsync("RefreshUserLists");
@ -167,9 +169,7 @@ namespace qtc_api.Hubs
private async Task LoginAsync(User user) private async Task LoginAsync(User user)
{ {
var statusDto = new UserStatusDto { Id = user.Id, Status = 1 }; await UpdateStatusAsync(user, 1);
await _userService.UpdateStatus(statusDto);
ServerConfig serverConfig = JsonDocument.Parse(File.ReadAllText("./ServerConfig.json")).Deserialize<ServerConfig>(); ServerConfig serverConfig = JsonDocument.Parse(File.ReadAllText("./ServerConfig.json")).Deserialize<ServerConfig>();
@ -181,9 +181,7 @@ namespace qtc_api.Hubs
private async Task LogoutAsync(User user) private async Task LogoutAsync(User user)
{ {
var statusDto = new UserStatusDto { Id = user.Id, Status = 0 }; await UpdateStatusAsync(user, 0);
await _userService.UpdateStatus(statusDto);
await Clients.All.SendAsync("RefreshUserLists"); await Clients.All.SendAsync("RefreshUserLists");
Log($"User {user.Username} Has Logged Out"); Log($"User {user.Username} Has Logged Out");

View File

@ -91,7 +91,7 @@ namespace qtc_api.Services.CurrencyGamesService
public ServiceResponse<int> GetRandomNumber() public ServiceResponse<int> GetRandomNumber()
{ {
Random rnd = new Random(); Random rnd = new Random();
return new ServiceResponse<int> { Success = true, Data = rnd.Next(1, 500) }; return new ServiceResponse<int> { Success = true, Data = rnd.Next(1, 100) };
} }
public ServiceResponse<NumberGuessResult> GuessRandomNumber(int original, int guess) public ServiceResponse<NumberGuessResult> GuessRandomNumber(int original, int guess)