Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#301-myInfo-page
Browse files Browse the repository at this point in the history
  • Loading branch information
GC-Park authored Aug 16, 2023
2 parents f44cdac + 8ae58f2 commit 13092dc
Show file tree
Hide file tree
Showing 72 changed files with 2,082 additions and 1,149 deletions.
11 changes: 11 additions & 0 deletions backend/src/docs/asciidoc/atlas.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
== ๋ชจ์•„๋ณด๊ธฐ

=== ๋ชจ์•„๋ณด๊ธฐ์— ์ง€๋„ ์ถ”๊ฐ€ํ•˜๊ธฐ

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

=== ๋ชจ์•„๋ณด๊ธฐ์—์„œ ์ง€๋„ ์ œ๊ฑฐํ•˜๊ธฐ

operation::atlas-controller-test/remove-topic-from-atlas[snippets='http-request,http-response']


4 changes: 1 addition & 3 deletions backend/src/docs/asciidoc/bookmark.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

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

=== ์œ ์ €์˜ ํ† ํ”ฝ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ์กฐํšŒ

operation::bookmark-controller-test/find-topics-in-bookmark[snippets='http-request,http-response']
=== ์œ ์ €์˜ ํ† ํ”ฝ ์ฆ๊ฒจ์ฐพ๊ธฐ ์‚ญ์ œ

=== ์œ ์ €์˜ ํ† ํ”ฝ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋‹จ์ผ ์‚ญ์ œ
operation::bookmark-controller-test/delete-topic-in-bookmark[snippets='http-request,http-response']
1 change: 1 addition & 0 deletions backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ toc::[]

include::topic.adoc[]
include::pin.adoc[]
include::atlas.adoc[]
include::member.adoc[]
include::permission.adoc[]
include::oauth.adoc[]
Expand Down
16 changes: 12 additions & 4 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ 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-pins-by-member[snippets='http-request,http-response']
operation::member-controller-test/find-my-all-topics[snippets='http-request,http-response']

=== ์œ ์ €๊ฐ€ ๋งŒ๋“  ํ† ํ”ฝ ์กฐํšŒ
=== ์œ ์ €์˜ ๋‚˜์˜ ํ•€ ๋ชฉ๋ก ์กฐํšŒ

