-
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.
Merge branch 'develop' into feature/#301-myInfo-page
- Loading branch information
Showing
72 changed files
with
2,082 additions
and
1,149 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
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'] | ||
|
||
|
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
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
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
78 changes: 78 additions & 0 deletions
78
backend/src/main/java/com/mapbefine/mapbefine/atlas/application/AtlasCommandService.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,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); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
backend/src/main/java/com/mapbefine/mapbefine/atlas/domain/Atlas.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,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์ด์ด์ ์๋ฉ๋๋ค."); | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/mapbefine/mapbefine/atlas/domain/AtlasRepository.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,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); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/com/mapbefine/mapbefine/atlas/presentation/AtlasController.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,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(); | ||
} | ||
|
||
} |
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
37 changes: 0 additions & 37 deletions
37
backend/src/main/java/com/mapbefine/mapbefine/bookmark/application/BookmarkQueryService.java
This file was deleted.
Oops, something went wrong.
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
5 changes: 1 addition & 4 deletions
5
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,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); | ||
} |
Oops, something went wrong.