GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
yhornisse
/
bremer
Browse code
fix bug to search audio
master
1 parent
7ece182
commit
62024e479cdb7eae56dd63331fdc9031588b93c3
yhornisse
authored
on 21 Aug 2023
Patch
Showing
1 changed file
src/main/kotlin/controller/api/AudioApiController.kt
Ignore Space
Show notes
View
src/main/kotlin/controller/api/AudioApiController.kt
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.controller.api import jakarta.validation.Valid import net.piedpiper.bremer.model.api.AudioListResponse import net.piedpiper.bremer.model.api.AudioRequest import net.piedpiper.bremer.service.AudioService import org.springframework.beans.factory.annotation.Qualifier import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RestController("bremer.controller.AudioApiController") @RequestMapping("bremer/api/audio") class AudioApiController( @Qualifier("bremer.service.AudioService") private val audioService: AudioService ) { companion object { private const val PAGE_LIMIT = 50 private fun splitKeywords(keywords: String?): List<String>? { return if (keywords?.isNotEmpty() == true) { keywords?.split("\\s".toRegex())?.toList() } else { null } } } @GetMapping fun getAudioList( @RequestParam("audio", required = false) audioName: String?, @RequestParam("artist", required = false) artistName: String?, @RequestParam("album", required = false) albumName: String?, @RequestParam("tag", required = false) tagName: String? ): ResponseEntity<AudioListResponse> = ResponseEntity.ok( audioService.getByKeywords( splitKeywords(audioName), splitKeywords(artistName), splitKeywords(albumName), splitKeywords(tagName), PAGE_LIMIT ) ) @GetMapping("history") fun getLeastRecentlyPlayedList(): ResponseEntity<AudioListResponse> = ResponseEntity.ok(audioService.getLeastRecentlyAccessedAudio(PAGE_LIMIT)) @PostMapping("history/{slug}") fun updateHistory( @PathVariable("slug") slug: String ): ResponseEntity<Void> { audioService.updateHistory(slug, PAGE_LIMIT) return ResponseEntity.ok(null) } @PutMapping("{slug}") fun updateAudio( @PathVariable("slug") slug: String, @Valid @RequestBody request: AudioRequest ): ResponseEntity<Void> { audioService.update(slug, request) return ResponseEntity.ok(null) } @DeleteMapping("{slug}") fun deleteAudio( @PathVariable("slug") slug: String ): ResponseEntity<Void> { audioService.delete(slug) return ResponseEntity.ok(null) } }
/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.controller.api import jakarta.validation.Valid import net.piedpiper.bremer.model.api.AudioListResponse import net.piedpiper.bremer.model.api.AudioRequest import net.piedpiper.bremer.service.AudioService import org.springframework.beans.factory.annotation.Qualifier import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RestController("bremer.controller.AudioApiController") @RequestMapping("bremer/api/audio") class AudioApiController( @Qualifier("bremer.service.AudioService") private val audioService: AudioService ) { companion object { private const val PAGE_LIMIT = 50 } @GetMapping fun getAudioList( @RequestParam("audio", required = false) audioName: String?, @RequestParam("artist", required = false) artistName: String?, @RequestParam("album", required = false) albumName: String?, @RequestParam("tag", required = false) tagName: String? ): ResponseEntity<AudioListResponse> = ResponseEntity.ok( audioService.getByKeywords( audioName?.split("\\s".toRegex())?.toList(), artistName?.split("\\s".toRegex())?.toList(), albumName?.split("\\s".toRegex())?.toList(), tagName?.split("\\s".toRegex())?.toList(), PAGE_LIMIT ) ) @GetMapping("history") fun getLeastRecentlyPlayedList(): ResponseEntity<AudioListResponse> = ResponseEntity.ok(audioService.getLeastRecentlyAccessedAudio(PAGE_LIMIT)) @PostMapping("history/{slug}") fun updateHistory( @PathVariable("slug") slug: String ): ResponseEntity<Void> { audioService.updateHistory(slug, PAGE_LIMIT) return ResponseEntity.ok(null) } @PutMapping("{slug}") fun updateAudio( @PathVariable("slug") slug: String, @Valid @RequestBody request: AudioRequest ): ResponseEntity<Void> { audioService.update(slug, request) return ResponseEntity.ok(null) } @DeleteMapping("{slug}") fun deleteAudio( @PathVariable("slug") slug: String ): ResponseEntity<Void> { audioService.delete(slug) return ResponseEntity.ok(null) } }
Show line notes below