diff --git a/src/main/java/com/mallang/category/TieredCategory.java b/src/main/java/com/mallang/category/TieredCategory.java index 6e6b8d51..a2882e83 100644 --- a/src/main/java/com/mallang/category/TieredCategory.java +++ b/src/main/java/com/mallang/category/TieredCategory.java @@ -128,7 +128,7 @@ private void validateNoChildrenInParent(T parent) { if (equals(root) && root.getPreviousSibling() == null && root.getNextSibling() == null) { return; } - throw new CategoryHierarchyViolationException("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + throw new CategoryHierarchyViolationException("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); } else { if (!parent.getChildren().isEmpty()) { throw new CategoryHierarchyViolationException("주어진 부모의 자식 카테고리와의 관계가 명시되지 않았습니다."); diff --git a/src/main/java/com/mallang/reference/application/ReferenceLinkService.java b/src/main/java/com/mallang/reference/application/ReferenceLinkService.java index f2b945c4..593b7966 100644 --- a/src/main/java/com/mallang/reference/application/ReferenceLinkService.java +++ b/src/main/java/com/mallang/reference/application/ReferenceLinkService.java @@ -2,8 +2,6 @@ import com.mallang.auth.domain.Member; import com.mallang.auth.domain.MemberRepository; -import com.mallang.blog.domain.Blog; -import com.mallang.blog.domain.BlogRepository; import com.mallang.reference.application.command.SaveReferenceLinkCommand; import com.mallang.reference.application.command.UpdateReferenceLinkCommand; import com.mallang.reference.domain.ReferenceLink; @@ -17,14 +15,12 @@ @Service public class ReferenceLinkService { - private final BlogRepository blogRepository; private final MemberRepository memberRepository; private final ReferenceLinkRepository referenceLinkRepository; public Long save(SaveReferenceLinkCommand command) { - Blog blog = blogRepository.getByName(command.blogName()); Member member = memberRepository.getById(command.memberId()); - ReferenceLink referenceLink = command.toReferenceLink(member, blog); + ReferenceLink referenceLink = command.toReferenceLink(member); return referenceLinkRepository.save(referenceLink).getId(); } diff --git a/src/main/java/com/mallang/reference/application/command/SaveReferenceLinkCommand.java b/src/main/java/com/mallang/reference/application/command/SaveReferenceLinkCommand.java index f452216f..c2aac5bc 100644 --- a/src/main/java/com/mallang/reference/application/command/SaveReferenceLinkCommand.java +++ b/src/main/java/com/mallang/reference/application/command/SaveReferenceLinkCommand.java @@ -1,18 +1,16 @@ package com.mallang.reference.application.command; import com.mallang.auth.domain.Member; -import com.mallang.blog.domain.Blog; import com.mallang.reference.domain.ReferenceLink; import jakarta.annotation.Nullable; public record SaveReferenceLinkCommand( Long memberId, - String blogName, String url, String title, @Nullable String memo ) { - public ReferenceLink toReferenceLink(Member member, Blog blog) { - return new ReferenceLink(url, title, memo, member, blog); + public ReferenceLink toReferenceLink(Member member) { + return new ReferenceLink(url, title, memo, member); } } diff --git a/src/main/java/com/mallang/reference/domain/ReferenceLink.java b/src/main/java/com/mallang/reference/domain/ReferenceLink.java index c2df6bc5..6839c519 100644 --- a/src/main/java/com/mallang/reference/domain/ReferenceLink.java +++ b/src/main/java/com/mallang/reference/domain/ReferenceLink.java @@ -5,7 +5,6 @@ import static lombok.AccessLevel.PROTECTED; import com.mallang.auth.domain.Member; -import com.mallang.blog.domain.Blog; import com.mallang.common.domain.CommonRootEntity; import com.mallang.reference.exception.NoAuthorityReferenceLinkException; import jakarta.persistence.Embedded; @@ -39,17 +38,11 @@ public class ReferenceLink extends CommonRootEntity { @JoinColumn(name = "owner_id", nullable = false) private Member member; - @ManyToOne(fetch = LAZY) - @JoinColumn(name = "blog_id", nullable = false) - private Blog blog; - - public ReferenceLink(String url, String title, String memo, Member member, Blog blog) { + public ReferenceLink(String url, String title, String memo, Member member) { this.url = new ReferenceLinkUrl(url); this.title = new ReferenceLinkTitle(title); this.memo = new ReferenceLinkMemo(memo); - this.blog = blog; this.member = member; - blog.validateOwner(member); } public void update(String url, String title, String memo) { diff --git a/src/main/java/com/mallang/reference/presentation/ReferenceLinkController.java b/src/main/java/com/mallang/reference/presentation/ReferenceLinkController.java index 03dcd503..9b05a68a 100644 --- a/src/main/java/com/mallang/reference/presentation/ReferenceLinkController.java +++ b/src/main/java/com/mallang/reference/presentation/ReferenceLinkController.java @@ -42,13 +42,12 @@ public ResponseEntity fetchTitleInfo( return ResponseEntity.ok(fetchReferenceLinkTitleService.fetchTitleMetaInfo(url)); } - @PostMapping("/{blogName}") + @PostMapping public ResponseEntity save( @Auth Long memberId, - @PathVariable(name = "blogName") String blogName, @Valid @RequestBody SaveReferenceLinkRequest request ) { - SaveReferenceLinkCommand command = request.toCommand(memberId, blogName); + SaveReferenceLinkCommand command = request.toCommand(memberId); Long referenceLinkId = referenceLinkService.save(command); return ResponseEntity.created(URI.create("/reference-title/" + referenceLinkId)).build(); } @@ -73,23 +72,21 @@ public ResponseEntity delete( return ResponseEntity.noContent().build(); } - @GetMapping("/{blogName}/exists") + @GetMapping("/exists") public ResponseEntity checkExistsUrl( @Auth Long memberId, - @PathVariable("blogName") String blogName, @RequestParam("url") String url ) { - boolean isExists = referenceLinkQueryService.existsReferenceLinkByUrl(memberId, blogName, url.strip()); + boolean isExists = referenceLinkQueryService.existsReferenceLinkByUrl(memberId, url.strip()); return ResponseEntity.ok(isExists); } - @GetMapping("/{blogName}") + @GetMapping public ResponseEntity> search( @Auth Long memberId, - @PathVariable("blogName") String blogName, @ModelAttribute ReferenceLinkSearchDaoCond cond ) { - List result = referenceLinkQueryService.search(memberId, blogName, cond); + List result = referenceLinkQueryService.search(memberId, cond); return ResponseEntity.ok(result); } } diff --git a/src/main/java/com/mallang/reference/presentation/request/SaveReferenceLinkRequest.java b/src/main/java/com/mallang/reference/presentation/request/SaveReferenceLinkRequest.java index ef103c07..d65e255a 100644 --- a/src/main/java/com/mallang/reference/presentation/request/SaveReferenceLinkRequest.java +++ b/src/main/java/com/mallang/reference/presentation/request/SaveReferenceLinkRequest.java @@ -9,7 +9,7 @@ public record SaveReferenceLinkRequest( @NotBlank String title, @Nullable String memo ) { - public SaveReferenceLinkCommand toCommand(Long memberId, String blogName) { - return new SaveReferenceLinkCommand(memberId, blogName, url, title, memo); + public SaveReferenceLinkCommand toCommand(Long memberId) { + return new SaveReferenceLinkCommand(memberId, url, title, memo); } } diff --git a/src/main/java/com/mallang/reference/query/ReferenceLinkQueryService.java b/src/main/java/com/mallang/reference/query/ReferenceLinkQueryService.java index abe5dc01..62bc6271 100644 --- a/src/main/java/com/mallang/reference/query/ReferenceLinkQueryService.java +++ b/src/main/java/com/mallang/reference/query/ReferenceLinkQueryService.java @@ -2,8 +2,6 @@ import com.mallang.auth.domain.Member; import com.mallang.auth.query.repository.MemberQueryRepository; -import com.mallang.blog.domain.Blog; -import com.mallang.blog.query.repository.BlogQueryRepository; import com.mallang.reference.query.repository.ReferenceLinkQueryRepository; import com.mallang.reference.query.repository.ReferenceLinkSearchDao.ReferenceLinkSearchDaoCond; import com.mallang.reference.query.response.ReferenceLinkSearchResponse; @@ -17,21 +15,16 @@ @Service public class ReferenceLinkQueryService { - private final BlogQueryRepository blogQueryRepository; private final MemberQueryRepository memberQueryRepository; private final ReferenceLinkQueryRepository referenceLinkQueryRepository; - public boolean existsReferenceLinkByUrl(Long memberId, String blogName, String url) { - Blog blog = blogQueryRepository.getByName(blogName); + public boolean existsReferenceLinkByUrl(Long memberId, String url) { Member member = memberQueryRepository.getById(memberId); - blog.validateOwner(member); - return referenceLinkQueryRepository.existsByBlogAndUrl(blog, url); + return referenceLinkQueryRepository.existsByMemberAndUrl(member, url); } - public List search(Long memberId, String blogName, ReferenceLinkSearchDaoCond cond) { - Blog blog = blogQueryRepository.getByName(blogName); + public List search(Long memberId, ReferenceLinkSearchDaoCond cond) { Member member = memberQueryRepository.getById(memberId); - blog.validateOwner(member); - return ReferenceLinkSearchResponse.from(referenceLinkQueryRepository.search(blog, cond)); + return ReferenceLinkSearchResponse.from(referenceLinkQueryRepository.search(member, cond)); } } diff --git a/src/main/java/com/mallang/reference/query/repository/ReferenceLinkQueryRepository.java b/src/main/java/com/mallang/reference/query/repository/ReferenceLinkQueryRepository.java index b00549d1..2518a9f1 100644 --- a/src/main/java/com/mallang/reference/query/repository/ReferenceLinkQueryRepository.java +++ b/src/main/java/com/mallang/reference/query/repository/ReferenceLinkQueryRepository.java @@ -1,6 +1,6 @@ package com.mallang.reference.query.repository; -import com.mallang.blog.domain.Blog; +import com.mallang.auth.domain.Member; import com.mallang.reference.domain.ReferenceLink; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -10,6 +10,6 @@ public interface ReferenceLinkQueryRepository extends JpaRepository, ReferenceLinkSearchDao { - @Query("SELECT COUNT(rl) > 0 FROM ReferenceLink rl WHERE rl.blog = :blog AND rl.url.url = :url") - boolean existsByBlogAndUrl(@Param("blog") Blog blog, @Param("url") String url); + @Query("SELECT COUNT(rl) > 0 FROM ReferenceLink rl WHERE rl.member = :member AND rl.url.url = :url") + boolean existsByMemberAndUrl(@Param("member") Member member, @Param("url") String url); } diff --git a/src/main/java/com/mallang/reference/query/repository/ReferenceLinkSearchDao.java b/src/main/java/com/mallang/reference/query/repository/ReferenceLinkSearchDao.java index 38611f8a..fab2c230 100644 --- a/src/main/java/com/mallang/reference/query/repository/ReferenceLinkSearchDao.java +++ b/src/main/java/com/mallang/reference/query/repository/ReferenceLinkSearchDao.java @@ -2,7 +2,7 @@ import static com.mallang.reference.domain.QReferenceLink.referenceLink; -import com.mallang.blog.domain.Blog; +import com.mallang.auth.domain.Member; import com.mallang.reference.domain.ReferenceLink; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -14,7 +14,7 @@ public interface ReferenceLinkSearchDao { - List search(Blog blog, ReferenceLinkSearchDaoCond cond); + List search(Member member, ReferenceLinkSearchDaoCond cond); record ReferenceLinkSearchDaoCond( @Nullable String url, @@ -30,10 +30,10 @@ class ReferenceLinkSearchDaoImpl implements ReferenceLinkSearchDao { private final JPAQueryFactory query; @Override - public List search(Blog blog, ReferenceLinkSearchDaoCond cond) { + public List search(Member member, ReferenceLinkSearchDaoCond cond) { return query.selectFrom(referenceLink) .where( - blogEq(blog), + memberEq(member), urlContains(cond.url()), titleContains(cond.title()), memoContains(cond.memo()) @@ -42,8 +42,8 @@ public List search(Blog blog, ReferenceLinkSearchDaoCond cond) { .fetch(); } - private BooleanExpression blogEq(Blog blog) { - return referenceLink.blog.eq(blog); + private BooleanExpression memberEq(Member member) { + return referenceLink.member.eq(member); } private BooleanExpression urlContains(String url) { diff --git a/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceSteps.java index 1c269615..e63a526f 100644 --- a/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceSteps.java @@ -13,12 +13,11 @@ public class ReferenceLinkAcceptanceSteps { public static ExtractableResponse 참고_링크_저장_요청( String 세션_ID, - String 블로그_이름, SaveReferenceLinkRequest 참고_링크_저장_요청 ) { return given(세션_ID) .body(참고_링크_저장_요청) - .post("/reference-links/{blogName}", 블로그_이름) + .post("/reference-links") .then() .extract(); } @@ -47,26 +46,24 @@ public class ReferenceLinkAcceptanceSteps { public static ExtractableResponse 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( String 세션_ID, - String 블로그_이름, String URL ) { return given(세션_ID) .queryParam("url", URL) - .get("/reference-links/{blogName}/exists", 블로그_이름) + .get("/reference-links/exists") .then() .extract(); } public static ExtractableResponse 참고_링크_검색_요청( String 세션_ID, - String 블로그_이름, ReferenceLinkSearchDaoCond 검색_조건 ) { return given(세션_ID) .queryParam("url", 검색_조건.url()) .queryParam("title", 검색_조건.title()) .queryParam("memo", 검색_조건.memo()) - .get("/reference-links/{blogName}", 블로그_이름) + .get("/reference-links") .then() .extract(); } diff --git a/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceTest.java b/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceTest.java index ee8b0534..8db6fb9f 100644 --- a/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/reference/ReferenceLinkAcceptanceTest.java @@ -10,7 +10,6 @@ import static com.mallang.acceptance.AcceptanceSteps.잘못된_요청; import static com.mallang.acceptance.AcceptanceSteps.정상_처리; import static com.mallang.acceptance.auth.AuthAcceptanceSteps.회원가입과_로그인_후_세션_ID_반환; -import static com.mallang.acceptance.blog.BlogAcceptanceSteps.블로그_개설; import static com.mallang.acceptance.reference.ReferenceLinkAcceptanceSteps.URL_의_제목_추출_요청; import static com.mallang.acceptance.reference.ReferenceLinkAcceptanceSteps.주어진_URL_로_이미_등록된_링크_존재여부_확인_요청; import static com.mallang.acceptance.reference.ReferenceLinkAcceptanceSteps.참고_링크_검색_요청; @@ -54,14 +53,12 @@ public class ReferenceLinkAcceptanceTest extends AcceptanceTest { @Autowired private MockUrlTitleMetaInfoFetcher fetcher; private String 말랑_세션_ID; - private String 말랑_블로그_이름; @Override @BeforeEach protected void setUp() { super.setUp(); 말랑_세션_ID = 회원가입과_로그인_후_세션_ID_반환("말랑"); - 말랑_블로그_이름 = 블로그_개설(말랑_세션_ID, "mallang-log"); } @Nested @@ -70,22 +67,19 @@ class 참고_링크_저장_API { @Test void 참고_링크를_저장한다() { // when - var 응답 = 참고_링크_저장_요청(말랑_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청); + var 응답 = 참고_링크_저장_요청(말랑_세션_ID, 참고_링크_저장_요청); // then 응답_상태를_검증한다(응답, 생성됨); } @Test - void 자신의_블로그가_아니라면_예외() { - // given - var 다른회원_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); - + void 인증정보가_없으면_아니라면_예외() { // when - var 응답 = 참고_링크_저장_요청(다른회원_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청); + var 응답 = 참고_링크_저장_요청(null, 참고_링크_저장_요청); // then - 응답_상태를_검증한다(응답, 권한_없음); + 응답_상태를_검증한다(응답, 인증되지_않음); } } @@ -101,7 +95,7 @@ class 참고_링크_정보_업데이트_API { @Test void 참고_링크를_정보를_수정한다() { // given - var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청)); + var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 참고_링크_저장_요청)); // when var 응답 = 참고_링크_업데이트_요청(말랑_세션_ID, 참고_링크_ID, 참고_링크_업데이트_요청); @@ -114,7 +108,7 @@ class 참고_링크_정보_업데이트_API { void 자신이_등록한_링크가_아니라면_예외() { // given var 다른회원_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); - var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청)); + var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 참고_링크_저장_요청)); // when var 응답 = 참고_링크_업데이트_요청(다른회원_세션_ID, 참고_링크_ID, 참고_링크_업데이트_요청); @@ -130,7 +124,7 @@ class 참고_링크_삭제_API { @Test void 참고_링크를_저장한다() { // given - var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청)); + var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 참고_링크_저장_요청)); // when var 응답 = 참고_링크_삭제_요청(말랑_세션_ID, 참고_링크_ID); @@ -143,7 +137,7 @@ class 참고_링크_삭제_API { void 자신이_등록한_링크가_아니라면_예외() { // given var 다른회원_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); - var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 말랑_블로그_이름, 참고_링크_저장_요청)); + var 참고_링크_ID = ID를_추출한다(참고_링크_저장_요청(말랑_세션_ID, 참고_링크_저장_요청)); // when var 응답 = 참고_링크_삭제_요청(다른회원_세션_ID, 참고_링크_ID); @@ -161,7 +155,7 @@ class 주어진_URL_로_이미_등록된_링크_존재여부_확인_API { // given 참고_링크_저장_요청( 말랑_세션_ID, - 말랑_블로그_이름, + new SaveReferenceLinkRequest( "https://ttl-blog.tistory.com", "말랑이 블로그", @@ -172,22 +166,22 @@ class 주어진_URL_로_이미_등록된_링크_존재여부_확인_API { // when var exactlyMatch = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 말랑_세션_ID, - 말랑_블로그_이름, + "https://ttl-blog.tistory.com" ); var exactlyMatch2 = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 말랑_세션_ID, - 말랑_블로그_이름, + " https://ttl-blog.tistory.com " // 앞뒤 공백은 제거됨 ); var notMatch1 = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 말랑_세션_ID, - 말랑_블로그_이름, + "//ttl-blog.tistory.com" ); var notMatch2 = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 말랑_세션_ID, - 말랑_블로그_이름, + "https://ttl-blog.tistory.com/" ); @@ -199,13 +193,11 @@ class 주어진_URL_로_이미_등록된_링크_존재여부_확인_API { } @Test - void 다른_블로그에_등록된것과는_무관하다() { + void 다른_사람이_등록한것과는_무관하다() { // given var 다른_사람_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); - var 다른_사람_블로그_이름 = 블로그_개설(다른_사람_세션_ID, "other-log"); 참고_링크_저장_요청( 다른_사람_세션_ID, - 다른_사람_블로그_이름, new SaveReferenceLinkRequest( "https://ttl-blog.tistory.com", "말랑이 블로그", @@ -216,12 +208,11 @@ class 주어진_URL_로_이미_등록된_링크_존재여부_확인_API { // when var notExist = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 말랑_세션_ID, - 말랑_블로그_이름, + "https://ttl-blog.tistory.com" ); var exist = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( 다른_사람_세션_ID, - 다른_사람_블로그_이름, "https://ttl-blog.tistory.com" ); @@ -231,19 +222,17 @@ class 주어진_URL_로_이미_등록된_링크_존재여부_확인_API { } @Test - void 블로그_주인이_아니라면_예외() { + void 인증정보가_없으면_예외() { // given - var 다른_사람_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); // when var 응답 = 주어진_URL_로_이미_등록된_링크_존재여부_확인_요청( - 다른_사람_세션_ID, - 말랑_블로그_이름, + null, "https://ttl-blog.tistory.com" ); // then - 응답_상태를_검증한다(응답, 권한_없음); + 응답_상태를_검증한다(응답, 인증되지_않음); } } @@ -257,7 +246,7 @@ class 참고_링크_목록_검색_API { void setUp() { 말랑이_블로그_링크_ID = ID를_추출한다(참고_링크_저장_요청( 말랑_세션_ID, - 말랑_블로그_이름, + new SaveReferenceLinkRequest( "https://ttl-blog.tistory.com", "말랑이 블로그", @@ -266,7 +255,7 @@ void setUp() { )); Spring_글_참고_링크_ID = ID를_추출한다(참고_링크_저장_요청( 말랑_세션_ID, - 말랑_블로그_이름, + new SaveReferenceLinkRequest( "https://ttl-blog.tistory.com/123", "스프링이란?", @@ -276,12 +265,12 @@ void setUp() { } @Test - void 조건_없이_검색하면_해당_블로그의_모든_링크가_조회된다() { + void 조건_없이_검색하면_나의_모든_링크가_조회된다() { // given ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); // when - var 응답 = 참고_링크_검색_요청(말랑_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(말랑_세션_ID, emptyCond); // then List responses = 응답.as(new TypeRef<>() { @@ -290,13 +279,11 @@ void setUp() { } @Test - void 다른_블로그의_링크는_조회되지_않는다() { + void 다른_사람의_링크는_조회되지_않는다() { // given var 다른_사람_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); - var 다른_사람_블로그_이름 = 블로그_개설(다른_사람_세션_ID, "other-log"); Long 다른사람_링크_ID = ID를_추출한다(참고_링크_저장_요청( 다른_사람_세션_ID, - 다른_사람_블로그_이름, new SaveReferenceLinkRequest( "https://ttl-blog.tistory.com/13", "자바", @@ -306,7 +293,7 @@ void setUp() { ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); // when - var 응답 = 참고_링크_검색_요청(말랑_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(말랑_세션_ID, emptyCond); // then List responses = 응답.as(new TypeRef<>() { @@ -318,16 +305,15 @@ void setUp() { } @Test - void 블로그_주인이_아니면_조회할_수_없다() { + void 인증정보가_없으면_조회할_수_없다() { // given - var 다른_사람_세션_ID = 회원가입과_로그인_후_세션_ID_반환("other"); ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); // when - var 응답 = 참고_링크_검색_요청(다른_사람_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(null, emptyCond); // then - 응답_상태를_검증한다(응답, 권한_없음); + 응답_상태를_검증한다(응답, 인증되지_않음); } @Test @@ -336,7 +322,7 @@ void setUp() { ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond("12", null, null); // when - var 응답 = 참고_링크_검색_요청(말랑_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(말랑_세션_ID, emptyCond); // then List responses = 응답.as(new TypeRef<>() { @@ -352,7 +338,7 @@ void setUp() { ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, "랑이", null); // when - var 응답 = 참고_링크_검색_요청(말랑_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(말랑_세션_ID, emptyCond); // then List responses = 응답.as(new TypeRef<>() { @@ -368,7 +354,7 @@ void setUp() { ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, "스프링에"); // when - var 응답 = 참고_링크_검색_요청(말랑_세션_ID, 말랑_블로그_이름, emptyCond); + var 응답 = 참고_링크_검색_요청(말랑_세션_ID, emptyCond); // then List responses = 응답.as(new TypeRef<>() { diff --git a/src/test/java/com/mallang/category/TieredCategoryTestTemplate.java b/src/test/java/com/mallang/category/TieredCategoryTestTemplate.java index 25b95134..cbe82098 100644 --- a/src/test/java/com/mallang/category/TieredCategoryTestTemplate.java +++ b/src/test/java/com/mallang/category/TieredCategoryTestTemplate.java @@ -430,11 +430,11 @@ class 형제들이_주어지지_않았을_때 { assertThatThrownBy(() -> { target.updateHierarchy(null, null, null); }).isInstanceOf(CategoryHierarchyViolationException.class) - .hasMessage("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + .hasMessage("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); assertThatThrownBy(() -> { prev.updateHierarchy(null, null, null); }).isInstanceOf(CategoryHierarchyViolationException.class) - .hasMessage("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + .hasMessage("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); } @Test @@ -459,7 +459,7 @@ class 형제들이_주어지지_않았을_때 { assertThatThrownBy(() -> { child.updateHierarchy(null, null, null); }).isInstanceOf(CategoryHierarchyViolationException.class) - .hasMessage("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + .hasMessage("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); } @Test @@ -475,7 +475,7 @@ class 형제들이_주어지지_않았을_때 { assertThatThrownBy(() -> { child.updateHierarchy(null, null, null); }).isInstanceOf(CategoryHierarchyViolationException.class) - .hasMessage("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + .hasMessage("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); } @Test @@ -489,7 +489,7 @@ class 형제들이_주어지지_않았을_때 { assertThatThrownBy(() -> { root.updateHierarchy(null, null, null); }).isInstanceOf(CategoryHierarchyViolationException.class) - .hasMessage("블로드에 존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); + .hasMessage("존재하는 다른 최상위 카테고리와의 관계가 명시되지 않았습니다."); } @Test @@ -690,6 +690,40 @@ class 제거_시 { }).isInstanceOf(권한_없음_예외()); } + @Test + void 나를_제외한_내_형제들을_반환한다() { + // given + T 최상위 = createRoot("최상위", member); + T 하위1 = createChild("하위1", member, 최상위); + T 하위2 = createChild("하위2", member, 최상위, 하위1, null); + T 하위3 = createChild("하위3", member, 최상위, 하위2, null); + T 더하위1 = createChild("더하위1", member, 하위1); + + // when + List siblingsExceptSelf = 하위2.getSiblingsExceptSelf(); + + // then + assertThat(siblingsExceptSelf) + .containsExactly(하위1, 하위3); + } + + @Test + void 정렬된_자식들을_반환한다() { + // given + T 최상위 = createRoot("최상위", member); + T 하위1 = createChild("하위1", member, 최상위); + T 하위3 = createChild("하위3", member, 최상위, 하위1, null); + T 하위2 = createChild("하위2", member, 최상위, 하위1, 하위3); + T 더하위1 = createChild("더하위1", member, 하위1); + + // when + List 최상위_descendants = 최상위.getSortedChildren(); + + // then + assertThat(최상위_descendants) + .containsExactly(하위1, 하위2, 하위3); + } + @Test void 모든_자손을_반환한다() { // given diff --git a/src/test/java/com/mallang/reference/application/ReferenceLinkServiceTest.java b/src/test/java/com/mallang/reference/application/ReferenceLinkServiceTest.java index 7e40d074..50187ce5 100644 --- a/src/test/java/com/mallang/reference/application/ReferenceLinkServiceTest.java +++ b/src/test/java/com/mallang/reference/application/ReferenceLinkServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.mallang.blog.exception.NoAuthorityBlogException; import com.mallang.common.ServiceTest; import com.mallang.reference.application.command.SaveReferenceLinkCommand; import com.mallang.reference.application.command.UpdateReferenceLinkCommand; @@ -22,17 +21,14 @@ class ReferenceLinkServiceTest extends ServiceTest { private Long memberId; - private String blogName; private SaveReferenceLinkCommand command; @BeforeEach void setUp() { memberId = 회원을_저장한다("말랑"); - blogName = 블로그_개설(memberId, "mallang-log"); command = new SaveReferenceLinkCommand( memberId, - blogName, "https://ttl-blog.tistory.com/", "말랑이 블로그", "짱 멋있는 말랑이 블로그임" @@ -62,24 +58,6 @@ class 참조_링크_저장_시 { // then assertThat(id).isNotNull(); } - - @Test - void 블로그의_주인이_아닌_경우_예외() { - // given - Long otherMember = 회원을_저장한다("other"); - SaveReferenceLinkCommand command = new SaveReferenceLinkCommand( - otherMember, - blogName, - "https://ttl-blog.tistory.com/", - "말랑이 블로그", - "짱 멋있는 말랑이 블로그임" - ); - - // when & then - assertThatThrownBy(() -> - referenceLinkService.save(command) - ).isInstanceOf(NoAuthorityBlogException.class); - } } @Nested diff --git a/src/test/java/com/mallang/reference/domain/ReferenceLinkTest.java b/src/test/java/com/mallang/reference/domain/ReferenceLinkTest.java index c4e64fc4..0fdbec52 100644 --- a/src/test/java/com/mallang/reference/domain/ReferenceLinkTest.java +++ b/src/test/java/com/mallang/reference/domain/ReferenceLinkTest.java @@ -2,15 +2,12 @@ import static com.mallang.auth.OauthMemberFixture.깃허브_동훈; import static com.mallang.auth.OauthMemberFixture.깃허브_말랑; -import static com.mallang.blog.domain.BlogFixture.mallangBlog; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import com.mallang.auth.domain.Member; import com.mallang.auth.domain.OauthMember; -import com.mallang.blog.domain.Blog; -import com.mallang.blog.exception.NoAuthorityBlogException; import com.mallang.reference.exception.BadReferenceLinkMemoException; import com.mallang.reference.exception.BadReferenceLinkTitleException; import com.mallang.reference.exception.BadReferenceLinkUrlException; @@ -30,7 +27,6 @@ class ReferenceLinkTest { private final Member member = 깃허브_말랑(1L); - private final Blog blog = mallangBlog(member); @Nested class 생성_시 { @@ -40,7 +36,7 @@ class 생성_시 { void 제목_없이_생성이_불가능하다(String nullAndEmptyTitle) { // when & then assertThatThrownBy(() -> - new ReferenceLink("url", nullAndEmptyTitle, "memo", member, blog) + new ReferenceLink("url", nullAndEmptyTitle, "memo", member) ).isInstanceOf(BadReferenceLinkTitleException.class); } @@ -53,14 +49,14 @@ class 생성_시 { void 제목은_공백으로만_이루어져_있으면_안된다(String title) { // when & then assertThatThrownBy(() -> - new ReferenceLink("url", title, "memo", member, blog) + new ReferenceLink("url", title, "memo", member) ).isInstanceOf(BadReferenceLinkTitleException.class); } @Test void 제목의_앞뒤_공백은_제거된다() { // when - ReferenceLink link = new ReferenceLink("url", " \n 1 \n ", null, member, blog); + ReferenceLink link = new ReferenceLink("url", " \n 1 \n ", null, member); // then assertThat(link.getTitle()).isEqualTo("1"); @@ -85,7 +81,7 @@ class 생성_시 { @NullAndEmptySource void 메모는_없어도_된다(String nullAndEmptyMemo) { // when - ReferenceLink referenceLink = new ReferenceLink("url", "title", nullAndEmptyMemo, member, blog); + ReferenceLink referenceLink = new ReferenceLink("url", "title", nullAndEmptyMemo, member); // then assertThat(referenceLink.getMemo()).isEqualTo(nullAndEmptyMemo); @@ -95,10 +91,10 @@ class 생성_시 { void 메모의_최대_길이는_300글자이다() { // when & then assertDoesNotThrow(() -> - new ReferenceLink("url", "title", "1".repeat(300), member, blog) + new ReferenceLink("url", "title", "1".repeat(300), member) ); assertThatThrownBy(() -> - new ReferenceLink("url", "title", "1".repeat(301), member, blog) + new ReferenceLink("url", "title", "1".repeat(301), member) ).isInstanceOf(BadReferenceLinkMemoException.class); } @@ -106,42 +102,31 @@ class 생성_시 { void url에_값이_존재해야_하며_공백으로만_이루어져서는_안된다() { // when & then assertThatThrownBy(() -> - new ReferenceLink(null, "title1", "", member, blog) + new ReferenceLink(null, "title1", "", member) ).isInstanceOf(BadReferenceLinkUrlException.class); assertThatThrownBy(() -> - new ReferenceLink("", "title1", "", member, blog) + new ReferenceLink("", "title1", "", member) ).isInstanceOf(BadReferenceLinkUrlException.class); assertThatThrownBy(() -> - new ReferenceLink(" ", "title1", "", member, blog) + new ReferenceLink(" ", "title1", "", member) ).isInstanceOf(BadReferenceLinkUrlException.class); } @Test void url의_앞_뒤_공백은_제거된다() { // when - ReferenceLink referenceLink = new ReferenceLink(" d d ", "title1", "", member, blog); + ReferenceLink referenceLink = new ReferenceLink(" d d ", "title1", "", member); // then assertThat(referenceLink.getUrl()).isEqualTo("d d"); } - - @Test - void 블로그의_주인과_생성한_회원이_다르면_예외() { - // given - OauthMember otherMember = 깃허브_동훈(member.getId() + 1); - - // when & then - assertThatThrownBy(() -> { - new ReferenceLink(" d d ", "title1", "", otherMember, blog); - }).isInstanceOf(NoAuthorityBlogException.class); - } } @Test void 회원에_대한_권한_검증을_한다() { // given OauthMember otherMember = 깃허브_동훈(member.getId() + 1); - ReferenceLink referenceLink = new ReferenceLink("url", "title1", null, member, blog); + ReferenceLink referenceLink = new ReferenceLink("url", "title1", null, member); // when & then assertDoesNotThrow(() -> { @@ -155,7 +140,7 @@ class 생성_시 { @Nested class 수정_시 { - private final ReferenceLink link = new ReferenceLink("url", "title", "memo", member, blog); + private final ReferenceLink link = new ReferenceLink("url", "title", "memo", member); @ParameterizedTest @NullAndEmptySource diff --git a/src/test/java/com/mallang/reference/query/ReferenceLinkQueryServiceTest.java b/src/test/java/com/mallang/reference/query/ReferenceLinkQueryServiceTest.java index b29d2a3c..b9d88bd0 100644 --- a/src/test/java/com/mallang/reference/query/ReferenceLinkQueryServiceTest.java +++ b/src/test/java/com/mallang/reference/query/ReferenceLinkQueryServiceTest.java @@ -1,9 +1,7 @@ package com.mallang.reference.query; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.mallang.blog.exception.NoAuthorityBlogException; import com.mallang.common.ServiceTest; import com.mallang.reference.application.command.SaveReferenceLinkCommand; import com.mallang.reference.query.repository.ReferenceLinkSearchDao.ReferenceLinkSearchDaoCond; @@ -22,13 +20,11 @@ class ReferenceLinkQueryServiceTest extends ServiceTest { private Long memberId; - private String blogName; @BeforeEach void setUp() { memberId = 회원을_저장한다("말랑"); - blogName = 블로그_개설(memberId, "mallang-log"); } @Nested @@ -39,7 +35,6 @@ class 주어진_Url로_등록된_링크가_이미_존재하는지_확인_시 { // given referenceLinkService.save(new SaveReferenceLinkCommand( memberId, - blogName, "https://ttl-blog.tistory.com", "말랑이 블로그", "말랑이 블로그 메인 페이지이다." @@ -48,17 +43,14 @@ class 주어진_Url로_등록된_링크가_이미_존재하는지_확인_시 { // when boolean exactlyMatch = referenceLinkQueryService.existsReferenceLinkByUrl( memberId, - blogName, "https://ttl-blog.tistory.com" ); boolean notMatch1 = referenceLinkQueryService.existsReferenceLinkByUrl( memberId, - blogName, "https://ttl-blog.tistory.com/" ); boolean notMatch2 = referenceLinkQueryService.existsReferenceLinkByUrl( memberId, - blogName, "ttl-blog.tistory.com" ); @@ -69,13 +61,11 @@ class 주어진_Url로_등록된_링크가_이미_존재하는지_확인_시 { } @Test - void 다른_블로그에_등록된것과는_무관하다() { + void 다른_회원이_등록한것과는_무관하다() { // given Long otherMemberId = 회원을_저장한다("other"); - String otherBlogName = 블로그_개설(otherMemberId, "other-log"); referenceLinkService.save(new SaveReferenceLinkCommand( otherMemberId, - otherBlogName, "https://ttl-blog.tistory.com/123", "스프링이란?", "누군가 쓴 스프링에 대한 내용." @@ -84,12 +74,10 @@ class 주어진_Url로_등록된_링크가_이미_존재하는지_확인_시 { // when boolean notExist = referenceLinkQueryService.existsReferenceLinkByUrl( memberId, - blogName, "https://ttl-blog.tistory.com/123" ); boolean exist = referenceLinkQueryService.existsReferenceLinkByUrl( otherMemberId, - otherBlogName, "https://ttl-blog.tistory.com/123" ); @@ -97,21 +85,6 @@ class 주어진_Url로_등록된_링크가_이미_존재하는지_확인_시 { assertThat(notExist).isFalse(); assertThat(exist).isTrue(); } - - @Test - void 블로그_주인이_아니라면_예외() { - // given - Long otherMemberId = 회원을_저장한다("other"); - - // when & then - assertThatThrownBy(() -> - referenceLinkQueryService.existsReferenceLinkByUrl( - otherMemberId, - blogName, - "https://ttl-blog.tistory.com/123" - ) - ).isInstanceOf(NoAuthorityBlogException.class); - } } @Nested @@ -124,14 +97,12 @@ class 검색_시 { void setUp() { 말랑이_블로그_링크_ID = referenceLinkService.save(new SaveReferenceLinkCommand( memberId, - blogName, "https://ttl-blog.tistory.com", "말랑이 블로그", "말랑이 블로그 메인 페이지이다." )); Spring_글_참고_링크_ID = referenceLinkService.save(new SaveReferenceLinkCommand( memberId, - blogName, "https://ttl-blog.tistory.com/123", "스프링이란?", "말랑이가 쓴 스프링에 대한 내용." @@ -139,25 +110,24 @@ void setUp() { } @Test - void 아무_조건이_없다면_블로그에_등록된_모든_링크를_조회한다() { + void 아무_조건이_없다면_내가_등록한_모든_링크를_조회한다() { // given ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); // when - List result = referenceLinkQueryService.search(memberId, blogName, emptyCond); + List result = referenceLinkQueryService.search(memberId, emptyCond); // then assertThat(result).hasSize(2); } @Test - void 다른_사람_글은_보이지_않는다() { + void 다른_사람_링크는_보이지_않는다() { // given Long otherMemberId = 회원을_저장한다("other"); String otherBlogName = 블로그_개설(otherMemberId, "other-log"); Long 타인의_Spring_글_참고_링크_ID = referenceLinkService.save(new SaveReferenceLinkCommand( otherMemberId, - otherBlogName, "https://ttl-blog.tistory.com/123", "스프링이란?", "누군가 쓴 스프링에 대한 내용." @@ -165,31 +135,19 @@ void setUp() { ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); // when - List result = referenceLinkQueryService.search(memberId, blogName, emptyCond); + List result = referenceLinkQueryService.search(memberId, emptyCond); // then assertThat(result).hasSize(2); } - @Test - void 블로그의_주인이_아닌_사람이_조회시_예외() { - // given - Long otherMemberId = 회원을_저장한다("other"); - ReferenceLinkSearchDaoCond emptyCond = new ReferenceLinkSearchDaoCond(null, null, null); - - // when & then - assertThatThrownBy(() -> { - referenceLinkQueryService.search(otherMemberId, blogName, emptyCond); - }).isInstanceOf(NoAuthorityBlogException.class); - } - @Test void url_포함조건으로_검색할_수_있다() { // given ReferenceLinkSearchDaoCond urlCond = new ReferenceLinkSearchDaoCond("12", null, null); // when - List result = referenceLinkQueryService.search(memberId, blogName, urlCond); + List result = referenceLinkQueryService.search(memberId, urlCond); // then assertThat(result) @@ -203,7 +161,7 @@ void setUp() { ReferenceLinkSearchDaoCond titleCond = new ReferenceLinkSearchDaoCond(null, "랑이", null); // when - List result = referenceLinkQueryService.search(memberId, blogName, titleCond); + List result = referenceLinkQueryService.search(memberId, titleCond); // then assertThat(result) @@ -217,7 +175,7 @@ void setUp() { ReferenceLinkSearchDaoCond memoCond = new ReferenceLinkSearchDaoCond(null, null, "스프링에"); // when - List result = referenceLinkQueryService.search(memberId, blogName, memoCond); + List result = referenceLinkQueryService.search(memberId, memoCond); // then assertThat(result)