diff --git a/src/main/kotlin/controller/api/AudioApiController.kt b/src/main/kotlin/controller/api/AudioApiController.kt index 46b1817..1918015 100644 --- a/src/main/kotlin/controller/api/AudioApiController.kt +++ b/src/main/kotlin/controller/api/AudioApiController.kt @@ -30,13 +30,24 @@ @RequestParam("album", required = false) albumName: String?, @RequestParam("tag", required = false) tagName: String? ): ResponseEntity = - ResponseEntity.ok(audioService.getByKeywords( - audioName, artistName, albumName, tagName, PAGE_LIMIT)) + ResponseEntity.ok( + audioService.getByKeywords( + audioName, artistName, albumName, tagName, PAGE_LIMIT + ) + ) @GetMapping("history") fun getLeastRecentlyPlayedList(): ResponseEntity = ResponseEntity.ok(audioService.getLeastRecentlyAccessedAudio(PAGE_LIMIT)) + @PostMapping("history/{slug}") + fun updateHistory( + @PathVariable("slug") slug: String + ): ResponseEntity { + audioService.updateHistory(slug) + return ResponseEntity.ok(null) + } + @PutMapping("{slug}") fun updateAudio( @PathVariable("slug") slug: String, diff --git a/src/main/kotlin/service/AudioService.kt b/src/main/kotlin/service/AudioService.kt index 8b04853..db4b4ae 100644 --- a/src/main/kotlin/service/AudioService.kt +++ b/src/main/kotlin/service/AudioService.kt @@ -39,12 +39,6 @@ if (!file.exists()) { throw NotFoundException() } - audioPlayHistoryDao.insertOrUpdateOne( - AudioPlayHistoryEntity( - audioId = audio.id, - lastPlayedAt = LocalDateTime.now(ZoneId.of("Asia/Tokyo")) - ) - ) return file } @@ -113,6 +107,17 @@ } } ?: throw NotFoundException() + fun updateHistory(slug: String) { + audioDao.findOneBySlug(slug)?.let { + audioPlayHistoryDao.insertOrUpdateOne( + AudioPlayHistoryEntity( + audioId = it.id, + lastPlayedAt = LocalDateTime.now(ZoneId.of("Asia/Tokyo")) + ) + ) + } + } + private fun findAllByArtistNameLikeLimit( artistNameLike: String, limit: Int