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] issue 329: 링크 모음 패지키 이동 리팩토링 #350

Merged
merged 43 commits into from
Oct 6, 2022
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f90aa58
refactor: referenceroom 패키지 studyroom 패키지로 이동
verus-j Sep 13, 2022
b0a3ec3
refactor: LinkArticle 클래스 이름 수정 및 필드 타입 변경
verus-j Sep 14, 2022
a72a3c1
refactor: LinkArticle 컨트롤러, 서비스 클래스명 변경 및 EditingLinkRequest 제거
verus-j Sep 14, 2022
56bffea
refactor: LinkArticle update 메서드 변경
verus-j Sep 14, 2022
5de05b1
refactor: LinkArticle delete 메서드 정리
verus-j Sep 14, 2022
8477653
refactor: LinkNotFoundException 제거
verus-j Sep 14, 2022
66a45f5
refactor: 링크 게시글 조회 관련 서비스 제거
verus-j Sep 14, 2022
970fcb8
test: LinkArticleControllerTest setUp 로직 제거
verus-j Sep 14, 2022
2d360cc
refactor: 링크 게시글 목록 조회 시 Authentication URI에서 제거
verus-j Sep 14, 2022
4d154ca
refactor: Community와 Notice 컨트롤러, 서비스 분리
verus-j Sep 14, 2022
96c6595
refactor: ArticleRepositoryFactory 제거
verus-j Sep 14, 2022
89c0efa
refactor: Article 및 조회 시 인가 기능 제거
verus-j Sep 14, 2022
6347b1e
refactor: NoticeArticle 소프트 delete 적용
verus-j Sep 14, 2022
9fa1459
refactor: CommunityArticle 소프트 delete 적용
verus-j Sep 14, 2022
cc91eeb
chore: 충돌 해결
verus-j Sep 15, 2022
b24da71
refactor: 사용하지 않는 메서드 정리 및 예외 패키지 이동
verus-j Sep 15, 2022
7b40834
refactor: 사용하지 않는 코드 제거
verus-j Sep 15, 2022
8231c45
refactor: import 문 정리 및 테스트 클래스 default 접근자 설정
verus-j Sep 15, 2022
689fbf6
chore: index.html gitignore 설정
verus-j Sep 15, 2022
d736fa4
chore: gitignore 재설정
verus-j Sep 15, 2022
99165a2
chore: 공지 게시글 API 문서화
verus-j Sep 15, 2022
452e356
refactor: 제네릭을 사용한 ArticleService 추출
verus-j Sep 15, 2022
14b3f7f
refactor: CommunityArticle에 제네릭 ArticleService 적용
verus-j Sep 15, 2022
503e38d
refactor: NoticeArticle 제네릭 적용 및 ArticleService 추상화 클래스로 전환
verus-j Sep 15, 2022
547589e
refactor: ArticleRepository 인터페이스 추출
verus-j Sep 15, 2022
b3323a5
refactor: Article 추상 클래스로 변경
verus-j Sep 16, 2022
6a0bfda
refactor: LinkArticleDao sql 수정 및 ArticleType 제거
verus-j Sep 16, 2022
907c2e3
test: 테스트 코드 정리
verus-j Sep 16, 2022
c450b64
refactor: 커뮤니티 게시글 삭제 URL 수정 및 Article 생성자 접근 제어자 수정
verus-j Sep 29, 2022
bba8852
refactor: LinkArticle 관련 테스트 가독성 정리
verus-j Sep 29, 2022
8a16f87
test: CommunityArticle 테스트 가독성 정리
verus-j Sep 29, 2022
5e205cf
test: NoticeArticle 테스트 가독성 정리
verus-j Sep 29, 2022
45afd56
chore: develop 브랜치 충돌 해결
verus-j Sep 29, 2022
aedff89
refactor: Article 구조 수정
verus-j Sep 29, 2022
8d94025
refactor: LinkArticle 상속 구조 제거
verus-j Oct 1, 2022
870c641
refactor: NoticeArtice 상속 구조 제거
verus-j Oct 1, 2022
0e4a4de
refactor: CommunityArticle 상속 구조 제거
verus-j Oct 1, 2022
547adcd
refactor: ArticleType을 사용한 구분
verus-j Oct 1, 2022
3f4e9f5
refactor: ArticleType Enum 정리
verus-j Oct 4, 2022
ee2e850
refactor: 도메인 패키지 정리
verus-j Oct 4, 2022
81aa170
refactor: 피드백 반영
verus-j Oct 6, 2022
445f0b3
chore: 충돌 해결
verus-j Oct 6, 2022
6bb7d06
refactor: 패키지 정리
verus-j Oct 6, 2022
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
Prev Previous commit
Next Next commit
refactor: 피드백 반영
verus-j committed Oct 6, 2022

