From 846fe20084aa5a57e945672e0fa38eacf2b2833e Mon Sep 17 00:00:00 2001 From: aarbit Date: Fri, 28 Jun 2024 16:06:53 -0500 Subject: [PATCH] Makes code formatting consistent and clean --- .../prettyplayerapi/config/WebConfig.kt | 2 +- .../controller/AlbumController.kt | 5 +++- .../controller/ImageController.kt | 5 +++- .../controller/MusicController.kt | 10 +++++-- .../exception/AlbumFolderNotFoundException.kt | 4 +-- .../exception/AlbumHashNotFoundException.kt | 3 +- .../EnvironmentVariableNotFoundException.kt | 4 +-- .../exception/GlobalExceptionHandler.kt | 29 ++++++++++++++----- 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/config/WebConfig.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/config/WebConfig.kt index b3e8fa9..69dd53a 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/config/WebConfig.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/config/WebConfig.kt @@ -7,7 +7,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @Configuration @EnableWebMvc -class WebConfig: WebMvcConfigurer { +class WebConfig : WebMvcConfigurer { override fun addCorsMappings(registry: CorsRegistry) { registry.addMapping("/**") } diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/AlbumController.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/AlbumController.kt index b7ce374..232fedf 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/AlbumController.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/AlbumController.kt @@ -4,7 +4,10 @@ import net.halfbinary.prettyplayerapi.model.AlbumInfo import net.halfbinary.prettyplayerapi.model.AlbumMetadata import net.halfbinary.prettyplayerapi.model.TrackInfo import net.halfbinary.prettyplayerapi.service.AlbumService -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("album") diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/ImageController.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/ImageController.kt index 34e0b36..c34aa9b 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/ImageController.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/ImageController.kt @@ -2,7 +2,10 @@ package net.halfbinary.prettyplayerapi.controller import net.halfbinary.prettyplayerapi.service.ImageService import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("image") diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/MusicController.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/MusicController.kt index 558fb2d..2dfa713 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/MusicController.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/MusicController.kt @@ -2,7 +2,10 @@ package net.halfbinary.prettyplayerapi.controller import net.halfbinary.prettyplayerapi.service.MusicService import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody @RestController @@ -10,7 +13,10 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo class MusicController(private val musicService: MusicService) { @GetMapping(value = ["/album/{albumHash}/track/{trackNumber}"], produces = ["audio/mpeg3"]) - fun getAlbum(@PathVariable albumHash: String, @PathVariable trackNumber: Int): ResponseEntity { + fun getAlbum( + @PathVariable albumHash: String, + @PathVariable trackNumber: Int + ): ResponseEntity { val track = musicService.getMusic(albumHash, trackNumber) val responseBody = StreamingResponseBody { stream -> stream.write(track.readBytes()) } return ResponseEntity.ok().body(responseBody) diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumFolderNotFoundException.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumFolderNotFoundException.kt index ab38ce7..6094f10 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumFolderNotFoundException.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumFolderNotFoundException.kt @@ -1,4 +1,4 @@ package net.halfbinary.prettyplayerapi.exception -class AlbumFolderNotFoundException(folder: String) : RuntimeException("Album folder $folder does not exist") { -} \ No newline at end of file +class AlbumFolderNotFoundException(folder: String) : + RuntimeException("Album folder $folder does not exist") \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumHashNotFoundException.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumHashNotFoundException.kt index 5889621..58af604 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumHashNotFoundException.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/AlbumHashNotFoundException.kt @@ -1,4 +1,3 @@ package net.halfbinary.prettyplayerapi.exception -class AlbumHashNotFoundException(hash: String) : RuntimeException("Album hash $hash not found") { -} \ No newline at end of file +class AlbumHashNotFoundException(hash: String) : RuntimeException("Album hash $hash not found") \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/EnvironmentVariableNotFoundException.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/EnvironmentVariableNotFoundException.kt index 8280f6d..a256137 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/EnvironmentVariableNotFoundException.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/EnvironmentVariableNotFoundException.kt @@ -1,4 +1,4 @@ package net.halfbinary.prettyplayerapi.exception -class EnvironmentVariableNotFoundException(envVar: String) : RuntimeException("Environment variable $envVar does not exist, please specify") { -} \ No newline at end of file +class EnvironmentVariableNotFoundException(envVar: String) : + RuntimeException("Environment variable $envVar does not exist, please specify") \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/GlobalExceptionHandler.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/GlobalExceptionHandler.kt index fa3499b..383b100 100644 --- a/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/GlobalExceptionHandler.kt +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/exception/GlobalExceptionHandler.kt @@ -10,28 +10,41 @@ class GlobalExceptionHandler { @ExceptionHandler fun handleEnvironmentVariableNotFoundException(e: EnvironmentVariableNotFoundException): ResponseEntity { return ResponseEntity( - ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), - e.message ?:""), HttpStatus.INTERNAL_SERVER_ERROR) + ErrorResponse( + HttpStatus.INTERNAL_SERVER_ERROR.value(), + e.message ?: "" + ), HttpStatus.INTERNAL_SERVER_ERROR + ) } @ExceptionHandler fun handleAlbumHashNotFoundException(e: AlbumHashNotFoundException): ResponseEntity { return ResponseEntity( - ErrorResponse(HttpStatus.BAD_REQUEST.value(), - e.message ?:""), HttpStatus.BAD_REQUEST) + ErrorResponse( + HttpStatus.BAD_REQUEST.value(), + e.message ?: "" + ), HttpStatus.BAD_REQUEST + ) } @ExceptionHandler fun handleAlbumFolderNotFoundException(e: AlbumFolderNotFoundException): ResponseEntity { return ResponseEntity( - ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), - e.message ?:""), HttpStatus.INTERNAL_SERVER_ERROR) + ErrorResponse( + HttpStatus.INTERNAL_SERVER_ERROR.value(), + e.message ?: "" + ), HttpStatus.INTERNAL_SERVER_ERROR + ) } + @ExceptionHandler fun handleException(e: RuntimeException): ResponseEntity { return ResponseEntity( - ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), - e.message?:""), HttpStatus.INTERNAL_SERVER_ERROR) + ErrorResponse( + HttpStatus.INTERNAL_SERVER_ERROR.value(), + e.message ?: "" + ), HttpStatus.INTERNAL_SERVER_ERROR + ) } }