operation::member-controller-test/find-topics-by-member[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']
4 changes: 4 additions & 0 deletions backend/src/docs/asciidoc/pin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ operation::pin-controller-test/find-all[snippets='http-request,http-response']

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

=== ๋ฉค๋ฒ„๋ณ„ ํ•€ ๋ชฉ๋ก ์กฐํšŒ

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

=== ํ•€ ์ƒ์„ฑ

operation::pin-controller-test/add[snippets='http-request,http-response']
Expand Down
14 changes: 14 additions & 0 deletions backend/src/docs/asciidoc/topic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ operation::topic-controller-test/find-all[snippets='http-request,http-response']

operation::location-controller-test/find-nearby-topics-sorted-by-pin-count[snippets='http-request,http-response']

=== ๋ฉค๋ฒ„๋ณ„ ํ† ํ”ฝ ๋ชฉ๋ก ์กฐํšŒ

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

=== ํ† ํ”ฝ ์ƒ์„ธ ์กฐํšŒ

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 All @@ -20,10 +27,17 @@ operation::topic-controller-test/create[snippets='http-request,http-response']

operation::topic-controller-test/merge-and-create[snippets='http-request,http-response']

== ํ† ํ”ฝ์— ํ•€ ์ถ”๊ฐ€
operation::topic-controller-test/copy-pin[snippets='http-request,http-response']

=== ํ† ํ”ฝ ์ˆ˜์ •

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

=== ํ† ํ”ฝ ์‚ญ์ œ

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

=== ์ธ๊ธฐ ๊ธ‰์ƒ์Šน ํ† ํ”ฝ ์กฐํšŒ

operation::topic-controller-test/find-all-best-topics[snippets='http-request,http-response']
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.mapbefine.mapbefine.atlas.application;

import com.mapbefine.mapbefine.atlas.domain.Atlas;
import com.mapbefine.mapbefine.atlas.domain.AtlasRepository;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberRepository;
import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.domain.TopicRepository;
import java.util.NoSuchElementException;
import java.util.Objects;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AtlasCommandService {

private final TopicRepository topicRepository;
private final MemberRepository memberRepository;
private final AtlasRepository atlasRepository;

public AtlasCommandService(
TopicRepository topicRepository,
MemberRepository memberRepository,
AtlasRepository atlasRepository
) {
this.topicRepository = topicRepository;
this.memberRepository = memberRepository;
this.atlasRepository = atlasRepository;
}

public void addTopic(AuthMember authMember, Long topicId) {
Long memberId = authMember.getMemberId();

if (Objects.isNull(memberId) || Objects.isNull(topicId)) {
throw new IllegalArgumentException("์ž˜๋ชป๋œ ID๊ฐ€ ์ž…๋ ฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

if (isTopicAlreadyAdded(topicId, memberId)) {
return;
}

Topic topic = findTopicById(topicId);
validateReadPermission(authMember, topic);

Member member = findMemberById(memberId);

Atlas atlas = Atlas.createWithAssociatedMember(topic, member);
atlasRepository.save(atlas);
}

private boolean isTopicAlreadyAdded(Long topicId, Long memberId) {
return atlasRepository.existsByMemberIdAndTopicId(memberId, topicId);
}

private Topic findTopicById(Long topicId) {
return topicRepository.findById(topicId)
.orElseThrow(NoSuchElementException::new);
}

private void validateReadPermission(AuthMember authMember, Topic topic) {
if (authMember.canRead(topic)) {
return;
}
throw new IllegalArgumentException("ํ•ด๋‹น ์ง€๋„์— ์ ‘๊ทผ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.");
}

private Member findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(NoSuchElementException::new);
}

public void removeTopic(AuthMember authMember, Long topicId) {
atlasRepository.deleteByMemberIdAndTopicId(authMember.getMemberId(), topicId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mapbefine.mapbefine.atlas.domain;

import static lombok.AccessLevel.PROTECTED;

import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.topic.domain.Topic;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = PROTECTED)
@Getter
public class Atlas {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "topic_id", nullable = false)
private Topic topic;

@ManyToOne
@JoinColumn(name = "member_id", nullable = false)
private Member member;

private Atlas(Topic topic, Member member) {
this.topic = topic;
this.member = member;
}

public static Atlas createWithAssociatedMember(Topic topic, Member member) {
validateNotNull(topic, member);
Atlas atlas = new Atlas(topic, member);

member.addAtlas(atlas);

return atlas;
}

private static void validateNotNull(Topic topic, Member member) {
if (Objects.isNull(topic) || Objects.isNull(member)) {
throw new IllegalArgumentException("์ง€๋„์™€ ์œ ์ €๋Š” Null์ด์–ด์„  ์•ˆ๋ฉ๋‹ˆ๋‹ค.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbefine.mapbefine.atlas.domain;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AtlasRepository extends JpaRepository<Atlas, Long> {

boolean existsByMemberIdAndTopicId(Long memberId, Long topicId);

void deleteByMemberIdAndTopicId(Long memberId, Long topicId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mapbefine.mapbefine.atlas.presentation;

import com.mapbefine.mapbefine.atlas.application.AtlasCommandService;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.common.interceptor.LoginRequired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/atlas")
public class AtlasController {

private final AtlasCommandService atlasCommandService;

public AtlasController(AtlasCommandService atlasCommandService) {
this.atlasCommandService = atlasCommandService;
}

@LoginRequired
@PostMapping("/topics")
public ResponseEntity<Void> addTopicToAtlas(AuthMember authMember, @RequestParam Long id) {
atlasCommandService.addTopic(authMember, id);

return ResponseEntity.status(HttpStatus.CREATED).build();
}

@LoginRequired
@DeleteMapping("/topics")
public ResponseEntity<Void> removeTopicFromAtlas(AuthMember authMember, @RequestParam Long id) {
atlasCommandService.removeTopic(authMember, id);

return ResponseEntity.noContent().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ private boolean isBearerType(String value) {
}

private String extractAuthHeaderValue(String value) {
String authHeaderValue = value.substring(BEARER_TYPE.length()).trim();

return authHeaderValue;
return value.substring(BEARER_TYPE.length()).trim();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@Transactional
public class BookmarkCommandService {

private final BookmarkRepository bookmarkRepository;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -34,8 +35,8 @@ private Bookmark(Topic topic, Member member) {
this.member = member;
}

// TODO: 2023/08/11 ํ•„์š”ํ•œ ๊ฒ€์ฆ์ด ๋ฌด์—‡์ด ์žˆ์„๊นŒ.. ํ˜„์žฌ๋กœ์ฌ ์™ธ๋ถ€์—์„œ ๊ฒ€์ฆํ•˜๋Š” ๋ฐฉ๋ฒ• ๋ฐ–์— ?
public static Bookmark createWithAssociatedTopicAndMember(Topic topic, Member member) {
validateNotNull(topic, member);
Bookmark bookmark = new Bookmark(topic, member);

topic.addBookmark(bookmark);
Expand All @@ -44,4 +45,10 @@ public static Bookmark createWithAssociatedTopicAndMember(Topic topic, Member me
return bookmark;
}

private static void validateNotNull(Topic topic, Member member) {
if (Objects.isNull(topic) || Objects.isNull(member)) {
throw new IllegalArgumentException("์ง€๋„์™€ ์œ ์ €๋Š” Null์ด์–ด์„  ์•ˆ๋ฉ๋‹ˆ๋‹ค.");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.mapbefine.mapbefine.bookmark.domain;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {

List<Bookmark> findAllByMemberId(Long memberId);
boolean existsByMemberIdAndTopicId(Long memberId, Long topicId);

void deleteAllByMemberId(Long memberId);

boolean existsByMemberIdAndTopicId(Long memberId, Long topicId);

void deleteByMemberIdAndTopicId(Long memberId, Long topicId);
}
Loading

0 comments on commit 13092dc

Please sign in to comment.