Verified

This commit was signed with the committer’s verified signature.
cyriltovena Cyril Tovena
commit 81aa17059ad9f5ba3e948f185b7a7c46b2f2f646
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.woowacourse.moamoa.studyroom.controller;

import com.woowacourse.moamoa.auth.config.AuthenticatedMemberId;
import com.woowacourse.moamoa.studyroom.domain.article.Article;
import com.woowacourse.moamoa.studyroom.domain.article.ArticleType;
import com.woowacourse.moamoa.studyroom.service.ArticleService;
import com.woowacourse.moamoa.studyroom.service.request.ArticleRequest;
@@ -39,8 +38,8 @@ public ResponseEntity<Void> createArticle(@AuthenticatedMemberId final Long id,
@Valid @RequestBody final ArticleRequest request
) {
final ArticleType type = ArticleType.valueOf(typeName.toUpperCase());
final Article article = articleService.createArticle(id, studyId, request.createContent(), type);
final URI location = URI.create("/api/studies/" + studyId + "/" + typeName + "/articles/" + article.getId());
final Long articleId = articleService.createArticle(id, studyId, request.createContent(), type);
final URI location = URI.create("/api/studies/" + studyId + "/" + typeName + "/articles/" + articleId);
return ResponseEntity.created(location).header("Access-Control-Allow-Headers", HttpHeaders.LOCATION).build();
}

