Skip to content

Commit 770c0e4

Browse files
committed
merge
2 parents 88e3cba + 308dba3 commit 770c0e4

9 files changed

Lines changed: 224 additions & 148 deletions

File tree

database/20.1 check api requests.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,62 @@ EXP WITH SESSION
9191

9292
curl -X POST "http://localhost:8080/data/experimentSession/insert" -H "Content-Type: application/json" -d "{\"pid1\":1,\"pid2\":2,\"sessions\":[{\"duration\":30,\"sessionType\":\"type1\",\"sessionOrder\":1,\"tolerance\":10,\"windowLength\":5},{\"duration\":45,\"sessionType\":\"Use PostgreSQLExecutor.\",\"sessionOrder\":2,\"tolerance\":12,\"windowLength\":6}]}"
9393

94+
95+
code for api testing:
96+
@PostMapping("/data/participant/{action}")
97+
fun dataTest1( @PathVariable action: String,
98+
@RequestBody body: String): ResponseEntity<String> {
99+
var obj = fromJson<ParticipantDTO>(body)
100+
101+
when(action) {
102+
"insert" -> { daoController.handleInsert(obj) }
103+
"delete" -> { daoController.handleDelete(obj) }
104+
"update" -> { daoController.handleUpdate(obj) }
105+
"select" -> { daoController.handleSelect(obj) }
106+
}
107+
return Response.getOk().toResponseEntity()
108+
}
109+
110+
@PostMapping("/data/experiment/{action}")
111+
fun dataTest2(
112+
@PathVariable action: String,
113+
@RequestBody body: String): ResponseEntity<String> {
114+
var obj = fromJson<ExperimentDTO>(body)
115+
116+
when(action) {
117+
"insert" -> { daoController.handleInsert(obj) }
118+
"delete" -> { daoController.handleDelete(obj) }
119+
"update" -> { daoController.handleUpdate(obj) }
120+
"select" -> { daoController.handleSelect(obj) }
121+
}
122+
return Response.getOk().toResponseEntity()
123+
}
124+
125+
@PostMapping("/data/session/{action}")
126+
fun dataTest3(
127+
@PathVariable action: String,
128+
@RequestBody body: String): ResponseEntity<String> {
129+
var obj = fromJson<SessionDTO>(body)
130+
when(action) {
131+
"insert" -> { daoController.handleInsert(obj) }
132+
"delete" -> { daoController.handleDelete(obj) }
133+
"update" -> { daoController.handleUpdate(obj) }
134+
"select" -> { daoController.handleSelect(obj) }
135+
}
136+
return Response.getOk().toResponseEntity()
137+
}
138+
139+
@PostMapping("/data/sessionEvent/{action}")
140+
fun dataTest4(
141+
@PathVariable action: String,
142+
@RequestBody body: String): ResponseEntity<String> {
143+
var obj = fromJson<SessionEventDTO>(body)
144+
145+
when(action) {
146+
"insert" -> { daoController.handleInsert(obj) }
147+
"delete" -> { daoController.handleDelete(obj) }
148+
"update" -> { daoController.handleUpdate(obj) }
149+
"select" -> { daoController.handleSelect(obj) }
150+
}
151+
return Response.getOk().toResponseEntity()
152+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import com.imsproject.gameserver.business.GameRequestFacade
1010
import com.imsproject.gameserver.business.ParticipantController
1111
import com.imsproject.gameserver.business.auth.AuthController
1212
import com.imsproject.gameserver.business.auth.Credentials
13-
import com.imsproject.gameserver.dataAccess.SectionEnum
13+
import com.imsproject.gameserver.dataAccess.models.ExperimentDTO
1414
import com.imsproject.gameserver.dataAccess.models.ParticipantDTO
15+
import com.imsproject.gameserver.dataAccess.models.SessionDTO
1516
import com.imsproject.gameserver.dataAccess.models.SessionEventDTO
1617
import kotlinx.coroutines.CoroutineScope
1718
import kotlinx.coroutines.asCoroutineDispatcher
@@ -154,7 +155,7 @@ class RestHandler(
154155
}
155156
scope.launch {
156157
val startTime = System.nanoTime()
157-
daoController.handleBulkInsert(SectionEnum.SESSION_EVENT, eventDTOs)
158+
daoController.handleBulkInsertSessionEvents(eventDTOs)
158159
val endTime = System.nanoTime()
159160
log.debug("Inserted {} events in {}ms for session {}", eventDTOs.size, (endTime - startTime) / 1_000_000, events.sessionId)
160161
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.imsproject.gameserver.business.ClientHandler
1111
import com.imsproject.gameserver.business.GameRequestFacade
1212
import com.imsproject.gameserver.business.LobbyController
1313
import com.imsproject.gameserver.dataAccess.DAOController
14-
import com.imsproject.gameserver.dataAccess.SectionEnum
1514
import com.imsproject.gameserver.dataAccess.implementations.ParticipantPK
1615
import org.slf4j.Logger
1716
import org.slf4j.LoggerFactory
@@ -155,7 +154,7 @@ class WsGameRequestHandler(
155154
return
156155
}
157156
)
158-
if(! daoController.handleExists(SectionEnum.PARTICIPANT,pk)){
157+
if(! daoController.handleExists(pk)){
159158
log.debug("Participant with id {} not found", id)
160159
session.send(GameRequest.builder(Type.PARTICIPANT_NOT_FOUND).build().toJson())
161160
return

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.imsproject.gameserver.business
22

33
import com.imsproject.gameserver.business.lobbies.LobbyState
4-
import com.imsproject.gameserver.dataAccess.DAOController
5-
import com.imsproject.gameserver.dataAccess.SectionEnum
6-
import com.imsproject.gameserver.dataAccess.models.ExperimentDTO
4+
import com.imsproject.gameserver.dataAccess.DAOController import com.imsproject.gameserver.dataAccess.models.ExperimentDTO
75
import com.imsproject.gameserver.dataAccess.models.SessionDTO
86
import kotlinx.coroutines.*
97
import org.slf4j.LoggerFactory
@@ -57,7 +55,7 @@ class ExperimentOrchestrator(
5755
val pid2 = Integer.parseInt(player2Id)
5856

5957
val experimentDTO = ExperimentDTO(null,pid1,pid2)
60-
val experimentId = daoController.handleInsert(SectionEnum.EXPERIMENT, experimentDTO)
58+
val experimentId = daoController.handleInsert(experimentDTO)
6159
experimentSessions.forEachIndexed { index, session ->
6260
if(session.dbId == null){
6361
val dto = SessionDTO(
@@ -70,7 +68,7 @@ class ExperimentOrchestrator(
7068
session.syncWindowLength.toInt(),
7169
SessionState.NOT_STARTED.name
7270
)
73-
val sessionId = daoController.handleInsert(SectionEnum.SESSION, dto)
71+
val sessionId = daoController.handleInsert(dto)
7472
session.dbId = sessionId
7573
}
7674
}
@@ -94,7 +92,7 @@ class ExperimentOrchestrator(
9492
delay(session.duration.toLong()*1000)
9593
games.endGame(lobbyId)
9694
val updatedSessionDTO = SessionDTO(sessionId = sessionId, state = SessionState.COMPLETED.name)
97-
daoController.handleUpdate(SectionEnum.SESSION, updatedSessionDTO)
95+
daoController.handleUpdate(updatedSessionDTO)
9896
sessions.removeSession(lobbyId, session.sessionId)
9997
}
10098
lobby.experimentRunning = false
@@ -134,7 +132,7 @@ class ExperimentOrchestrator(
134132
throw IllegalStateException("Session dbId not found for in-progress session in lobby $lobbyId")
135133
}
136134
val updatedSessionDTO = SessionDTO(sessionId = dbId, state = SessionState.CANCELLED.name)
137-
daoController.handleUpdate(SectionEnum.SESSION, updatedSessionDTO)
135+
daoController.handleUpdate(updatedSessionDTO)
138136
sessions.removeSession(lobbyId, currentSession.sessionId)
139137
}
140138
if(lobby.hasSessions){

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.imsproject.gameserver.business
22

33
import com.imsproject.common.utils.SimpleIdGenerator
44
import com.imsproject.gameserver.dataAccess.DAOController
5-
import com.imsproject.gameserver.dataAccess.SectionEnum
65
import com.imsproject.gameserver.dataAccess.implementations.ParticipantPK
76
import com.imsproject.gameserver.dataAccess.models.ParticipantDTO
87
import org.springframework.stereotype.Component
@@ -13,19 +12,19 @@ class ParticipantController(val daoController: DAOController) {
1312

1413
operator fun contains(userId: Int): Boolean {
1514
val pk = ParticipantPK(userId)
16-
return daoController.handleExists(SectionEnum.PARTICIPANT,pk)
15+
return daoController.handleExists(pk)
1716
}
1817

1918
fun getAll(): List<ParticipantDTO>{
20-
return daoController.handleSelectAll(SectionEnum.PARTICIPANT)
19+
return daoController.handleSelectAllParticipants()
2120
}
2221

2322
fun remove(userId: Int) {
2423
val pk = ParticipantDTO(pid = userId)
25-
daoController.handleDelete(SectionEnum.PARTICIPANT,pk)
24+
daoController.handleDelete(pk)
2625
}
2726

2827
fun addParticipant(participant: ParticipantDTO): Int {
29-
return daoController.handleInsert(SectionEnum.PARTICIPANT,participant)
28+
return daoController.handleInsert(participant)
3029
}
3130
}

0 commit comments

Comments
 (0)