Skip to content

Commit

Permalink
Expose logs via /api/logs/ endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
stscoundrel committed Apr 21, 2024
1 parent 170cc1b commit 56f08d9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.stscoundrel.revalidator.controller

import io.github.stscoundrel.revalidator.entities.Log
import io.github.stscoundrel.revalidator.service.LogService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/logs")
class LogController(private val logService: LogService) {
@GetMapping
fun getAllLogs(): List<Log> {
return logService.getAll()
}

@GetMapping("/old-norse")
fun getOldNorseLogs(): List<Log> {
return logService.getOldNorse()
}

@GetMapping("/old-icelandic")
fun getOldIcelandicLogs(): List<Log> {
return logService.getOldIcelandic()
}

@GetMapping("/old-swedish")
fun getOldSwedishLogs(): List<Log> {
return logService.getOldSwedish()
}

@GetMapping("/old-norwegian")
fun getOldNorwegianLogs(): List<Log> {
return logService.getOldNorwegian()
}

@GetMapping("/old-danish")
fun getOldDanishLogs(): List<Log> {
return logService.getOldDanish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import jakarta.persistence.*
import java.time.LocalDateTime

@Entity
data class Log(
class Log(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
val message: String,
val timestamp: LocalDateTime = LocalDateTime.now(),
@Enumerated(EnumType.STRING)
val dictionaryType: DictionaryType
)
) {
// Default constructor, mainly to sidestep serialization issues.
constructor() : this(0, "", LocalDateTime.now(), DictionaryType.OLD_NORSE)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.stscoundrel.revalidator.repository

import io.github.stscoundrel.revalidator.entities.Log
import io.github.stscoundrel.revalidator.enums.DictionaryType
import org.springframework.data.jpa.repository.JpaRepository

interface LogRepository : JpaRepository<Log, Long>
interface LogRepository : JpaRepository<Log, Long> {
fun findByDictionaryType(dictionaryType: DictionaryType): List<Log>
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,24 @@ class LogService(private val logRepository: LogRepository) {
fun getAll(): List<Log> {
return logRepository.findAll()
}

fun getOldNorse(): List<Log> {
return logRepository.findByDictionaryType(DictionaryType.OLD_NORSE)
}

fun getOldIcelandic(): List<Log> {
return logRepository.findByDictionaryType(DictionaryType.OLD_ICELANDIC)
}

fun getOldNorwegian(): List<Log> {
return logRepository.findByDictionaryType(DictionaryType.OLD_NORWEGIAN)
}

fun getOldSwedish(): List<Log> {
return logRepository.findByDictionaryType(DictionaryType.OLD_SWEDISH)
}

fun getOldDanish(): List<Log> {
return logRepository.findByDictionaryType(DictionaryType.OLD_DANISH)
}
}

0 comments on commit 56f08d9

Please sign in to comment.