Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,29 @@ class CheckpointSessionController(
?: throw NotFoundException(message = "session with $sessionId not found")
}

@GetMapping("/dates")
fun getCalendarSessions(
@Passport passport: PassportContent,
@PathVariable groupId: Long,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM") month: YearMonth
): List<SessionResponseDto> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method should return SessionDateReponseDTO

passport.userGroups?.find { it.toLong() == groupId }
?: throw ForbiddenException(message = "User is not a member of this group")

return sessionService.getCalendarSessions(groupId, month)
}

@GetMapping("/months")
fun getMonthsWithSessions(
@Passport passport: PassportContent,
@PathVariable groupId: Long
): List<String> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -89,6 +90,26 @@ class CheckpointSessionService(
}
return response.toList()
}
fun getCalendarSessions(groupId: Long, month: YearMonth): List<SessionResponseDto> {
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())

return checkpointSessionRepository.findAllByGroupIdAndCreatedDateBetween(groupId, calendarStart, calendarEnd)
.map { it.toDto() }
}

fun getMonthsWithSessions(groupId: Long): List<String> {
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)
Expand All @@ -100,5 +121,7 @@ class CheckpointSessionService(
checkpointRepository.save(Checkpoint(session, groupUser))
}
return session.toDto()


}
}