Skip to content

Commit

Permalink
Refactor: 클래스네임 변경
Browse files Browse the repository at this point in the history
bean 충돌이 생겨서 클래스 이름을 좀 변경 했습니다
  • Loading branch information
Preta3418 committed Nov 5, 2024
1 parent 25f4114 commit d33c17b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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<LikeDTO> {
fun toggleLike(@PathVariable feedId: Long, @RequestParam profileId: Long): ResponseEntity<FeedLikeDTO> {
val likeDTO = likeService.toggleLike(feedId, profileId)
return ResponseEntity.ok(likeDTO)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.tenten.bittakotlin.feedInteraction.feedLike.dto

data class FeedLikeDTO(
val feedId: Long?,
val profileId: Long?,
val isLiked: Boolean
)
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Like, Long> {
fun findByFeedAndProfile(feed: Feed, profile: Profile): Optional<Like>
interface FeedLikeRepository : JpaRepository<FeedLike, Long> {
fun findByFeedAndProfile(feed: Feed, profile: Profile): Optional<FeedLike>
fun countByFeedAndLikedTrue(feed: Feed): Long
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
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
}

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)
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit d33c17b

Please sign in to comment.