Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add :: music like delete; #446

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading