diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/controller/LikeController.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/controller/FeedLikeController.kt similarity index 63% rename from src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/controller/LikeController.kt rename to src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/controller/FeedLikeController.kt index caedfcd..cf0219f 100644 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/controller/LikeController.kt +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/controller/FeedLikeController.kt @@ -1,17 +1,17 @@ -package org.tenten.bittakotlin.feedInteraction.like.controller +package org.tenten.bittakotlin.feedInteraction.feedLike.controller import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* -import org.tenten.bittakotlin.feedInteraction.like.dto.LikeDTO -import org.tenten.bittakotlin.feedInteraction.like.service.LikeService +import org.tenten.bittakotlin.feedInteraction.feedLike.dto.FeedLikeDTO +import org.tenten.bittakotlin.feedInteraction.feedLike.service.FeedLikeService @RestController @RequestMapping("/api/v1/feed/like") -class LikeController(private val likeService: LikeService) { +class FeedLikeController(private val likeService: FeedLikeService) { @PostMapping("/{feedId}") - fun toggleLike(@PathVariable feedId: Long, @RequestParam profileId: Long): ResponseEntity { + fun toggleLike(@PathVariable feedId: Long, @RequestParam profileId: Long): ResponseEntity { val likeDTO = likeService.toggleLike(feedId, profileId) return ResponseEntity.ok(likeDTO) } diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/dto/FeedLikeDTO.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/dto/FeedLikeDTO.kt new file mode 100644 index 0000000..6b70070 --- /dev/null +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/dto/FeedLikeDTO.kt @@ -0,0 +1,7 @@ +package org.tenten.bittakotlin.feedInteraction.feedLike.dto + +data class FeedLikeDTO( + val feedId: Long?, + val profileId: Long?, + val isLiked: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/entity/Like.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/entity/FeedLike.kt similarity index 73% rename from src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/entity/Like.kt rename to src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/entity/FeedLike.kt index 35581cc..e25fc79 100644 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/entity/Like.kt +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/entity/FeedLike.kt @@ -1,14 +1,10 @@ -package org.tenten.bittakotlin.feedInteraction.like.entity +package org.tenten.bittakotlin.feedInteraction.feedLike.entity import jakarta.persistence.* -import lombok.AllArgsConstructor -import lombok.Builder -import lombok.Data -import lombok.NoArgsConstructor import org.tenten.bittakotlin.feed.entity.Feed import org.tenten.bittakotlin.profile.entity.Profile -data class Like( +data class FeedLike( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null, diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/repository/LikeRepository.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/repository/FeedLikeRepository.kt similarity index 58% rename from src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/repository/LikeRepository.kt rename to src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/repository/FeedLikeRepository.kt index 723ea7a..a7a3fa6 100644 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/repository/LikeRepository.kt +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/repository/FeedLikeRepository.kt @@ -1,13 +1,13 @@ -package org.tenten.bittakotlin.feedInteraction.like.repository +package org.tenten.bittakotlin.feedInteraction.feedLike.repository import org.springframework.data.jpa.repository.JpaRepository import org.tenten.bittakotlin.feed.entity.Feed -import org.tenten.bittakotlin.feedInteraction.like.entity.Like +import org.tenten.bittakotlin.feedInteraction.feedLike.entity.FeedLike import org.tenten.bittakotlin.profile.entity.Profile import java.util.* -interface LikeRepository : JpaRepository { - fun findByFeedAndProfile(feed: Feed, profile: Profile): Optional +interface FeedLikeRepository : JpaRepository { + fun findByFeedAndProfile(feed: Feed, profile: Profile): Optional fun countByFeedAndLikedTrue(feed: Feed): Long } diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeService.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeService.kt new file mode 100644 index 0000000..15b72ce --- /dev/null +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeService.kt @@ -0,0 +1,8 @@ +package org.tenten.bittakotlin.feedInteraction.feedLike.service + +import org.tenten.bittakotlin.feedInteraction.feedLike.dto.FeedLikeDTO + +interface FeedLikeService { + fun toggleLike(feedId: Long, profileId: Long): FeedLikeDTO + fun getLikeCount(feedId: Long): Long +} diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeServiceImpl.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeServiceImpl.kt similarity index 67% rename from src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeServiceImpl.kt rename to src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeServiceImpl.kt index 508919c..fbc333e 100644 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeServiceImpl.kt +++ b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/feedLike/service/FeedLikeServiceImpl.kt @@ -1,31 +1,31 @@ -package org.tenten.bittakotlin.feedInteraction.like.service +package org.tenten.bittakotlin.feedInteraction.feedLike.service import jakarta.persistence.EntityNotFoundException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import org.tenten.bittakotlin.feed.repository.FeedRepository -import org.tenten.bittakotlin.feedInteraction.like.dto.LikeDTO -import org.tenten.bittakotlin.feedInteraction.like.entity.Like -import org.tenten.bittakotlin.feedInteraction.like.repository.LikeRepository +import org.tenten.bittakotlin.feedInteraction.feedLike.dto.FeedLikeDTO +import org.tenten.bittakotlin.feedInteraction.feedLike.entity.FeedLike +import org.tenten.bittakotlin.feedInteraction.feedLike.repository.FeedLikeRepository import org.tenten.bittakotlin.profile.repository.ProfileRepository @Service -class LikeServiceImpl( - private val likeRepository: LikeRepository, +class FeedLikeServiceImpl( + private val likeRepository: FeedLikeRepository, private val feedRepository: FeedRepository, private val profileRepository: ProfileRepository -) : LikeService { +) : FeedLikeService { @Transactional - override fun toggleLike(feedId: Long, profileId: Long): LikeDTO { + override fun toggleLike(feedId: Long, profileId: Long): FeedLikeDTO { val feed = feedRepository.findById(feedId) .orElseThrow { EntityNotFoundException("Feed not found for id: $feedId") } val profile = profileRepository.findById(profileId) .orElseThrow { EntityNotFoundException("Profile not found for id: $profileId") } val like = likeRepository.findByFeedAndProfile(feed, profile).orElseGet { - val newLike = Like(feed = feed, profile = profile, liked = true) + val newLike = FeedLike(feed = feed, profile = profile, liked = true) likeRepository.save(newLike) newLike } @@ -33,7 +33,7 @@ class LikeServiceImpl( like.liked = !like.liked likeRepository.save(like) - return LikeDTO(feed.id, profile.id, like.liked) + return FeedLikeDTO(feed.id, profile.id, like.liked) } @Transactional(readOnly = true) diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/dto/LikeDTO.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/dto/LikeDTO.kt deleted file mode 100644 index ee77b21..0000000 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/dto/LikeDTO.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.tenten.bittakotlin.feedInteraction.like.dto - -data class LikeDTO( - val feedId: Long?, - val profileId: Long?, - val isLiked: Boolean -) \ No newline at end of file diff --git a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeService.kt b/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeService.kt deleted file mode 100644 index 634fcf5..0000000 --- a/src/main/kotlin/org/tenten/bittakotlin/feedInteraction/like/service/LikeService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.tenten.bittakotlin.feedInteraction.like.service - -import org.tenten.bittakotlin.feedInteraction.like.dto.LikeDTO - -interface LikeService { - fun toggleLike(feedId: Long, profileId: Long): LikeDTO - fun getLikeCount(feedId: Long): Long -}