Skip to content

Commit b528e76

Browse files
committed
Fixed the names of the classes and their annotations to match their purpose (controller vs service)
1 parent dce7621 commit b528e76

23 files changed

+336
-345
lines changed

game_server/src/main/kotlin/com/imsproject/gameserver/api/RestHandler.kt renamed to game_server/src/main/kotlin/com/imsproject/gameserver/api/RestApiController.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import com.imsproject.gameserver.dataAccess.DAOController
88
import com.imsproject.gameserver.toResponseEntity
99
import com.imsproject.common.utils.fromJson
1010
import com.imsproject.gameserver.business.GameRequestFacade
11-
import com.imsproject.gameserver.business.ParticipantController
12-
import com.imsproject.gameserver.business.auth.AuthController
11+
import com.imsproject.gameserver.business.ParticipantService
12+
import com.imsproject.gameserver.business.auth.AuthService
1313
import com.imsproject.gameserver.business.auth.Credentials
1414
import com.imsproject.gameserver.dataAccess.implementations.ParticipantsDAO
1515
import com.imsproject.gameserver.dataAccess.models.*
@@ -29,10 +29,10 @@ import java.util.concurrent.Executors
2929

3030
@EnableMethodSecurity
3131
@RestController
32-
class RestHandler(
32+
class RestApiController(
3333
private val gameRequestFacade: GameRequestFacade,
34-
private val authController: AuthController,
35-
private val participantController: ParticipantController,
34+
private val authService: AuthService,
35+
private val participantService: ParticipantService,
3636
private val daoController: DAOController,
3737
private val resources: ResourceLoader,
3838
private val participantsDAO: ParticipantsDAO
@@ -50,7 +50,7 @@ class RestHandler(
5050
val credentials = header.removePrefix("Basic ")
5151
val decoded = String(Base64.getDecoder().decode(credentials))
5252
val (userId, password) = decoded.split(":")
53-
return authController.authenticateUser(userId, password).toResponseEntity()
53+
return authService.authenticateUser(userId, password).toResponseEntity()
5454
}
5555

5656
@PostMapping("/manager")
@@ -73,10 +73,10 @@ class RestHandler(
7373
withErrorHandling("Error handling operator request") {
7474
try {
7575
when (action) {
76-
"add" -> authController.createUser(credentials)
77-
"remove" -> authController.deleteUser(credentials.userId)
76+
"add" -> authService.createUser(credentials)
77+
"remove" -> authService.deleteUser(credentials.userId)
7878
"get" -> {
79-
val users = authController.getAllUsers()
79+
val users = authService.getAllUsers()
8080
return Response.getOk(users).toResponseEntity()
8181
}
8282

@@ -99,19 +99,19 @@ class RestHandler(
9999
when(action){
100100
"add" -> {
101101
log.debug("Adding participant: {}", participant)
102-
val id = participantController.addParticipant(participant)
102+
val id = participantService.addParticipant(participant)
103103
log.debug("Successfully Added participant with id: {}", id)
104104
Response.getOk(id).toResponseEntity()
105105
}
106106
"remove" ->{
107107
log.debug("Removing participant: {}", participant)
108108
val pid = participant.pid ?: throw IllegalArgumentException("Participant id not provided")
109-
participantController.remove(pid)
109+
participantService.remove(pid)
110110
log.debug("Successfully removed participant with id: {}", pid)
111111
Response.getOk().toResponseEntity()
112112
}
113113
"get" -> {
114-
val participants = participantController.getAll()
114+
val participants = participantService.getAll()
115115
Response.getOk(participants).toResponseEntity()
116116
}
117117
else -> Response.getError("Invalid action").toResponseEntity(HttpStatus.BAD_REQUEST)
@@ -275,7 +275,7 @@ class RestHandler(
275275

276276
@PostMapping("/bcrypt/encrypt")
277277
fun bcryptSend(@RequestBody password : String): ResponseEntity<String> {
278-
return authController.textToBCrypt(password).toResponseEntity()
278+
return authService.textToBCrypt(password).toResponseEntity()
279279
}
280280

281281
@GetMapping("/error")
@@ -320,6 +320,6 @@ class RestHandler(
320320
}
321321

322322
companion object {
323-
private val log = LoggerFactory.getLogger(RestHandler::class.java)
323+
private val log = LoggerFactory.getLogger(RestController::class.java)
324324
}
325325
}

game_server/src/main/kotlin/com/imsproject/gameserver/api/UdpGameActionHandler.kt renamed to game_server/src/main/kotlin/com/imsproject/gameserver/api/UdpGameActionController.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import com.imsproject.common.gameserver.GameAction
44
import com.imsproject.common.gameserver.GameAction.Type
55
import com.imsproject.common.networking.UdpClient
66
import com.imsproject.gameserver.*
7-
import com.imsproject.gameserver.business.ClientController
7+
import com.imsproject.gameserver.business.ClientService
88
import com.imsproject.gameserver.business.ClientHandler
9-
import com.imsproject.gameserver.business.GameController
9+
import com.imsproject.gameserver.business.GameService
1010
import org.slf4j.LoggerFactory
1111
import org.springframework.beans.factory.annotation.Value
1212
import org.springframework.boot.context.event.ApplicationReadyEvent
1313
import org.springframework.context.event.EventListener
14-
import org.springframework.stereotype.Component
14+
import org.springframework.stereotype.Service
1515
import java.net.SocketAddress
1616
import java.util.concurrent.ConcurrentHashMap
1717

1818

19-
@Component
20-
class UdpGameActionHandler(
21-
private val gameController: GameController,
22-
private val clients: ClientController
19+
@Service
20+
class UdpGameActionController(
21+
private val gameService: GameService,
22+
private val clients: ClientService
2323
) {
2424

2525
@Value("\${udp.local_port}")
@@ -66,7 +66,7 @@ class UdpGameActionHandler(
6666
return
6767
}
6868
try{
69-
gameController.handleGameAction(client, action)
69+
gameService.handleGameAction(client, action)
7070
} catch(e: Exception){
7171
log.error("Error handling game action", e)
7272
}
@@ -119,7 +119,7 @@ class UdpGameActionHandler(
119119
}
120120

121121
companion object {
122-
private val log = LoggerFactory.getLogger(UdpGameActionHandler::class.java)
122+
private val log = LoggerFactory.getLogger(UdpGameActionController::class.java)
123123
}
124124

125125
}

game_server/src/main/kotlin/com/imsproject/gameserver/api/WebSocketConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
88
@Configuration
99
@EnableWebSocket
1010
class WebSocketConfig(
11-
private val wsGameRequestHandler: WsGameRequestHandler
11+
private val wsGameRequestController: WsGameRequestController
1212
) : WebSocketConfigurer {
1313

1414
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) {
15-
registry.addHandler(wsGameRequestHandler, "/ws").setAllowedOrigins("*")
15+
registry.addHandler(wsGameRequestController, "/ws").setAllowedOrigins("*")
1616
}
1717
}
1818

game_server/src/main/kotlin/com/imsproject/gameserver/api/WsGameRequestHandler.kt renamed to game_server/src/main/kotlin/com/imsproject/gameserver/api/WsGameRequestController.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ import com.imsproject.common.utils.SimpleIdGenerator
66
import com.imsproject.common.utils.fromJson
77
import com.imsproject.common.utils.toJson
88
import com.imsproject.gameserver.*
9-
import com.imsproject.gameserver.business.ClientController
9+
import com.imsproject.gameserver.business.ClientService
1010
import com.imsproject.gameserver.business.ClientHandler
1111
import com.imsproject.gameserver.business.GameRequestFacade
12-
import com.imsproject.gameserver.business.LobbyController
12+
import com.imsproject.gameserver.business.LobbyService
1313
import com.imsproject.gameserver.dataAccess.DAOController
1414
import com.imsproject.gameserver.dataAccess.implementations.ParticipantPK
1515
import org.slf4j.Logger
1616
import org.slf4j.LoggerFactory
1717
import org.springframework.lang.NonNull
18-
import org.springframework.stereotype.Component
18+
import org.springframework.stereotype.Service
1919
import org.springframework.web.socket.CloseStatus
2020
import org.springframework.web.socket.TextMessage
2121
import org.springframework.web.socket.WebSocketSession
2222
import org.springframework.web.socket.handler.TextWebSocketHandler
2323
import java.time.LocalDateTime
2424
import java.util.*
2525

26-
@Component
27-
class WsGameRequestHandler(
26+
@Service
27+
class WsGameRequestController(
2828
private val facade: GameRequestFacade,
29-
private val gameActionHandler: UdpGameActionHandler,
30-
private val clientController: ClientController,
31-
private val lobbyController: LobbyController,
29+
private val gameActionHandler: UdpGameActionController,
30+
private val clientService: ClientService,
31+
private val lobbyService: LobbyService,
3232
private val daoController: DAOController
3333
) : TextWebSocketHandler() {
3434

3535
companion object {
36-
private val log: Logger = LoggerFactory.getLogger(WsGameRequestHandler::class.java)
36+
private val log: Logger = LoggerFactory.getLogger(WsGameRequestController::class.java)
3737
}
3838

3939
private val idGenerator: SimpleIdGenerator = SimpleIdGenerator(3)
@@ -61,13 +61,13 @@ class WsGameRequestHandler(
6161
Type.PING -> session.send(GameRequest.pong)
6262
Type.PONG -> {}
6363
Type.EXIT -> {
64-
clientController.getByWsSessionId(session.id)?.let {
65-
clientController.onExit(it.id)
64+
clientService.getByWsSessionId(session.id)?.let {
65+
clientService.onExit(it.id)
6666
log.debug("Client exited: {}", it.id)
6767
}
6868
}
6969
Type.HEARTBEAT -> {
70-
clientController.getByWsSessionId(session.id)?.let {
70+
clientService.getByWsSessionId(session.id)?.let {
7171
it.lastHeartbeat = LocalDateTime.now()
7272
}
7373
session.send(GameRequest.heartbeat)
@@ -83,14 +83,14 @@ class WsGameRequestHandler(
8383
}
8484

8585
// Check that a client exists
86-
val client = clientController.getByClientId(id) ?: run {
86+
val client = clientService.getByClientId(id) ?: run {
8787
log.error("Client not found for id: {}", id)
8888
return
8989
}
9090
// map the client to the new wsSession
91-
clientController.removeClientHandler(client.id) // clear old mappings
91+
clientService.removeClientHandler(client.id) // clear old mappings
9292
client.wsSession = session
93-
clientController.addClientHandler(client)
93+
clientService.addClientHandler(client)
9494
client.lastHeartbeat = LocalDateTime.now()
9595

9696
log.debug("Reconnected client: {}", client.id)
@@ -111,7 +111,7 @@ class WsGameRequestHandler(
111111

112112
else -> {
113113
// get the client handler for the session if it exists
114-
val client = clientController.getByWsSessionId(session.id) ?: run {
114+
val client = clientService.getByWsSessionId(session.id) ?: run {
115115
log.error("Client not found for session: {}", session.id)
116116
session.send(GameRequest.builder(Type.ERROR)
117117
.message("Client not found, please reconnect")
@@ -164,7 +164,7 @@ class WsGameRequestHandler(
164164

165165
// Check if the id is already connected from elsewhere
166166
// and if so, disconnect the old connection
167-
var clientHandler = clientController.getByClientId(id)
167+
var clientHandler = clientService.getByClientId(id)
168168
if (clientHandler != null) {
169169
if(clientHandler.isConnected){
170170
log.debug("Client with id {} already connected", id)
@@ -186,13 +186,13 @@ class WsGameRequestHandler(
186186
}
187187

188188
// map the client to the new wsSession
189-
clientController.removeClientHandler(clientHandler.id) // clear old mappings
189+
clientService.removeClientHandler(clientHandler.id) // clear old mappings
190190
clientHandler.wsSession = session
191-
clientController.addClientHandler(clientHandler)
191+
clientService.addClientHandler(clientHandler)
192192
} else {
193193
// client is new, create a new client handler
194194
clientHandler = newClientHandler(session, id)
195-
clientController.addClientHandler(clientHandler)
195+
clientService.addClientHandler(clientHandler)
196196
}
197197

198198
clientHandler.isConnected = true
@@ -209,13 +209,13 @@ class WsGameRequestHandler(
209209
.toJson()
210210
.also { session.send(it) }
211211

212-
if (lobbyController.isClientInALobby(id)) {
213-
lobbyController.onClientConnect(clientHandler)
212+
if (lobbyService.isClientInALobby(id)) {
213+
lobbyService.onClientConnect(clientHandler)
214214
}
215215
}
216216

217217
override fun afterConnectionClosed(session: WebSocketSession, @NonNull status: CloseStatus) {
218-
val client = clientController.getByWsSessionId(session.id) ?: return
218+
val client = clientService.getByWsSessionId(session.id) ?: return
219219
client.isConnected = false
220220
log.debug("afterConnectionClosed: client {} websocket session disconnected", client.id)
221221
}

game_server/src/main/kotlin/com/imsproject/gameserver/business/ClientController.kt renamed to game_server/src/main/kotlin/com/imsproject/gameserver/business/ClientService.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import org.slf4j.LoggerFactory
66
import org.springframework.boot.context.event.ApplicationReadyEvent
77
import org.springframework.context.event.EventListener
88
import org.springframework.stereotype.Component
9+
import org.springframework.stereotype.Service
910
import java.util.concurrent.ConcurrentHashMap
1011

11-
@Component
12-
class ClientController {
12+
@Service
13+
class ClientService {
1314

1415
companion object{
1516
const val HEARTBEAT_TIMEOUT_THRESHOLD = 60L
16-
private val log = LoggerFactory.getLogger(ClientController::class.java)
17+
private val log = LoggerFactory.getLogger(ClientService::class.java)
1718
}
1819

1920
var onClientDisconnect: ((ClientHandler) -> Unit) = {}

game_server/src/main/kotlin/com/imsproject/gameserver/business/ExperimentOrchestrator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import com.imsproject.gameserver.dataAccess.DAOController import com.imsproject.
55
import com.imsproject.gameserver.dataAccess.models.SessionDTO
66
import kotlinx.coroutines.*
77
import org.slf4j.LoggerFactory
8-
import org.springframework.stereotype.Component
8+
import org.springframework.stereotype.Service
99
import java.util.concurrent.Executors
1010

11-
@Component
11+
@Service
1212
class ExperimentOrchestrator(
13-
private val lobbies: LobbyController,
14-
private val sessions: SessionController,
15-
private val games: GameController,
13+
private val lobbies: LobbyService,
14+
private val sessions: SessionService,
15+
private val games: GameService,
1616
private val daoController: DAOController
1717
) {
1818

game_server/src/main/kotlin/com/imsproject/gameserver/business/GameRequestFacade.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import com.imsproject.common.gameserver.GameRequest
44
import com.imsproject.common.gameserver.GameRequest.Type
55
import com.imsproject.common.utils.Response
66
import org.slf4j.LoggerFactory
7-
import org.springframework.stereotype.Component
7+
import org.springframework.stereotype.Service
88
import kotlin.reflect.full.memberProperties
99

10-
@Component
10+
@Service
1111
final class GameRequestFacade(
12-
private val games: GameController,
13-
private val sessions: SessionController,
14-
private val lobbies: LobbyController,
15-
private val clients: ClientController,
12+
private val games: GameService,
13+
private val sessions: SessionService,
14+
private val lobbies: LobbyService,
15+
private val clients: ClientService,
1616
private val experiments: ExperimentOrchestrator
1717
) {
1818

game_server/src/main/kotlin/com/imsproject/gameserver/business/GameController.kt renamed to game_server/src/main/kotlin/com/imsproject/gameserver/business/GameService.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import com.imsproject.common.utils.toJson
88
import com.imsproject.gameserver.business.games.*
99
import com.imsproject.gameserver.business.lobbies.LobbyState
1010
import org.slf4j.LoggerFactory
11-
import org.springframework.stereotype.Component
11+
import org.springframework.stereotype.Service
1212
import java.util.concurrent.ConcurrentHashMap
1313

14-
@Component
15-
class GameController(
16-
private val clients: ClientController,
17-
private val lobbies: LobbyController
14+
@Service
15+
class GameService(
16+
private val clients: ClientService,
17+
private val lobbies: LobbyService
1818
) {
1919

2020
init{
@@ -176,6 +176,6 @@ class GameController(
176176
}
177177

178178
companion object{
179-
private val log = LoggerFactory.getLogger(GameController::class.java)
179+
private val log = LoggerFactory.getLogger(GameService::class.java)
180180
}
181181
}

0 commit comments

Comments
 (0)