Skip to content

Commit

Permalink
Merge pull request #98 from dnd-side-project/develop
Browse files Browse the repository at this point in the history
main <- develop
  • Loading branch information
HunSeongPark authored Jan 2, 2024
2 parents 1eb986f + 52e7c93 commit a09d0a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
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

0 comments on commit a09d0a0

Please sign in to comment.