Add ChatInfoService for retrieving player and party names: integrated backend APIs, updated chat service with caching logic for names, and extended OpenAPI documentation.
This commit is contained in:
@@ -2,7 +2,6 @@ package com.alttd.altitudeweb.controllers.chat;
|
||||
|
||||
import com.alttd.altitudeweb.api.ChatApi;
|
||||
import com.alttd.altitudeweb.model.ChatMessageDto;
|
||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||
import com.alttd.altitudeweb.model.ServerStateDto;
|
||||
import com.alttd.altitudeweb.services.chat.ChatService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -12,7 +11,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -33,24 +31,4 @@ public class ChatController implements ChatApi {
|
||||
//TODO [Stijn] [2026-07-18]: Implement handling server state updates (push to listeners)
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PlayerNameDto> getName(UUID uuid) {
|
||||
return chatService.getPlayerName(uuid)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<String> getPartyName(String id) {
|
||||
int partyId;
|
||||
try {
|
||||
partyId = Integer.parseInt(id);
|
||||
} catch (NumberFormatException e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
return chatService.getPartyName(partyId)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alttd.altitudeweb.controllers.chat;
|
||||
|
||||
import com.alttd.altitudeweb.api.ChatInfoApi;
|
||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||
import com.alttd.altitudeweb.services.chat.ChatInfoService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class ChatInfoController implements ChatInfoApi {
|
||||
|
||||
private final ChatInfoService chatInfoService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PlayerNameDto> getName(UUID uuid) {
|
||||
return chatInfoService.getPlayerName(uuid)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<String> getPartyName(String id) {
|
||||
int partyId;
|
||||
try {
|
||||
partyId = Integer.parseInt(id);
|
||||
} catch (NumberFormatException e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
return chatInfoService.getPartyName(partyId)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.alttd.altitudeweb.services.chat;
|
||||
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.chat.NicknameMapper;
|
||||
import com.alttd.altitudeweb.database.chat.PartyMapper;
|
||||
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
|
||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||
import com.alttd.altitudeweb.setup.Connection;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ChatInfoService {
|
||||
|
||||
public Optional<PlayerNameDto> getPlayerName(UUID uuid) {
|
||||
String username = Connection.getConnection(Databases.LUCK_PERMS)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(UUIDUsernameMapper.class).getUsernameFromUUID(uuid.toString()));
|
||||
|
||||
if (username == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<String> nickname = Connection.getConnection(Databases.CHAT)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(NicknameMapper.class).getNicknameFromUUID(uuid.toString()));
|
||||
|
||||
PlayerNameDto playerNameDto = new PlayerNameDto();
|
||||
playerNameDto.setName(username);
|
||||
playerNameDto.setNickname(nickname.orElse(null));
|
||||
|
||||
return Optional.of(playerNameDto);
|
||||
}
|
||||
|
||||
public Optional<String> getPartyName(int id) {
|
||||
return Connection.getConnection(Databases.CHAT)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(PartyMapper.class).getPartyName(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,7 @@ import com.alttd.altitudeweb.controllers.chat.ChatMessage;
|
||||
import com.alttd.altitudeweb.controllers.chat.ChatMessageMapper;
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.chat.ChatLogMapper;
|
||||
import com.alttd.altitudeweb.database.chat.NicknameMapper;
|
||||
import com.alttd.altitudeweb.database.chat.PartyMapper;
|
||||
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
|
||||
import com.alttd.altitudeweb.model.PermissionClaimDto;
|
||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||
import com.alttd.altitudeweb.services.chat.event_publisher.EventPublisher;
|
||||
import com.alttd.altitudeweb.services.chat.event_publisher.EventUser;
|
||||
import com.alttd.altitudeweb.setup.Connection;
|
||||
@@ -145,27 +141,4 @@ public class ChatService {
|
||||
return chatMessages.tailMap(instant, false).values().stream().toList();
|
||||
}
|
||||
|
||||
public Optional<PlayerNameDto> getPlayerName(UUID uuid) {
|
||||
String username = Connection.getConnection(Databases.LUCK_PERMS)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(UUIDUsernameMapper.class).getUsernameFromUUID(uuid.toString()));
|
||||
|
||||
if (username == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<String> nickname = Connection.getConnection(Databases.CHAT)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(NicknameMapper.class).getNicknameFromUUID(uuid.toString()));
|
||||
|
||||
PlayerNameDto playerNameDto = new PlayerNameDto();
|
||||
playerNameDto.setName(username);
|
||||
playerNameDto.setNickname(nickname.orElse(null));
|
||||
|
||||
return Optional.of(playerNameDto);
|
||||
}
|
||||
|
||||
public Optional<String> getPartyName(int id) {
|
||||
return Connection.getConnection(Databases.CHAT)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(PartyMapper.class).getPartyName(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user