-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: PermissionId 생성자 접근 제어자 수정 * refactor: BookmarkId 구현 * refactor: Bookmark 의존성 분리 (간접 참조) * refactor: 불필요한 mocking 로직 제거 * refactor: 미사용 import문 제거 * refactor: Bookmark 조회 로직 수정 (JPQL 제거) * refactor: PermissionId Null 검증 로직 추가 * refactor: BookmarkId Null 검증 로직 추가
- Loading branch information
Showing
25 changed files
with
232 additions
and
216 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
58 changes: 58 additions & 0 deletions
58
backend/src/main/java/com/mapbefine/mapbefine/bookmark/domain/BookmarkId.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,58 @@ | ||
package com.mapbefine.mapbefine.bookmark.domain; | ||
|
||
import com.mapbefine.mapbefine.bookmark.exception.BookmarkErrorCode; | ||
import com.mapbefine.mapbefine.bookmark.exception.BookmarkException.BookmarkBadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class BookmarkId implements Serializable { | ||
|
||
@Column(nullable = false, updatable = false) | ||
private Long topicId; | ||
|
||
@Column(nullable = false, updatable = false) | ||
private Long memberId; | ||
|
||
private BookmarkId(Long topicId, Long memberId) { | ||
this.topicId = topicId; | ||
this.memberId = memberId; | ||
} | ||
|
||
public static BookmarkId of(Long topicId, Long memberId) { | ||
validateNotNull(topicId, memberId); | ||
|
||
return new BookmarkId(topicId, memberId); | ||
} | ||
|
||
private static void validateNotNull(Long topicId, Long memberId) { | ||
if (Objects.isNull(topicId)) { | ||
throw new BookmarkBadRequestException(BookmarkErrorCode.ILLEGAL_TOPIC_ID); | ||
} | ||
|
||
if (Objects.isNull(memberId)) { | ||
throw new BookmarkBadRequestException(BookmarkErrorCode.ILLEGAL_MEMBER_ID); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
BookmarkId that = (BookmarkId) o; | ||
return Objects.equals(getTopicId(), that.getTopicId()) && Objects.equals(getMemberId(), that.getMemberId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getTopicId(), getMemberId()); | ||
} | ||
} |
15 changes: 9 additions & 6 deletions
15
backend/src/main/java/com/mapbefine/mapbefine/bookmark/domain/BookmarkRepository.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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.mapbefine.mapbefine.bookmark.domain; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> { | ||
import java.util.List; | ||
|
||
Optional<Bookmark> findByMemberIdAndTopicId(Long memberId, Long topicId); | ||
public interface BookmarkRepository extends JpaRepository<Bookmark, BookmarkId> { | ||
|
||
boolean existsByMemberIdAndTopicId(Long memberId, Long topicId); | ||
List<Long> findAllIdTopicIdByIdMemberId(Long memberId); | ||
|
||
@EntityGraph(attributePaths = "topic") | ||
List<Bookmark> findAllByIdMemberId(Long memberId); | ||
|
||
@Modifying(clearAutomatically = true) | ||
@Query("delete from Bookmark b where b.member.id = :memberId") | ||
@Query("delete from Bookmark b where b.id.memberId = :memberId") | ||
void deleteAllByMemberId(@Param("memberId") Long memberId); | ||
|
||
@Modifying(clearAutomatically = true) | ||
@Query("delete from Bookmark b where b.topic.id = :topicId") | ||
@Query("delete from Bookmark b where b.id.topicId = :topicId") | ||
void deleteAllByTopicId(@Param("topicId") Long topicId); | ||
|
||
} |
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.