Skip to content

Commit

Permalink
add :: music like delete;
Browse files Browse the repository at this point in the history
  • Loading branch information
esperar committed Sep 30, 2024
1 parent df4f4c1 commit 9529dc1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class SignInEmailAndPasswordServiceImpl(
)
)
return toResponse(
accessToken,
refreshToken,
accessExp,
refreshExp,
member.roles,
expiresAt
accessToken = accessToken,
refreshToken = refreshToken,
accessExp = accessExp,
refreshExp = refreshExp,
roles = member.roles,
expiresAt = expiresAt
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ interface MusicLikeRepository : JpaRepository<MusicLike,Long> {
@Query("select l from MusicLike l where l.memberId = :memberId and l.musicId = :musicId")
fun findByMemberIdAndMusicId(@Param("memberId") memberId: Long,@Param("musicId") musicId: Long): MusicLike?

fun deleteAllByMusicId(music: Long)

fun existsByMusicIdAndMemberId(musicId: Long, memberId: Long): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.dotori.v2.domain.music.service.impl

import com.dotori.v2.domain.member.enums.MusicStatus
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.exception.MusicNotFoundException
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
Expand All @@ -15,16 +16,20 @@ import org.springframework.transaction.annotation.Transactional
@Transactional(rollbackFor = [Exception::class])
class DeleteMusicServiceImpl(
private val musicRepository: MusicRepository,
private val redisCacheService: RedisCacheService
private val redisCacheService: RedisCacheService,
private val musicLikeRepository: MusicLikeRepository
) : DeleteMusicService {

override fun execute(musicId: Long) {
val music: Music = musicRepository.findByIdOrNull(musicId) ?: throw MusicNotFoundException()
val music: Music = musicRepository.findByIdOrNull(musicId)
?: throw MusicNotFoundException()

val date = music.createdDate.toLocalDate().toString()

redisCacheService.putToCacheMusic(date, MusicListResDto(mutableListOf()))
musicLikeRepository.deleteAllByMusicId(musicId)
musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dotori.v2.domain.music.service.impl
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.domain.member.enums.MusicStatus
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.exception.MusicNotFoundException
import com.dotori.v2.domain.music.exception.NotMyMusicException
Expand All @@ -19,19 +20,23 @@ import org.springframework.transaction.annotation.Transactional
class DeleteMyMusicServiceImpl(
private val musicRepository: MusicRepository,
private val userUtil: UserUtil,
private val redisCacheService: RedisCacheService
private val redisCacheService: RedisCacheService,
private val musicLikeRepository: MusicLikeRepository
) : DeleteMyMusicService {


override fun execute(musicId: Long) {
val music: Music = musicRepository.findByIdOrNull(musicId) ?: throw MusicNotFoundException()
val music: Music = musicRepository.findByIdOrNull(musicId)
?: throw MusicNotFoundException()

val member: Member = userUtil.fetchCurrentUser()

validMusic(music, member)

val date = music.createdDate.toLocalDate().toString()

redisCacheService.putToCacheMusic(date, MusicListResDto(mutableListOf()))
musicLikeRepository.deleteAllByMusicId(musicId)
musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
Expand Down

0 comments on commit 9529dc1

Please sign in to comment.