Skip to content

Commit 714d33c

Browse files
authored
Merge pull request #201 from mp-access/return-time-frame-on-publish
`/publish` endpoint adjustment
2 parents 903fa7d + c5e2219 commit 714d33c

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/main/kotlin/ch/uzh/ifi/access/controller/ExampleController.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,36 @@ class ExampleController(
170170
@PathVariable course: String,
171171
@PathVariable example: String,
172172
@RequestBody body: ExampleDurationDTO,
173-
) {
173+
):ExamplePublicationDTO {
174174
val activeExample = exampleService.getExamples(course).firstOrNull {
175175
it.status == TaskStatus.Interactive
176176
}
177177

178178
if (activeExample != null) {
179179
throw ResponseStatusException(
180-
HttpStatus.NOT_FOUND,
180+
HttpStatus.CONFLICT,
181181
"An interactive example already exists."
182182
)
183183
}
184184

185185
val updatedExample = exampleService.publishExampleBySlug(course, example, body.duration)
186186

187+
val start = updatedExample.start
188+
val end = updatedExample.end
189+
190+
if (start == null || end == null) {
191+
throw ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Published example is missing required start or end time.")
192+
}
193+
187194
emitterService.sendPayload(EmitterType.STUDENT, course, "redirect", "/courses/$course/examples/$example")
188195
emitterService.sendPayload(
189196
EmitterType.EVERYONE,
190197
course,
191198
"timer-update",
192-
"${updatedExample.start}/${updatedExample.end}"
199+
"${start}/${end}"
193200
)
201+
202+
return ExamplePublicationDTO(start, end)
194203
}
195204

196205
// Invoked by the teacher when want to extend the time of an active example by a certain amount of seconds
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ch.uzh.ifi.access.model.dto
2+
3+
import java.time.LocalDateTime
4+
5+
data class ExamplePublicationDTO (
6+
val startDate: LocalDateTime,
7+
val endDate:LocalDateTime
8+
)

0 commit comments

Comments
 (0)