-
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.
* remove: 북마크 관련 삭제 * feat: 꿀조합 댓글 작성 구현 * refactor: Comments 단방향으로 수정 * feat: 꿀조합 댓글 조회 기능 추가 * refactor: Specification private 기본생성자 추가 * refactor: 적용된 코드 SESSION ID 수정 * refactor: 생성자 정렬 수정 * refactor: 세션 쿠키 이름 SESSION 으로 수정 * refactor: 변수명 상세하게 specification 로 수정 * refactor: repeat 사용과 디버깅 출력 코드 삭제 * remove: 디버깅 출력 코드 삭제 * refactor: subList() 와 for each 사용으로 수정 * test: 꿀조합 댓글 관련 서비스 테스트 추가 * refactor: 응답 변수명 상세하게 수정 * refactor: toResponse 맞춰서 수정 * refactor: 메소드 순서에 맞게 수정 * refactor: 리뷰 반영 * refactor: 테스트 실패 수정
- Loading branch information
Showing
27 changed files
with
844 additions
and
100 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
59 changes: 59 additions & 0 deletions
59
backend/src/main/java/com/funeat/comment/domain/Comment.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,59 @@ | ||
package com.funeat.comment.domain; | ||
|
||
import com.funeat.member.domain.Member; | ||
import com.funeat.recipe.domain.Recipe; | ||
import java.time.LocalDateTime; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
@Entity | ||
public class Comment { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String comment; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "recipe_id") | ||
private Recipe recipe; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime createdAt = LocalDateTime.now(); | ||
|
||
protected Comment() { | ||
} | ||
|
||
public Comment(final Recipe recipe, final Member member, final String comment) { | ||
this.recipe = recipe; | ||
this.member = member; | ||
this.comment = comment; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getComment() { | ||
return comment; | ||
} | ||
|
||
public Member getMember() { | ||
return member; | ||
} | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/funeat/comment/persistence/CommentRepository.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,8 @@ | ||
package com.funeat.comment.persistence; | ||
|
||
import com.funeat.comment.domain.Comment; | ||
import com.funeat.common.repository.BaseRepository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long>, BaseRepository<Comment, Long> { | ||
} |
56 changes: 56 additions & 0 deletions
56
backend/src/main/java/com/funeat/comment/specification/CommentSpecification.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,56 @@ | ||
package com.funeat.comment.specification; | ||
|
||
import com.funeat.comment.domain.Comment; | ||
import com.funeat.recipe.domain.Recipe; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.persistence.criteria.JoinType; | ||
import javax.persistence.criteria.Path; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public class CommentSpecification { | ||
|
||
private CommentSpecification() { | ||
} | ||
|
||
private static final List<Class<Long>> COUNT_RESULT_TYPES = List.of(Long.class, long.class); | ||
|
||
public static Specification<Comment> findAllByRecipe(final Recipe recipe, final Long lastCommentId) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (!COUNT_RESULT_TYPES.contains(query.getResultType())) { | ||
root.fetch("member", JoinType.LEFT); | ||
} | ||
|
||
criteriaBuilder.desc(root.get("id")); | ||
|
||
return Specification | ||
.where(lessThan(lastCommentId)) | ||
.and(equalToRecipe(recipe)) | ||
.toPredicate(root, query, criteriaBuilder); | ||
}; | ||
} | ||
|
||
private static Specification<Comment> lessThan(final Long commentId) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (Objects.isNull(commentId)) { | ||
return null; | ||
} | ||
|
||
final Path<Long> commentIdPath = root.get("id"); | ||
|
||
return criteriaBuilder.lessThan(commentIdPath, commentId); | ||
}; | ||
} | ||
|
||
private static Specification<Comment> equalToRecipe(final Recipe recipe) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (Objects.isNull(recipe)) { | ||
return null; | ||
} | ||
|
||
final Path<Recipe> recipePath = root.get("recipe"); | ||
|
||
return criteriaBuilder.equal(recipePath, recipe); | ||
}; | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
backend/src/main/java/com/funeat/member/domain/bookmark/ProductBookmark.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
backend/src/main/java/com/funeat/member/domain/bookmark/RecipeBookmark.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/com/funeat/member/persistence/ProductBookmarkRepository.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/com/funeat/member/persistence/RecipeBookMarkRepository.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.