forked from woowacourse-teams/2024-touroot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - 좋아요 기능 구현 (woowacourse-teams#336)
* feat: 여행기 좋아요 기능 구현 * style: swagger 메시지 수정 * feat: `@Transactional` 추가 * feat: 여행기와 좋아요를 누른 사용자에 대해 unique 제약 조건 추가 * fix: 컬럼명에 id 누락된 부분 추가 * feat: 여행기 좋아요 취소 기능 구현 * feat: 액세스 토큰이 존재하는 경우, 화이트 리스트의 요청도 `JwtAuthFilter`를 거치도록 변경 * feat: 여행기 상세 조회 시 좋아요 수, 좋아요 여부도 같이 응답하도록 변경 * feat: 메인 페이지에서 여행기 조회 시 좋아요 개수도 같이 응답하도록 변경 * refactor: JwtAuthFilter 메소드 분리 * docs: Swagger 응답 description 수정 * style: 클래스 첫 빈 줄 추가 * refactor: 좋아요 취소에 대한 단어를 전체적으로 `unlike`로 통일 * test: 401 예외 확인 테스트에서 메시지도 검증도 추가 * style: `.`이 하나만 존재할 때 줄바꿈 하지 않도록 컨벤션에 맞게 수정
- Loading branch information
1 parent
af47c69
commit f418f4e
Showing
14 changed files
with
542 additions
and
15 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
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
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/kr/touroot/travelogue/domain/TravelogueLike.java
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,40 @@ | ||
package kr.touroot.travelogue.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import kr.touroot.member.domain.Member; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"TRAVELOGUE_ID", "LIKER_ID"})}) | ||
@Entity | ||
public class TravelogueLike { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@JoinColumn(name = "TRAVELOGUE_ID", nullable = false) | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
private Travelogue travelogue; | ||
|
||
@JoinColumn(name = "LIKER_ID", nullable = false) | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
private Member liker; | ||
|
||
public TravelogueLike(Travelogue travelogue, Member liker) { | ||
this(null, travelogue, liker); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/kr/touroot/travelogue/dto/response/TravelogueLikeResponse.java
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,11 @@ | ||
package kr.touroot.travelogue.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record TravelogueLikeResponse( | ||
@Schema(description = "사용자의 좋아요 여부", example = "true") | ||
Boolean isLiked, | ||
@Schema(description = "여행기의 좋아요 수", example = "10") | ||
Long likeCount | ||
) { | ||
} |
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
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/kr/touroot/travelogue/repository/TravelogueLikeRepository.java
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,15 @@ | ||
package kr.touroot.travelogue.repository; | ||
|
||
import kr.touroot.member.domain.Member; | ||
import kr.touroot.travelogue.domain.Travelogue; | ||
import kr.touroot.travelogue.domain.TravelogueLike; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TravelogueLikeRepository extends JpaRepository<TravelogueLike, Long> { | ||
|
||
Long countByTravelogue(Travelogue travelogue); | ||
|
||
boolean existsByTravelogueAndLiker(Travelogue travelogue, Member liker); | ||
|
||
void deleteByTravelogueAndLiker(Travelogue travelogue, Member liker); | ||
} |
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
Oops, something went wrong.