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

[BE] feature/#251 최신 지도 조회 API 구현 #258

Merged
merged 29 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e9d7017
feat: 모아보기 기능 구현
junpakPark Aug 9, 2023
1de1b01
refactor: controller 필드 final 추가
junpakPark Aug 10, 2023
62ba5f1
refactor: URI 및 메서드 네이밍 변경
junpakPark Aug 10, 2023
10df876
test: atlas 테스트 추가
junpakPark Aug 10, 2023
53ec9b4
test: 테스트 코드 리팩터링
junpakPark Aug 10, 2023
8af79ae
feat: 최신 토픽 조회 기능 구현
junpakPark Aug 10, 2023
b075d3a
test: 테스트 추가 및 리팩터링
junpakPark Aug 10, 2023
b6e45e7
test: 테스트 코드 로직 오류 수정
junpakPark Aug 10, 2023
fd65611
Merge branch 'feature/atlas' into feature/#251-updatedTopic
junpakPark Aug 10, 2023
fe0225a
refactor: null값 validate 추가 및 개행 추가
junpakPark Aug 11, 2023
e8ac42a
test: 개행 및 DisplayName 수정
junpakPark Aug 11, 2023
8167a2c
test: 개행 및 DisplayName 수정
junpakPark Aug 11, 2023
573fc31
docs: restDocs snippets 추가
junpakPark Aug 11, 2023
4faba89
refactor: 메서드 순서 변경
junpakPark Aug 13, 2023
d4429bb
feat: Response에 isInAtlas 추가
junpakPark Aug 13, 2023
9905b19
refactor: convert 로직 간소화
junpakPark Aug 13, 2023
14296c4
refactor: 메서드 분리 및 정리
junpakPark Aug 14, 2023
1ef8041
chore: git conflict 해결
junpakPark Aug 14, 2023
f8b18d3
doc: restDocs 적용
junpakPark Aug 14, 2023
e530d4d
chore: git conflict 해결
junpakPark Aug 14, 2023
a7f1392
refactor: 메서드 네이밍 수정
junpakPark Aug 14, 2023
88ff4e6
refactor: git conflict 해결 및 Atlas 및 Bookmark 관련 조회 기능 MemberQueryServ…
junpakPark Aug 14, 2023
0c2d500
refactor: MemberController 내 토픽 및 핀 조회 메서드 분리
junpakPark Aug 14, 2023
e84a463
chore: git Conflict 해결
junpakPark Aug 16, 2023
8b479c3
refactor: 코드 리뷰 반영
junpakPark Aug 16, 2023
4d87239
refactor: 코드 리뷰 반영
junpakPark Aug 16, 2023
5e216db
refactor: DTO에 작성자 이름 추가
junpakPark Aug 16, 2023
7c45b11
Merge branch 'develop' into feature/#251-updatedTopic
junpakPark Aug 16, 2023
9c98f8a
chore: git conflict 해결
junpakPark Aug 16, 2023
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
4 changes: 3 additions & 1 deletion backend/src/docs/asciidoc/bookmark.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

operation::bookmark-controller-test/add-topic-in-bookmark[snippets='http-request,http-response']

=== 유저의 토픽 즐겨찾기 단일 삭제

=== 유저의 토픽 즐겨찾기 삭제

