Skip to content

Commit

Permalink
Merge pull request #432 from Team-Ampersand/431-add-music-like-check
Browse files Browse the repository at this point in the history
Music 조회할 때 좋아요 유무 반환
  • Loading branch information
ta2ye0n authored Sep 19, 2024
2 parents 70327e2 + 7015786 commit 4c2220f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class AdminMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

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

@GetMapping("/like")
fun findMusicRank(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class CouncillorMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

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

@GetMapping("/like")
fun findMusicRank(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class MusicRankResDto(
val email: String,
val createdTime: LocalDateTime,
val stuNum: String,
val likeCount: Int
val likeCount: Int,
val memberLikeCheck: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class DeveloperMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

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

@GetMapping("/like")
fun findMusicRank(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class MemberMusicController(
.run { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

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

@GetMapping("/like")
fun findMusicRank(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.dotori.v2.domain.music.service.impl

import com.dotori.v2.domain.music.domain.entity.Music
import com.dotori.v2.domain.music.domain.repository.MusicLikeRepository
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 com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate

@Service
@Transactional(readOnly = true)
@Transactional
class FindMusicRankServiceImpl(
private val musicRepository: MusicRepository
private val musicRepository: MusicRepository,
private val musicLikeRepository: MusicLikeRepository,
private val userUtil: UserUtil
) : FindMusicRankService {

override fun execute(date: LocalDate): MusicRankListResDto {
Expand All @@ -27,7 +32,8 @@ class FindMusicRankServiceImpl(
email = music.member.email,
createdTime = music.createdDate,
stuNum = music.member.stuNum,
likeCount = music.likeCount
likeCount = music.likeCount,
memberLikeCheck = checkLike(music)
)
}

Expand All @@ -36,4 +42,10 @@ class FindMusicRankServiceImpl(
)
}

private fun checkLike(music: Music): Boolean {
val member = userUtil.fetchCurrentUser()

return musicLikeRepository.findByMemberIdAndMusicId(member.id, music.id) != null
}

}

0 comments on commit 4c2220f

Please sign in to comment.