Added mechanism for retrieving in-progress session data.
This commit is contained in:
parent
0ec96a874d
commit
319e59354a
@ -80,4 +80,8 @@ object GroupSessionManager {
|
|||||||
fun updateObservationData(input: GroupObservation) {
|
fun updateObservationData(input: GroupObservation) {
|
||||||
observations[input.person] = input
|
observations[input.person] = input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun participantExistsInSession(name: String): Boolean = observations.containsKey(name)
|
||||||
|
|
||||||
|
fun getObservationDataForParticipant(name: String): GroupObservation? = observations[name]
|
||||||
}
|
}
|
@ -120,6 +120,16 @@ class GroupSessionController {
|
|||||||
return committedObservation
|
return committedObservation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current observation data for a user with [name] in the current session.
|
||||||
|
*/
|
||||||
|
@GetMapping("/participant/{name}")
|
||||||
|
fun getParticipantData(@PathVariable name: String): GroupObservation{
|
||||||
|
if(GroupSessionManager.participantExistsInSession(name))
|
||||||
|
return GroupSessionManager.getObservationDataForParticipant(name)!!
|
||||||
|
throw ResponseStatusException(HttpStatus.NOT_FOUND, "No participant with the name:'$name'")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit an observation to be added to the session state and actual database
|
* Submit an observation to be added to the session state and actual database
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,6 @@ import org.mockito.Mockito
|
|||||||
import org.mockito.Mockito.times
|
import org.mockito.Mockito.times
|
||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
import org.mockito.junit.MockitoJUnitRunner
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
|
||||||
import org.springframework.messaging.simp.SimpMessagingTemplate
|
import org.springframework.messaging.simp.SimpMessagingTemplate
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
import uk.co.neviyn.observationdatabase.GroupObservation
|
import uk.co.neviyn.observationdatabase.GroupObservation
|
||||||
@ -150,4 +149,26 @@ class GroupSessionControllerTest {
|
|||||||
assertEquals("A Student", GroupSessionManager.observations.keys.first())
|
assertEquals("A Student", GroupSessionManager.observations.keys.first())
|
||||||
assertEquals("A Student", GroupSessionManager.observations.values.first().person)
|
assertEquals("A Student", GroupSessionManager.observations.values.first().person)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = ResponseStatusException::class)
|
||||||
|
fun testGetParticipantData_NoParticipant() {
|
||||||
|
controller.getParticipantData("Someone")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ResponseStatusException::class)
|
||||||
|
fun testGetParticipantData_WrongName() {
|
||||||
|
val rc = RatingComponent(rating = 5)
|
||||||
|
val testData = GroupObservation("A Student", listOf(Scenario(0, "Sample title", rc, rc, rc, rc, rc, rc, rc, rc)))
|
||||||
|
GroupSessionManager.observations["A Student"] = testData
|
||||||
|
controller.getParticipantData("Another Student")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetParticipantData() {
|
||||||
|
val rc = RatingComponent(rating = 5)
|
||||||
|
val testData = GroupObservation("A Student", listOf(Scenario(0, "Sample title", rc, rc, rc, rc, rc, rc, rc, rc)))
|
||||||
|
GroupSessionManager.observations["A Student"] = testData
|
||||||
|
val output = controller.getParticipantData("A Student")
|
||||||
|
assertEquals(testData, output)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user