-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from Team-Ampersand/440-feat/like-function
좋아요 부분 관련 기능
- Loading branch information
Showing
21 changed files
with
325 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/dotori/v2/domain/music/domain/entity/MusicLike.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dotori.v2.domain.music.domain.entity | ||
|
||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.GenerationType | ||
import javax.persistence.Id | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "likes") | ||
class MusicLike ( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "like_id") | ||
val id: Long = 0, | ||
|
||
@Column(name = "music_id", nullable = false) | ||
val musicId: Long, | ||
|
||
@Column(name = "member_id", nullable = false) | ||
val memberId: Long, | ||
) { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/dotori/v2/domain/music/domain/repository/MusicLikeRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.dotori.v2.domain.music.domain.repository | ||
|
||
import com.dotori.v2.domain.music.domain.entity.MusicLike | ||
import io.lettuce.core.dynamic.annotation.Param | ||
import javax.persistence.LockModeType | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Lock | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface MusicLikeRepository : JpaRepository<MusicLike,Long> { | ||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
@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 existsByMusicIdAndMemberId(musicId: Long, memberId: Long): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/dotori/v2/domain/music/exception/NotValidMusicLikeException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.dotori.v2.domain.music.exception | ||
|
||
import com.dotori.v2.global.error.ErrorCode | ||
import com.dotori.v2.global.error.exception.BasicException | ||
|
||
class NotValidMusicLikeException : BasicException(ErrorCode.NOT_VALID_MUSIC_LIKE) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/dotori/v2/domain/music/presentation/data/res/MusicLikeCountResDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 MusicLikeCountResDto( | ||
val likeCount: Int | ||
) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/dotori/v2/domain/music/presentation/data/res/MusicRankListResDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/dotori/v2/domain/music/presentation/data/res/MusicRankResDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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, | ||
val memberLikeCheck: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/dotori/v2/domain/music/service/FindMusicRankService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/dotori/v2/domain/music/service/ToggleMusicLikeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.dotori.v2.domain.music.service | ||
|
||
import com.dotori.v2.domain.music.presentation.data.res.MusicLikeCountResDto | ||
|
||
interface ToggleMusicLikeService { | ||
fun execute(musicId: Long) : MusicLikeCountResDto | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/com/dotori/v2/domain/music/service/impl/FindMusicRankServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
class FindMusicRankServiceImpl( | ||
private val musicRepository: MusicRepository, | ||
private val musicLikeRepository: MusicLikeRepository, | ||
private val userUtil: UserUtil | ||
) : FindMusicRankService { | ||
|
||
override fun execute(date: LocalDate): MusicRankListResDto { | ||
val responses = musicRepository.findAllByCreatedDateOrderByLikeCountDESC(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, | ||
memberLikeCheck = checkLike(music) | ||
) | ||
} | ||
|
||
return MusicRankListResDto( | ||
responses | ||
) | ||
} | ||
|
||
private fun checkLike(music: Music): Boolean { | ||
val member = userUtil.fetchCurrentUser() | ||
|
||
return musicLikeRepository.existsByMusicIdAndMemberId(music.id, member.id) | ||
} | ||
|
||
} |
Oops, something went wrong.