콘텐츠 API 추가
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package kr.co.vividnext.sodalive.content.like
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.PrePersist
|
||||
import javax.persistence.PreUpdate
|
||||
import javax.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name = "content_like")
|
||||
data class AudioContentLike(
|
||||
val memberId: Long,
|
||||
val contentId: Long
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var id: Long? = null
|
||||
|
||||
var createdAt: LocalDateTime? = null
|
||||
var updatedAt: LocalDateTime? = null
|
||||
|
||||
@PrePersist
|
||||
fun prePersist() {
|
||||
createdAt = LocalDateTime.now()
|
||||
updatedAt = LocalDateTime.now()
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
fun preUpdate() {
|
||||
updatedAt = LocalDateTime.now()
|
||||
}
|
||||
|
||||
var isActive = true
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package kr.co.vividnext.sodalive.content.like
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.content.like.QAudioContentLike.audioContentLike
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface AudioContentLikeRepository : JpaRepository<AudioContentLike, Long>, AudioContentLikeQueryRepository
|
||||
|
||||
interface AudioContentLikeQueryRepository {
|
||||
fun findByMemberIdAndContentId(memberId: Long, contentId: Long): AudioContentLike?
|
||||
fun totalCountAudioContentLike(contentId: Long): Int
|
||||
}
|
||||
|
||||
@Repository
|
||||
class AudioContentLikeQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AudioContentLikeQueryRepository {
|
||||
override fun findByMemberIdAndContentId(memberId: Long, contentId: Long): AudioContentLike? {
|
||||
return queryFactory
|
||||
.selectFrom(audioContentLike)
|
||||
.where(
|
||||
audioContentLike.memberId.eq(memberId)
|
||||
.and(audioContentLike.contentId.eq(contentId))
|
||||
)
|
||||
.fetchFirst()
|
||||
}
|
||||
|
||||
override fun totalCountAudioContentLike(contentId: Long): Int {
|
||||
return queryFactory
|
||||
.select(audioContentLike.id)
|
||||
.from(audioContentLike)
|
||||
.where(
|
||||
audioContentLike.contentId.eq(contentId)
|
||||
.and(audioContentLike.isActive.isTrue)
|
||||
)
|
||||
.fetch()
|
||||
.size
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
package kr.co.vividnext.sodalive.content.like
|
||||
|
||||
data class PutAudioContentLikeRequest(val contentId: Long)
|
@@ -0,0 +1,3 @@
|
||||
package kr.co.vividnext.sodalive.content.like
|
||||
|
||||
data class PutAudioContentLikeResponse(val like: Boolean)
|
Reference in New Issue
Block a user