feat: Init backend

This commit is contained in:
2025-02-21 08:26:58 +01:00
parent 84e701131f
commit e7557ce2e2
29 changed files with 1802 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
package com.betriebsratkanzlei.legalconsenthub.error
class ApplicationFormNotCreatedException(e: Exception): RuntimeException("Couldn't create application form", e)

View File

@@ -0,0 +1,3 @@
package com.betriebsratkanzlei.legalconsenthub.error
class ApplicationFormNotDeletedException(e: Exception): RuntimeException("Couldn't delete application form", e)

View File

@@ -0,0 +1,5 @@
package com.betriebsratkanzlei.legalconsenthub.error
import java.util.UUID
class ApplicationFormNotFoundException(id: UUID): RuntimeException("Couldn't find application form with ID: $id")

View File

@@ -0,0 +1,5 @@
package com.betriebsratkanzlei.legalconsenthub.error
import java.util.UUID
class ApplicationFormNotUpdatedException(e: Exception, id: UUID): RuntimeException("Couldn't update application form with ID: $id", e)

View File

@@ -0,0 +1,53 @@
package com.betriebsratkanzlei.legalconsenthub.error
import com.betriebsratkanzlei.legalconsenthub_api.model.ProblemDetails
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.ResponseStatus
import java.net.URI
@ControllerAdvice
class ExceptionHandler {
var logger = LoggerFactory.getLogger(ExceptionHandler::class.java)
@ResponseBody
@ExceptionHandler(ApplicationFormNotFoundException::class)
@ResponseStatus(HttpStatus.NOT_FOUND)
fun handleNotFoundError(e: Exception): ResponseEntity<ProblemDetails> {
logger.warn(e.message, e)
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_PROBLEM_JSON)
.body(
ProblemDetails(
title = "Not Found",
status = HttpStatus.NOT_FOUND.value(),
type = URI.create("about:blank"),
detail = e.message ?: "Something went wrong"
)
)
}
@ResponseBody
@ExceptionHandler(
ApplicationFormNotCreatedException::class,
ApplicationFormNotUpdatedException::class,
ApplicationFormNotDeletedException::class,
)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
fun handleInternalServerError(e: Exception): ResponseEntity<ProblemDetails> {
logger.warn(e.message, e)
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.APPLICATION_PROBLEM_JSON)
.body(
ProblemDetails(
title = "Internal Server Error",
status = HttpStatus.INTERNAL_SERVER_ERROR.value(),
type = URI.create("about:blank"),
detail = e.message ?: "Something went wrong"
)
)
}
}