operation::bookmark-controller-test/delete-topic-in-bookmark[snippets='http-request,http-response']
11 changes: 9 additions & 2 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ operation::member-controller-test/find-all-member[snippets='http-request,http-re

operation::member-controller-test/find-member-by-id[snippets='http-request,http-response']


=== 유저의 나의 지도 목록 조회

operation::member-controller-test/find-my-all-topics[snippets='http-request,http-response']

=== 유저의 나의 핀 목록 조회

operation::member-controller-test/find-my-all-pins[snippets='http-request,http-response']

=== 유저의 모아보기 조회

operation::member-controller-test/find-all-topics-in-atlas[snippets='http-request,http-response']

=== 유저의 즐겨찾기 조회

operation::member-controller-test/find-all-topics-in-bookmark[snippets='http-request,http-response']
3 changes: 3 additions & 0 deletions backend/src/docs/asciidoc/topic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ operation::topic-controller-test/find-all-topics-by-member-id[snippets='http-req

operation::topic-controller-test/find-by-id[snippets='http-request,http-response']

=== 최신 토픽 목록 조회
operation::topic-controller-test/find-all-by-order-by-updated-at-desc[snippets='http-request,http-response']

=== 토픽 생성

operation::topic-controller-test/create[snippets='http-request,http-response']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mapbefine.mapbefine.member.domain.MemberRepository;
import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse;
import com.mapbefine.mapbefine.member.dto.response.MemberResponse;
import com.mapbefine.mapbefine.pin.dto.response.PinResponse;

import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse;
import java.util.List;
Expand Down Expand Up @@ -84,8 +86,8 @@ public List<TopicResponse> findAllTopicsInAtlas(AuthMember authMember) {
return topicsInAtlas.stream()
.map(topic -> TopicResponse.from(
topic,
isBookMarked(bookMarkedTopics, topic),
true
true,
isBookMarked(bookMarkedTopics, topic)
))
.toList();
}
Expand All @@ -94,4 +96,30 @@ private boolean isBookMarked(List<Topic> bookMarkedTopics, Topic topic) {
return bookMarkedTopics.contains(topic);
}

public List<TopicResponse> findMyAllTopics(AuthMember authMember) {

Member member = findMemberById(authMember.getMemberId());

List<Topic> bookMarkedTopics = findBookMarkedTopics(member);
List<Topic> topicsInAtlas = findTopicsInAtlas(member);

return member.getCreatedTopics()
.stream()
.map(topic -> TopicResponse.from(
topic,
isInAtlas(topicsInAtlas, topic),
isBookMarked(bookMarkedTopics, topic)
))
.toList();
}

public List<PinResponse> findMyAllPins(AuthMember authMember) {
Member member = findMemberById(authMember.getMemberId());

return member.getCreatedPins()
.stream()
.map(PinResponse::from)
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mapbefine.mapbefine.member.application.MemberQueryService;
import com.mapbefine.mapbefine.member.dto.response.MemberDetailResponse;
import com.mapbefine.mapbefine.member.dto.response.MemberResponse;
import com.mapbefine.mapbefine.pin.dto.response.PinResponse;
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse;
import java.util.List;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -40,15 +41,32 @@ public ResponseEntity<MemberDetailResponse> findMemberById(@PathVariable Long me
}

@LoginRequired
@GetMapping("/atlas")
@GetMapping("/my/topics")
public ResponseEntity<List<TopicResponse>> findMyAllTopics(AuthMember authMember) {
List<TopicResponse> responses = memberQueryService.findMyAllTopics(authMember);

return ResponseEntity.ok(responses);
}

@LoginRequired
@GetMapping("/my/pins")
public ResponseEntity<List<PinResponse>> findMyAllPins(AuthMember authMember) {
List<PinResponse> pinResponses = memberQueryService.findMyAllPins(authMember);

return ResponseEntity.ok(pinResponses);
}

@LoginRequired
@GetMapping("/my/atlas")
public ResponseEntity<List<TopicResponse>> findAllTopicsInAtlas(AuthMember authMember) {
List<TopicResponse> responses = memberQueryService.findAllTopicsInAtlas(authMember);

return ResponseEntity.ok(responses);
}

@LoginRequired
@GetMapping("/bookmarks")
@GetMapping("/my/bookmarks")

public ResponseEntity<List<TopicResponse>> findAllTopicsInBookmark(AuthMember authMember) {
List<TopicResponse> responses = memberQueryService.findAllTopicsInBookmark(authMember);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface PinRepository extends JpaRepository<Pin, Long> {

List<Pin> findByCreatorId(Long creatorId);

List<Pin> findAllByOrderByUpdatedAtDesc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public record PinDetailResponse(
String name,
String address,
String description,
String creator,
double latitude,
double longitude,
LocalDateTime updatedAt,
Expand All @@ -24,6 +25,7 @@ public static PinDetailResponse from(Pin pin) {
pinInfo.getName(),
pin.getRoadBaseAddress(),
pinInfo.getDescription(),
pin.getCreator().getMemberInfo().getNickName(),
pin.getLatitude(),
pin.getLongitude(),
pin.getUpdatedAt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record PinResponse(
String name,
String address,
String description,
String creator,
double latitude,
double longitude
) {
Expand All @@ -20,6 +21,7 @@ public static PinResponse from(Pin pin) {
pinInfo.getName(),
pin.getRoadBaseAddress(),
pinInfo.getDescription(),
pin.getCreator().getMemberInfo().getNickName(),
pin.getLatitude(),
pin.getLongitude()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -79,10 +80,11 @@ public ResponseEntity<List<PinResponse>> findAll(AuthMember member) {
return ResponseEntity.ok(allResponses);
}

@GetMapping("/members/{memberId}")
@GetMapping("/members")
public ResponseEntity<List<PinResponse>> findAllPinsByMemberId(
AuthMember authMember,
@PathVariable Long memberId
@RequestParam("id") Long memberId

) {
List<PinResponse> responses = pinQueryService.findAllPinsByMemberId(authMember, memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.mapbefine.mapbefine.bookmark.domain.Bookmark;
import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberRepository;
import com.mapbefine.mapbefine.pin.domain.Pin;
import com.mapbefine.mapbefine.pin.domain.PinRepository;

import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.domain.TopicRepository;
import com.mapbefine.mapbefine.topic.dto.response.TopicDetailResponse;
Expand All @@ -20,10 +23,17 @@
public class TopicQueryService {

private final TopicRepository topicRepository;
private final PinRepository pinRepository;
private final MemberRepository memberRepository;

public TopicQueryService(TopicRepository topicRepository, MemberRepository memberRepository) {
public TopicQueryService(
TopicRepository topicRepository,
PinRepository pinRepository,
MemberRepository memberRepository
) {
this.topicRepository = topicRepository;
this.pinRepository = pinRepository;

this.memberRepository = memberRepository;
}

Expand Down Expand Up @@ -106,6 +116,7 @@ public TopicDetailResponse findDetailById(AuthMember authMember, Long topicId) {
);
}


private Topic findTopic(Long id) {
return topicRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("해당하는 Topic이 존재하지 않습니다."));
Expand All @@ -126,6 +137,7 @@ public List<TopicDetailResponse> findDetailsByIds(AuthMember authMember, List<Lo
validateTopicsCount(ids, topics);
validateReadableTopics(authMember, topics);


if (Objects.isNull(authMember.getMemberId())) {
return getGuestTopicDetailResponses(topics);
}
Expand Down Expand Up @@ -191,8 +203,28 @@ public List<TopicResponse> findAllTopicsByMemberId(AuthMember authMember, Long m
.map(topic -> TopicResponse.from(
topic,
isInAtlas(topicsInAtlas, topic),
isBookMarked(topicsInBookMark, topic))
).toList();
isBookMarked(topicsInBookMark, topic)
)).
toList();

}

public List<TopicResponse> findAllByOrderByUpdatedAtDesc(AuthMember authMember) {
Member member = findMemberById(authMember.getMemberId());

List<Topic> topicsInAtlas = findTopicsInAtlas(member);
List<Topic> topicsInBookMark = findBookMarkedTopics(member);

return pinRepository.findAllByOrderByUpdatedAtDesc()
.stream()
.map(Pin::getTopic)
.distinct()
.filter(authMember::canRead)
.map(topic -> TopicResponse.from(
topic,
isInAtlas(topicsInAtlas, topic),
isBookMarked(topicsInBookMark, topic)
)).
toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mapbefine.mapbefine.topic.domain;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -21,36 +20,4 @@ public interface TopicRepository extends JpaRepository<Topic, Long> {

List<Topic> findByCreatorId(Long creatorId);

@Query("select new com.mapbefine.mapbefine.topic.domain.TopicWithBookmarkStatus("
+ "t, case when b.id is not null then true else false end"
+ ") "
+ "from Topic t "
+ "left join t.bookmarks b on b.member.id = :memberId")
List<TopicWithBookmarkStatus> findAllWithBookmarkStatusByMemberId(
@Param("memberId") Long memberId);


@Query("select new com.mapbefine.mapbefine.topic.domain.TopicWithBookmarkStatus("
+ "t, case when b.id is not null then true else false end"
+ ") "
+ "from Topic t "
+ "left join t.bookmarks b on t.id = :topicId AND b.member.id = :memberId "
+ "where t.id = :topicId")
Optional<TopicWithBookmarkStatus> findWithBookmarkStatusByIdAndMemberId(
@Param("topicId") Long topicId,
@Param("memberId") Long memberId
);

@Query("select new com.mapbefine.mapbefine.topic.domain.TopicWithBookmarkStatus("
+ "t, case when b.id is not null then true else false end"
+ " )"
+ "from Topic t "
+ "left join t.bookmarks b on b.member.id = :memberId "
+ "where t.id in :topicIds"
)
List<TopicWithBookmarkStatus> findWithBookmarkStatusByIdsAndMemberId(
@Param("topicIds") List<Long> topicIds,
@Param("memberId") Long memberId
);

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record TopicDetailResponse(
String name,
String description,
String image,
String creator,
Integer pinCount,
Boolean isInAtlas,
Integer bookmarkCount,
Expand All @@ -30,6 +31,7 @@ public static TopicDetailResponse from(Topic topic, Boolean isInAtlas, Boolean i
topicInfo.getName(),
topicInfo.getDescription(),
topicInfo.getImageUrl(),
topic.getCreator().getMemberInfo().getNickName(),
topic.countPins(),
isInAtlas,
topic.countBookmarks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record TopicResponse(
Long id,
String name,
String image,
String creator,
Integer pinCount,
Boolean isInAtlas,
Integer bookmarkCount,
Expand All @@ -21,6 +22,7 @@ public static TopicResponse from(Topic topic, Boolean isInAtlas, Boolean isBookm
topic.getId(),
topicInfo.getName(),
topicInfo.getImageUrl(),
topic.getCreator().getMemberInfo().getNickName(),
topic.countPins(),
isInAtlas,
topic.countBookmarks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,31 @@ public ResponseEntity<TopicDetailResponse> findById(
@GetMapping("/ids")
public ResponseEntity<List<TopicDetailResponse>> findByIds(
AuthMember member,
@RequestParam(value = "ids") List<Long> topicIds
@RequestParam("ids") List<Long> topicIds
) {
List<TopicDetailResponse> responses = topicQueryService.findDetailsByIds(member, topicIds);

return ResponseEntity.ok(responses);
}

@GetMapping("/members/{memberId}")
@GetMapping("/members")
public ResponseEntity<List<TopicResponse>> findAllTopicsByMemberId(
AuthMember authMember,
@PathVariable Long memberId
@RequestParam("id") Long memberId

) {
List<TopicResponse> responses = topicQueryService.findAllTopicsByMemberId(authMember, memberId);

return ResponseEntity.ok(responses);
}

@GetMapping("/newest")
public ResponseEntity<List<TopicResponse>> findAllByOrderByUpdatedAtDesc(AuthMember member) {
List<TopicResponse> responses = topicQueryService.findAllByOrderByUpdatedAtDesc(member);

return ResponseEntity.ok(responses);
}

@LoginRequired
@PutMapping("/{topicId}")
public ResponseEntity<Void> update(
Expand Down
Loading