@@ -56,9 +55,11 @@ public ResponseEntity<ArticleResponse> getArticle(@PathVariable("article-id") fi
@DeleteMapping("/{article-id}")
public ResponseEntity<Void> deleteArticle(@AuthenticatedMemberId final Long id,
@PathVariable("study-id") final Long studyId,
@PathVariable("article-id") final Long articleId
@PathVariable("article-id") final Long articleId,
@PathVariable("type") final String typeName
) {
articleService.deleteArticle(id, studyId, articleId);
final ArticleType type = ArticleType.valueOf(typeName.toUpperCase());
articleService.deleteArticle(id, studyId, articleId, type);
return ResponseEntity.noContent().build();
}

@@ -77,9 +78,11 @@ public ResponseEntity<ArticleSummariesResponse> getArticles(
public ResponseEntity<Void> updateArticle(@AuthenticatedMemberId final Long id,
@PathVariable("study-id") final Long studyId,
@PathVariable("article-id") final Long articleId,
@PathVariable("type") final String typeName,
@Valid @RequestBody final ArticleRequest request
) {
articleService.updateArticle(id, studyId, articleId, request.createContent());
final ArticleType type = ArticleType.valueOf(typeName.toUpperCase());
articleService.updateArticle(id, studyId, articleId, request.createContent(), type);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public ResponseEntity<Void> createLink(
@PathVariable("study-id") final Long studyId,
@Valid @RequestBody final LinkArticleRequest articleRequest
) {
final Long id = linkArticleService.createArticle(memberId, studyId, articleRequest.createContent()).getId();
final Long id = linkArticleService.createArticle(memberId, studyId, articleRequest.createContent());
return ResponseEntity.created(URI.create("/api/studies/" + studyId + "/reference-room/links/" + id)).build();
}

Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public static Article create(
final StudyRoom studyRoom, final Accessor accessor, final Content content, final ArticleType type
) {
if (type.isUnwritableAccessor(studyRoom, accessor)) {
throw new UneditableArticleException(studyRoom.getId(), accessor, Article.class);
throw new UneditableArticleException(studyRoom.getId(), accessor, type.name());
}

return new Article(null, studyRoom, accessor.getMemberId(), content, type);
@@ -68,15 +68,15 @@ private Article(

public void update(final Accessor accessor, final Content content) {
if (type.isUneditableAccessor(studyRoom, authorId, accessor)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 방법으로 푸니 로직이 훨씬 간결해졌네요 👍

throw new UneditableArticleException(studyRoom.getId(), accessor, getClass());
throw new UneditableArticleException(studyRoom.getId(), accessor, type.name());
}

this.content = content;
}

public final void delete(final Accessor accessor) {
if (type.isUneditableAccessor(studyRoom, authorId, accessor)) {
throw new UneditableArticleException(studyRoom.getId(), accessor, getClass());
throw new UneditableArticleException(studyRoom.getId(), accessor, type.name());
}

deleted = true;
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

public class UneditableArticleException extends BadRequestException {

public UneditableArticleException(final Long studyId, final Accessor accessor, final Class<?> articleType) {
super(String.format("스터디[%d]에 접근자[%s]가 %s의 게시글을 수정/추가할 수 없습니다.", studyId, accessor, articleType.getSimpleName()));
public UneditableArticleException(final Long studyId, final Accessor accessor, final String typeName) {
super(String.format("스터디[%d]에 접근자[%s]가 %s의 게시글을 수정/추가할 수 없습니다.", studyId, accessor, typeName));
}
}
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ public static LinkArticle create(final StudyRoom studyRoom, final Accessor acces
return new LinkArticle(studyRoom, accessor.getMemberId(), content);
}

throw new UneditableArticleException(studyRoom.getId(), accessor, LinkArticle.class);
throw new UneditableArticleException(studyRoom.getId(), accessor, "LINK");
}

private LinkArticle(final StudyRoom studyRoom, final Long authorId, final LinkContent content) {
@@ -62,15 +62,15 @@ private LinkArticle(final Long id, final StudyRoom studyRoom, final Long authorI

public final void delete(final Accessor accessor) {
if (isUneditableAccessor(accessor)) {
throw new UneditableArticleException(studyRoom.getId(), accessor, LinkArticle.class);
throw new UneditableArticleException(studyRoom.getId(), accessor, "LINK");
}

deleted = true;
}

public void update(final Accessor accessor, final LinkContent content) {
if (isUneditableAccessor(accessor)) {
throw new UneditableArticleException(studyRoom.getId(), accessor, LinkArticle.class);
throw new UneditableArticleException(studyRoom.getId(), accessor, "LINK");
}

this.content = content;
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import com.woowacourse.moamoa.studyroom.domain.article.Article;
import com.woowacourse.moamoa.studyroom.domain.article.ArticleType;
import com.woowacourse.moamoa.studyroom.domain.article.Content;
import com.woowacourse.moamoa.studyroom.domain.exception.ArticleNotFoundException;
import com.woowacourse.moamoa.studyroom.service.exception.ArticleNotFoundException;
import com.woowacourse.moamoa.studyroom.domain.article.repository.ArticleRepository;
import com.woowacourse.moamoa.studyroom.domain.studyroom.repository.StudyRoomRepository;
import com.woowacourse.moamoa.studyroom.query.ArticleDao;
@@ -39,7 +39,7 @@ public ArticleService(final StudyRoomRepository studyRoomRepository,

public ArticleResponse getArticle(final Long articleId, final ArticleType type) {
final ArticleData data = articleDao.getById(articleId, type)
.orElseThrow(() -> new ArticleNotFoundException(articleId, Article.class));
.orElseThrow(() -> new ArticleNotFoundException(articleId, type.name()));
return new ArticleResponse(data);
}

@@ -55,30 +55,31 @@ public ArticleSummariesResponse getArticles(final Long studyId, final Pageable p
}

@Transactional
public Article createArticle(
public Long createArticle(
final Long memberId, final Long studyId, final Content content, final ArticleType type
) {
final StudyRoom studyRoom = studyRoomRepository.findByStudyId(studyId)
.orElseThrow(() -> new StudyNotFoundException(studyId));
final Article article = Article.create(studyRoom, new Accessor(memberId, studyId), content, type);

return articleRepository.save(article);
return articleRepository.save(article).getId();
}

@Transactional
public void updateArticle(
final Long memberId, final Long studyId, final Long articleId, final Content newContent
final Long memberId, final Long studyId, final Long articleId, final Content newContent,
final ArticleType type
) {
final Article article = articleRepository.findById(articleId)
.orElseThrow(() -> new ArticleNotFoundException(articleId, Article.class));
.orElseThrow(() -> new ArticleNotFoundException(articleId, type.name()));

article.update(new Accessor(memberId, studyId), newContent);
}

@Transactional
public void deleteArticle(final Long memberId, final Long studyId, final Long articleId) {
public void deleteArticle(final Long memberId, final Long studyId, final Long articleId, final ArticleType type) {
final Article article = articleRepository.findById(articleId)
.orElseThrow(() -> new ArticleNotFoundException(articleId, Article.class));
.orElseThrow(() -> new ArticleNotFoundException(articleId, type.name()));
final Accessor accessor = new Accessor(memberId, studyId);

article.delete(accessor);
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import com.woowacourse.moamoa.studyroom.domain.studyroom.StudyRoom;
import com.woowacourse.moamoa.studyroom.domain.link.LinkArticle;
import com.woowacourse.moamoa.studyroom.domain.link.LinkContent;
import com.woowacourse.moamoa.studyroom.domain.exception.ArticleNotFoundException;
import com.woowacourse.moamoa.studyroom.service.exception.ArticleNotFoundException;
import com.woowacourse.moamoa.studyroom.domain.link.repository.LinkArticleRepository;
import com.woowacourse.moamoa.studyroom.domain.studyroom.repository.StudyRoomRepository;
import com.woowacourse.moamoa.studyroom.query.LinkArticleDao;
@@ -39,28 +39,28 @@ public LinksResponse getLinks(final Long studyId, final Pageable pageable) {
}

@Transactional
public LinkArticle createArticle(final Long memberId, final Long studyId, final LinkContent content) {
public Long createArticle(final Long memberId, final Long studyId, final LinkContent content) {
final StudyRoom studyRoom = studyRoomRepository.findByStudyId(studyId)
.orElseThrow(() -> new StudyNotFoundException(studyId));
final LinkArticle article = LinkArticle.create(studyRoom, new Accessor(memberId, studyId), content);

return linkArticleRepository.save(article);
return linkArticleRepository.save(article).getId();
}

@Transactional
public void updateArticle(
final Long memberId, final Long studyId, final Long articleId, final LinkContent newContent
) {
final LinkArticle article = linkArticleRepository.findById(articleId)
.orElseThrow(() -> new ArticleNotFoundException(articleId, LinkArticle.class));
.orElseThrow(() -> new ArticleNotFoundException(articleId, "LINK"));

article.update(new Accessor(memberId, studyId), newContent);
}

@Transactional
public void deleteArticle(final Long memberId, final Long studyId, final Long articleId) {
final LinkArticle article = linkArticleRepository.findById(articleId)
.orElseThrow(() -> new ArticleNotFoundException(articleId, LinkArticle.class));
.orElseThrow(() -> new ArticleNotFoundException(articleId, "LINK"));
final Accessor accessor = new Accessor(memberId, studyId);

article.delete(accessor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음 Accessor를 활용할 때는 몰랐는데, 이렇게 보니 Accessor 의 활용도가 굉장히 높네요!
Member가 굳이 필요가 없군요!

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.woowacourse.moamoa.studyroom.domain.exception;
package com.woowacourse.moamoa.studyroom.service.exception;

import com.woowacourse.moamoa.common.exception.NotFoundException;

public class ArticleNotFoundException extends NotFoundException {

public ArticleNotFoundException(final Long articleId, final Class<?> articleType) {
super(String.format("%d의 식별자를 가진 %s 게시글이 존재하지 않습니다.", articleId, articleType.getSimpleName()));
public ArticleNotFoundException(final Long articleId, final String typeName) {
super(String.format("%d의 식별자를 가진 %s 게시글이 존재하지 않습니다.", articleId, typeName));
}
}
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class ArticleTest {
class CommunityArticleTest {

private static final long OWNER_ID = 1L;
private static final long PARTICIPANT_ID = 2L;
Loading