Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bookmark bug fix #97

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

import java.time.LocalDateTime;

Expand All @@ -24,6 +25,7 @@ public class BookmarkDto {
private String thumbnailUrl;
private Short rate;
private String people;
@Nullable
private BookMarkRelLink relLinks;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.reetplace.app.dto.bookmark.response;

import com.dnd.reetplace.app.domain.bookmark.BookMarkRelLink;
import com.dnd.reetplace.app.dto.bookmark.BookmarkDto;
import com.dnd.reetplace.app.dto.member.response.MemberResponse;
import com.dnd.reetplace.app.dto.place.response.PlaceResponse;
Expand All @@ -22,11 +23,13 @@ public class BookmarkResponse {
@Schema(description = "뢁마크 ν•œ μž₯μ†Œ 정보")
private PlaceResponse place;

@Schema(description = "<p>뢁마크 μ’…λ₯˜. λͺ©λ‘μ€ λ‹€μŒκ³Ό κ°™μŒ</p>" +
"<ul>" +
"<li>WANT - 가보고 μ‹Άμ–΄μš”</li>" +
"<li>GONE - λ‹€λ…€μ™”μ–΄μš”</li>" +
"</ul>",
@Schema(description = """
<p>뢁마크 μ’…λ₯˜. λͺ©λ‘μ€ λ‹€μŒκ³Ό κ°™μŒ</p>
<ul>
<li>WANT - 가보고 μ‹Άμ–΄μš”</li>
<li>GONE - λ‹€λ…€μ™”μ–΄μš”</li>
</ul>
""",
example = "WANT")
private BookmarkType type;

Expand All @@ -49,6 +52,7 @@ public class BookmarkResponse {
private String relLink3;

public static BookmarkResponse from(BookmarkDto bookmarkDto) {
BookMarkRelLink relLinks = bookmarkDto.getRelLinks();
return new BookmarkResponse(
bookmarkDto.getId(),
MemberResponse.from(bookmarkDto.getMember()),
Expand All @@ -57,9 +61,9 @@ public static BookmarkResponse from(BookmarkDto bookmarkDto) {
bookmarkDto.getThumbnailUrl(),
bookmarkDto.getRate(),
bookmarkDto.getPeople(),
bookmarkDto.getRelLinks().getRelLink1(),
bookmarkDto.getRelLinks().getRelLink2(),
bookmarkDto.getRelLinks().getRelLink3()
relLinks != null ? relLinks.getRelLink1() : null,
relLinks != null ? relLinks.getRelLink2() : null,
relLinks != null ? relLinks.getRelLink3() : null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {

boolean existsByMember_IdAndPlace_KakaoPid(Long memberId, String kakaoPid);

Optional<Bookmark> findByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType type, Long memberId);
Optional<Bookmark> findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType type, Long memberId);

@Query("select b from Bookmark b " +
"join fetch b.place p " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private Bookmark findById(Long bookmarkId) {
}

private Bookmark getLatestBookmarkByTypeAndMemberId(BookmarkType type, Long memberId) {
return bookmarkRepository.findByTypeAndMember_IdOrderByCreatedAtDesc(type, memberId)
return bookmarkRepository.findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(type, memberId)
.orElseThrow(BookmarkNotFoundException::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ void givenMemberId_whenGettingNumOfBookmarks_thenReturnNumOfBookmarks() {
);
int numOfBookmarks = bookmarks.size();
given(bookmarkRepository.findAllByMember(memberId)).willReturn(bookmarks);
given(bookmarkRepository.findByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.WANT, memberId)).willReturn(Optional.of(createBookmark(dummyMember, dummyPlace)));
given(bookmarkRepository.findByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.DONE, memberId)).willReturn(Optional.of(createBookmark(dummyMember, dummyPlace)));
given(bookmarkRepository.findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.WANT, memberId)).willReturn(Optional.of(createBookmark(dummyMember, dummyPlace)));
given(bookmarkRepository.findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.DONE, memberId)).willReturn(Optional.of(createBookmark(dummyMember, dummyPlace)));

// when
BookmarkTypeInformationResponse bookmarkTypeInformationResponse = sut.getBookmarkTypeInformation(memberId);

// then
then(bookmarkRepository).should().findAllByMember(memberId);
then(bookmarkRepository).should().findByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.WANT, memberId);
then(bookmarkRepository).should().findByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.DONE, memberId);
then(bookmarkRepository).should().findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.WANT, memberId);
then(bookmarkRepository).should().findTop1ByTypeAndMember_IdOrderByCreatedAtDesc(BookmarkType.DONE, memberId);
then(bookmarkRepository).shouldHaveNoMoreInteractions();
assertThat(bookmarkTypeInformationResponse.getNumOfAll()).isEqualTo(numOfBookmarks);
assertThat(bookmarkTypeInformationResponse.getNumOfWant()).isEqualTo(numOfBookmarks);
Expand Down
Loading