From 0ca3f7f340243ecad466e76f6c894ca19fb1b956 Mon Sep 17 00:00:00 2001 From: HahaGh0sty <181955075+HahaGh0sty@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:15:37 +0200 Subject: [PATCH 1/2] added endpoints for calendar, one to get a months worth of sessions and another to get every month that has checkpoints --- .../CheckpointSessionController.kt | 26 +++++++++++++++++++ .../services/CheckpointSessionService.kt | 22 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt b/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt index 700a364..df62a5a 100644 --- a/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt +++ b/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt @@ -83,6 +83,32 @@ class CheckpointSessionController( ?: throw NotFoundException(message = "session with $sessionId not found") } + @GetMapping("/calendar") + fun getCalendarSessions( + @Passport passport: PassportContent, + @PathVariable groupId: Long, + @RequestParam year: Int, + @RequestParam month: Int + ): List { + passport.userGroups?.find { it.toLong() == groupId } + ?: throw ForbiddenException(message = "User is not a member of this group") + + if (month !in 1..12) throw BadRequestException(message = "Month must be between 1 and 12") + + return sessionService.getCalendarSessions(groupId, year, month) + } + + @GetMapping("/months") + fun getMonthsWithSessions( + @Passport passport: PassportContent, + @PathVariable groupId: Long + ): List { + passport.userGroups?.find { it.toLong() == groupId } + ?: throw ForbiddenException(message = "User is not a member of this group") + + return sessionService.getMonthsWithSessions(groupId) + } + @PostMapping fun createSession( @Passport passport: PassportContent, diff --git a/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt b/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt index fcd024f..206e5e9 100644 --- a/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt +++ b/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt @@ -15,6 +15,7 @@ import org.springframework.security.oauth2.jwt.Jwt import org.springframework.stereotype.Service import java.time.LocalDate import java.time.LocalTime +import java.time.YearMonth @Service class CheckpointSessionService( @@ -89,6 +90,25 @@ class CheckpointSessionService( } return response.toList() } + fun getCalendarSessions(groupId: Long, year: Int, month: Int): List { + val firstOfMonth = LocalDate.of(year, month, 1) + val lastOfMonth = firstOfMonth.withDayOfMonth(firstOfMonth.lengthOfMonth()) + val calendarStart = firstOfMonth.minusDays((firstOfMonth.dayOfWeek.value - 1).toLong()) + val calendarEnd = lastOfMonth.plusDays((7 - lastOfMonth.dayOfWeek.value).toLong()) + + return checkpointSessionRepository.findAllByGroupIdAndCreatedDateBetween(groupId, calendarStart, calendarEnd) + .map { it.toDto() } + } + + fun getMonthsWithSessions(groupId: Long): List { + val dates = checkpointSessionRepository.findAllByGroupId(groupId).map { it.createdDate } + + return dates + .map { YearMonth.from(it) } + .distinct() + .sorted() + .map { it.toString() } // formats as "2026-01" + } fun createSession(jwt: Jwt, groupId: Long, ownerId: Long, dto: CheckpointSessionCreationDto): SessionResponseDto { val checkpointSession = dto.toEntity(groupId, ownerId, dto.name) @@ -100,5 +120,7 @@ class CheckpointSessionService( checkpointRepository.save(Checkpoint(session, groupUser)) } return session.toDto() + + } } \ No newline at end of file From 5d1e23717bd2f724ab3ade8fa2f552076fd6fd9a Mon Sep 17 00:00:00 2001 From: HahaGh0sty <181955075+HahaGh0sty@users.noreply.github.com> Date: Mon, 22 Jun 2026 14:50:14 +0200 Subject: [PATCH 2/2] changed the url for the request (sorry i forgot it) --- .../controllers/CheckpointSessionController.kt | 10 ++++------ .../services/CheckpointSessionService.kt | 7 ++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt b/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt index df62a5a..53c2139 100644 --- a/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt +++ b/src/main/kotlin/com/scrumdapp/checkpointservice/controllers/CheckpointSessionController.kt @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController import java.time.LocalDate +import java.time.YearMonth @RestController @Validated @@ -83,19 +84,16 @@ class CheckpointSessionController( ?: throw NotFoundException(message = "session with $sessionId not found") } - @GetMapping("/calendar") + @GetMapping("/dates") fun getCalendarSessions( @Passport passport: PassportContent, @PathVariable groupId: Long, - @RequestParam year: Int, - @RequestParam month: Int + @RequestParam @DateTimeFormat(pattern = "yyyy-MM") month: YearMonth ): List { passport.userGroups?.find { it.toLong() == groupId } ?: throw ForbiddenException(message = "User is not a member of this group") - if (month !in 1..12) throw BadRequestException(message = "Month must be between 1 and 12") - - return sessionService.getCalendarSessions(groupId, year, month) + return sessionService.getCalendarSessions(groupId, month) } @GetMapping("/months") diff --git a/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt b/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt index 206e5e9..a4f89a7 100644 --- a/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt +++ b/src/main/kotlin/com/scrumdapp/checkpointservice/services/CheckpointSessionService.kt @@ -90,9 +90,10 @@ class CheckpointSessionService( } return response.toList() } - fun getCalendarSessions(groupId: Long, year: Int, month: Int): List { - val firstOfMonth = LocalDate.of(year, month, 1) - val lastOfMonth = firstOfMonth.withDayOfMonth(firstOfMonth.lengthOfMonth()) + fun getCalendarSessions(groupId: Long, month: YearMonth): List { + val firstOfMonth = month.atDay(1) + val lastOfMonth = month.atEndOfMonth() + val calendarStart = firstOfMonth.minusDays((firstOfMonth.dayOfWeek.value - 1).toLong()) val calendarEnd = lastOfMonth.plusDays((7 - lastOfMonth.dayOfWeek.value).toLong())