Makes code formatting consistent and clean

This commit is contained in:
aarbit 2024-06-28 16:06:53 -05:00
parent 139d40f1e0
commit 846fe20084
8 changed files with 43 additions and 19 deletions

View File

@ -7,7 +7,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration @Configuration
@EnableWebMvc @EnableWebMvc
class WebConfig: WebMvcConfigurer { class WebConfig : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) { override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**") registry.addMapping("/**")
} }

View File

@ -4,7 +4,10 @@ import net.halfbinary.prettyplayerapi.model.AlbumInfo
import net.halfbinary.prettyplayerapi.model.AlbumMetadata import net.halfbinary.prettyplayerapi.model.AlbumMetadata
import net.halfbinary.prettyplayerapi.model.TrackInfo import net.halfbinary.prettyplayerapi.model.TrackInfo
import net.halfbinary.prettyplayerapi.service.AlbumService 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 @RestController
@RequestMapping("album") @RequestMapping("album")

View File

@ -2,7 +2,10 @@ package net.halfbinary.prettyplayerapi.controller
import net.halfbinary.prettyplayerapi.service.ImageService import net.halfbinary.prettyplayerapi.service.ImageService
import org.springframework.http.MediaType 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 @RestController
@RequestMapping("image") @RequestMapping("image")

View File

@ -2,7 +2,10 @@ package net.halfbinary.prettyplayerapi.controller
import net.halfbinary.prettyplayerapi.service.MusicService import net.halfbinary.prettyplayerapi.service.MusicService
import org.springframework.http.ResponseEntity 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 import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
@RestController @RestController
@ -10,7 +13,10 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
class MusicController(private val musicService: MusicService) { class MusicController(private val musicService: MusicService) {
@GetMapping(value = ["/album/{albumHash}/track/{trackNumber}"], produces = ["audio/mpeg3"]) @GetMapping(value = ["/album/{albumHash}/track/{trackNumber}"], produces = ["audio/mpeg3"])
fun getAlbum(@PathVariable albumHash: String, @PathVariable trackNumber: Int): ResponseEntity<StreamingResponseBody> { fun getAlbum(
@PathVariable albumHash: String,
@PathVariable trackNumber: Int
): ResponseEntity<StreamingResponseBody> {
val track = musicService.getMusic(albumHash, trackNumber) val track = musicService.getMusic(albumHash, trackNumber)
val responseBody = StreamingResponseBody { stream -> stream.write(track.readBytes()) } val responseBody = StreamingResponseBody { stream -> stream.write(track.readBytes()) }
return ResponseEntity.ok().body(responseBody) return ResponseEntity.ok().body(responseBody)

View File

@ -1,4 +1,4 @@
package net.halfbinary.prettyplayerapi.exception package net.halfbinary.prettyplayerapi.exception
class AlbumFolderNotFoundException(folder: String) : RuntimeException("Album folder $folder does not exist") { class AlbumFolderNotFoundException(folder: String) :
} RuntimeException("Album folder $folder does not exist")

View File

@ -1,4 +1,3 @@
package net.halfbinary.prettyplayerapi.exception package net.halfbinary.prettyplayerapi.exception
class AlbumHashNotFoundException(hash: String) : RuntimeException("Album hash $hash not found") { class AlbumHashNotFoundException(hash: String) : RuntimeException("Album hash $hash not found")
}

View File

@ -1,4 +1,4 @@
package net.halfbinary.prettyplayerapi.exception package net.halfbinary.prettyplayerapi.exception
class EnvironmentVariableNotFoundException(envVar: String) : RuntimeException("Environment variable $envVar does not exist, please specify") { class EnvironmentVariableNotFoundException(envVar: String) :
} RuntimeException("Environment variable $envVar does not exist, please specify")

View File

@ -10,28 +10,41 @@ class GlobalExceptionHandler {
@ExceptionHandler @ExceptionHandler
fun handleEnvironmentVariableNotFoundException(e: EnvironmentVariableNotFoundException): ResponseEntity<ErrorResponse> { fun handleEnvironmentVariableNotFoundException(e: EnvironmentVariableNotFoundException): ResponseEntity<ErrorResponse> {
return ResponseEntity( return ResponseEntity(
ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ErrorResponse(
e.message ?:""), HttpStatus.INTERNAL_SERVER_ERROR) HttpStatus.INTERNAL_SERVER_ERROR.value(),
e.message ?: ""
), HttpStatus.INTERNAL_SERVER_ERROR
)
} }
@ExceptionHandler @ExceptionHandler
fun handleAlbumHashNotFoundException(e: AlbumHashNotFoundException): ResponseEntity<ErrorResponse> { fun handleAlbumHashNotFoundException(e: AlbumHashNotFoundException): ResponseEntity<ErrorResponse> {
return ResponseEntity( return ResponseEntity(
ErrorResponse(HttpStatus.BAD_REQUEST.value(), ErrorResponse(
e.message ?:""), HttpStatus.BAD_REQUEST) HttpStatus.BAD_REQUEST.value(),
e.message ?: ""
), HttpStatus.BAD_REQUEST
)
} }
@ExceptionHandler @ExceptionHandler
fun handleAlbumFolderNotFoundException(e: AlbumFolderNotFoundException): ResponseEntity<ErrorResponse> { fun handleAlbumFolderNotFoundException(e: AlbumFolderNotFoundException): ResponseEntity<ErrorResponse> {
return ResponseEntity( return ResponseEntity(
ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ErrorResponse(
e.message ?:""), HttpStatus.INTERNAL_SERVER_ERROR) HttpStatus.INTERNAL_SERVER_ERROR.value(),
e.message ?: ""
), HttpStatus.INTERNAL_SERVER_ERROR
)
} }
@ExceptionHandler @ExceptionHandler
fun handleException(e: RuntimeException): ResponseEntity<ErrorResponse> { fun handleException(e: RuntimeException): ResponseEntity<ErrorResponse> {
return ResponseEntity( return ResponseEntity(
ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ErrorResponse(
e.message?:""), HttpStatus.INTERNAL_SERVER_ERROR) HttpStatus.INTERNAL_SERVER_ERROR.value(),
e.message ?: ""
), HttpStatus.INTERNAL_SERVER_ERROR
)
} }
} }