Skip to content

Commit

Permalink
Merge pull request #428 from Team-Ampersand/415-feat/music-rank-query
Browse files Browse the repository at this point in the history
415 음악 랭킹 조회 api + 최신순 조회 like count 반환값 추가
  • Loading branch information
esperar authored Sep 19, 2024
2 parents e592561 + 46d18b5 commit 70327e2
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class Music(
@JoinColumn(name = "member_id", nullable = false)
val member: Member
) : BaseTimeEntity() {

fun plusLikeCount() {
this.likeCount++
}

fun minusLikeCount() {
this.likeCount--
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.time.LocalDate
import java.time.LocalDateTime

interface MusicRepository : JpaRepository<Music, Long> {

@Modifying
@Query("update member set member_music = 'CAN'", nativeQuery = true)
fun updateMusicStatusMemberByMember()
Expand All @@ -18,4 +19,7 @@ interface MusicRepository : JpaRepository<Music, Long> {

fun deleteAllByCreatedDateBefore(date: LocalDateTime)

@Query(value = "select * from music where created_date like :date% order by music.like_count", nativeQuery = true)
fun findAllByCreatedDateOrderByLikeCount(@Param("date") date: LocalDate): List<Music>

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.dotori.v2.domain.music.presentation.admin

import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicLikeCountResDto
import com.dotori.v2.domain.music.service.DeleteMusicService
import com.dotori.v2.domain.music.service.FindMusicRankService
import com.dotori.v2.domain.music.service.FindMusicsService
import com.dotori.v2.domain.music.service.ToggleMusicLikeService
import org.springframework.format.annotation.DateTimeFormat
Expand All @@ -16,8 +18,10 @@ import java.time.LocalDate
class AdminMusicController(
private val findMusicsService: FindMusicsService,
private val deleteMusicService: DeleteMusicService,
private val toggleMusicLikeService: ToggleMusicLikeService
private val toggleMusicLikeService: ToggleMusicLikeService,
private val findMusicRankService: FindMusicRankService
) {

@GetMapping
fun findMusics(
@RequestParam(
Expand All @@ -33,6 +37,16 @@ class AdminMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

@PatchMapping("/{music_id}/like")
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<MusicLikeCountResDto> =
ResponseEntity.status(HttpStatus.OK).body(toggleMusicLikeService.execute(musicId))
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<Void> =
toggleMusicLikeService.execute(musicId)
.run { ResponseEntity.status(HttpStatus.OK).build() }

@GetMapping("/like")
fun findMusicRank(
@RequestParam(
value = "date",
required = true
) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) date: LocalDate
): ResponseEntity<MusicRankListResDto> =
ResponseEntity.status(HttpStatus.OK).body(findMusicRankService.execute(date))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.dotori.v2.domain.music.presentation.councillor

import com.dotori.v2.domain.music.presentation.data.req.ApplyMusicReqDto
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicLikeCountResDto
import com.dotori.v2.domain.music.service.ApplyMusicService
import com.dotori.v2.domain.music.service.DeleteMusicService
import com.dotori.v2.domain.music.service.FindMusicRankService
import com.dotori.v2.domain.music.service.FindMusicsService
import com.dotori.v2.domain.music.service.ToggleMusicLikeService
import org.springframework.format.annotation.DateTimeFormat
Expand All @@ -20,7 +22,8 @@ class CouncillorMusicController(
private val applyMusicService: ApplyMusicService,
private val findMusicsService: FindMusicsService,
private val deleteMusicService: DeleteMusicService,
private val toggleMusicLikeService: ToggleMusicLikeService
private val toggleMusicLikeService: ToggleMusicLikeService,
private val findMusicRankService: FindMusicRankService
) {
@PostMapping
fun applyMusic(@RequestBody applyMusicReqDto: ApplyMusicReqDto): ResponseEntity<Void> =
Expand All @@ -42,6 +45,16 @@ class CouncillorMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

@PatchMapping("/{music_id}/like")
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<MusicLikeCountResDto> =
ResponseEntity.status(HttpStatus.OK).body(toggleMusicLikeService.execute(musicId))
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<Void> =
toggleMusicLikeService.execute(musicId)
.run { ResponseEntity.status(HttpStatus.OK).build() }

@GetMapping("/like")
fun findMusicRank(
@RequestParam(
value = "date",
required = true
) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) date: LocalDate
): ResponseEntity<MusicRankListResDto> =
ResponseEntity.status(HttpStatus.OK).body(findMusicRankService.execute(date))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dotori.v2.domain.music.presentation.data.res

data class MusicRankListResDto(
val content: List<MusicRankResDto>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dotori.v2.domain.music.presentation.data.res

import java.time.LocalDateTime

data class MusicRankResDto(
val id: Long,
val rank: Int,
val url: String,
val title: String,
val thumbnail: String,
val username: String,
val email: String,
val createdTime: LocalDateTime,
val stuNum: String,
val likeCount: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class MusicResDto(
val username: String,
val email: String,
val createdTime: LocalDateTime,
val stuNum: String
val stuNum: String,
val likeCount: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.dotori.v2.domain.music.presentation.developer

import com.dotori.v2.domain.music.presentation.data.req.ApplyMusicReqDto
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicLikeCountResDto
import com.dotori.v2.domain.music.service.ApplyMusicService
import com.dotori.v2.domain.music.service.DeleteMusicService
import com.dotori.v2.domain.music.service.FindMusicRankService
import com.dotori.v2.domain.music.service.FindMusicsService
import com.dotori.v2.domain.music.service.ToggleMusicLikeService
import org.springframework.format.annotation.DateTimeFormat
Expand All @@ -20,7 +22,8 @@ class DeveloperMusicController(
private val applyMusicService: ApplyMusicService,
private val findMusicsService: FindMusicsService,
private val deleteMusicService: DeleteMusicService,
private val toggleMusicLikeService: ToggleMusicLikeService
private val toggleMusicLikeService: ToggleMusicLikeService,
private val findMusicRankService: FindMusicRankService
) {
@PostMapping
fun applyMusic(@RequestBody applyMusicReqDto: ApplyMusicReqDto): ResponseEntity<Void> =
Expand All @@ -42,6 +45,16 @@ class DeveloperMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

@PatchMapping("/{music_id}/like")
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<MusicLikeCountResDto> =
ResponseEntity.status(HttpStatus.OK).body(toggleMusicLikeService.execute(musicId))
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<Void> =
toggleMusicLikeService.execute(musicId)
.run { ResponseEntity.status(HttpStatus.OK).build() }

@GetMapping("/like")
fun findMusicRank(
@RequestParam(
value = "date",
required = true
) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) date: LocalDate
): ResponseEntity<MusicRankListResDto> =
ResponseEntity.status(HttpStatus.OK).body(findMusicRankService.execute(date))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.dotori.v2.domain.music.presentation.member

import com.dotori.v2.domain.music.presentation.data.req.ApplyMusicReqDto
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicLikeCountResDto
import com.dotori.v2.domain.music.service.ApplyMusicService
import com.dotori.v2.domain.music.service.DeleteMyMusicService
import com.dotori.v2.domain.music.service.FindMusicRankService
import com.dotori.v2.domain.music.service.FindMusicsService
import com.dotori.v2.domain.music.service.ToggleMusicLikeService
import org.springframework.format.annotation.DateTimeFormat
Expand All @@ -20,7 +22,8 @@ class MemberMusicController(
private val applyMusicService: ApplyMusicService,
private val findMusicsService: FindMusicsService,
private val deleteMyMusicService: DeleteMyMusicService,
private val toggleMusicLikeService: ToggleMusicLikeService
private val toggleMusicLikeService: ToggleMusicLikeService,
private val findMusicRankService: FindMusicRankService
) {
@PostMapping
fun applyMusic(@RequestBody applyMusicReqDto: ApplyMusicReqDto): ResponseEntity<Void> =
Expand All @@ -42,6 +45,16 @@ class MemberMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

@PatchMapping("/{music_id}/like")
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<MusicLikeCountResDto> =
ResponseEntity.status(HttpStatus.OK).body(toggleMusicLikeService.execute(musicId))
}
fun toggleMusicLike(@PathVariable("music_id") musicId: Long): ResponseEntity<Void> =
toggleMusicLikeService.execute(musicId)
.run { ResponseEntity.status(HttpStatus.OK).build() }

@GetMapping("/like")
fun findMusicRank(
@RequestParam(
value = "date",
required = true
) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) date: LocalDate
): ResponseEntity<MusicRankListResDto> =
ResponseEntity.status(HttpStatus.OK).body(findMusicRankService.execute(date))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.dotori.v2.domain.music.service

import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import java.time.LocalDate

interface FindMusicRankService {
fun execute(date: LocalDate): MusicRankListResDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class ApplyMusicServiceImpl(
username = music.member.memberName,
email = music.member.email,
createdTime = music.createdDate,
stuNum = music.member.stuNum
stuNum = music.member.stuNum,
likeCount = music.likeCount
)

private fun validDayOfWeek(dayOfWeek: DayOfWeek) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dotori.v2.domain.music.service.impl

import com.dotori.v2.domain.music.domain.repository.MusicRepository
import com.dotori.v2.domain.music.presentation.data.res.MusicRankListResDto
import com.dotori.v2.domain.music.presentation.data.res.MusicRankResDto
import com.dotori.v2.domain.music.service.FindMusicRankService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate

@Service
@Transactional(readOnly = true)
class FindMusicRankServiceImpl(
private val musicRepository: MusicRepository
) : FindMusicRankService {

override fun execute(date: LocalDate): MusicRankListResDto {
val responses = musicRepository.findAllByCreatedDateOrderByLikeCount(date)
.mapIndexed { index, music ->
MusicRankResDto(
id = music.id,
rank = index + 1,
url = music.url,
title = music.title,
thumbnail = music.thumbnail,
username = music.member.memberName,
email = music.member.email,
createdTime = music.createdDate,
stuNum = music.member.stuNum,
likeCount = music.likeCount
)
}

return MusicRankListResDto(
responses
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FindMusicsServiceImpl(
username = music.member.memberName,
email = music.member.email,
createdTime = music.createdDate,
stuNum = music.member.stuNum
stuNum = music.member.stuNum,
likeCount = music.likeCount
)
}

0 comments on commit 70327e2

Please sign in to comment.