From 27d95dadb8df83aeb56987a880046a777eb8e476 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Thu, 20 Jul 2023 17:50:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=EB=AF=B8=EB=8F=99=EC=9E=91=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.ebextensions/02-set-filebeat.config | 48 -------------------- 1 file changed, 48 deletions(-) delete mode 100644 backend/.ebextensions/02-set-filebeat.config diff --git a/backend/.ebextensions/02-set-filebeat.config b/backend/.ebextensions/02-set-filebeat.config deleted file mode 100644 index 5a0648d88..000000000 --- a/backend/.ebextensions/02-set-filebeat.config +++ /dev/null @@ -1,48 +0,0 @@ -files: - "/tmp/make_filebeat_yml.sh": - mode: "000755" - content: | - #!/bin/bash - PASSWORD=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PASSWORD) - HOST=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_HOST) - PORT=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PORT) - USER=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_USER) - cat > /home/ec2-user/filebeat-7.14.1-linux-x86_64/filebeat.yml < Date: Sun, 23 Jul 2023 22:51:01 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20EssayAnswer=20=EC=9D=98=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=98=88=EC=99=B8=20=EC=83=81=ED=99=A9=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prolog/common/exception/BadRequestCode.java | 5 +++++ .../roadmap/application/EssayAnswerService.java | 15 +++++++++------ .../prolog/roadmap/domain/EssayAnswer.java | 8 ++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/wooteco/prolog/common/exception/BadRequestCode.java b/backend/src/main/java/wooteco/prolog/common/exception/BadRequestCode.java index f7790786f..63d12ffda 100644 --- a/backend/src/main/java/wooteco/prolog/common/exception/BadRequestCode.java +++ b/backend/src/main/java/wooteco/prolog/common/exception/BadRequestCode.java @@ -41,6 +41,7 @@ public enum BadRequestCode { SCRAP_NOT_EXIST(3008, "스크랩이 존재하지 않습니다."), SCRAP_NOT_VALID_USER(3009, "본인의 스크랩만 추가할 수 있습니다."), NOT_EXISTS_MEMBER_TAG(3010, "멤버 태그가 존재하지 않습니다."), + CANT_FIND_GROUP_TYPE(3011, "해당 그룹의 타입을 결정할 수 없습니다."), INVALID_LIKE_REQUEST_EXCEPTION(5001, "스터디로그를 좋아요 할 수 없습니다."), INVALID_UNLIKE_REQUEST_EXCEPTION(5002, "스터디로그를 좋아요 취소 할 수 없습니다."), @@ -65,6 +66,10 @@ public enum BadRequestCode { CURRICULUM_NOT_FOUND_EXCEPTION(8010, "해당하는 커리큘럼을 찾을 수 없습니다"), CURRICULUM_INVALID_EXCEPTION(8011, "커리큘럼이 유효하지 않습니다."), + ESSAY_ANSWER_NOT_FOUND_EXCEPTION(8012, "해당 답변을 찾을 수 없습니다."), + NOT_EMPTY_ESSAY_ANSWER_EXCEPTION(8013, "답변은 공백일 수 없습니다."), + ESSAY_ANSWER_NOT_VALID_USER(8014, "본인이 작성한 답변만 수정할 수 있습니다."), + FILE_NAME_EMPTY_EXCEPTION(9001, "파일 이름이 존재하지 않습니다."), UNSUPPORTED_FILE_EXTENSION_EXCEPTION(9002, "지원하지 않는 파일 확장자입니다."), FILE_UPLOAD_FAIL_EXCEPTION(9003, "파일 업로드에 실패했습니다."), diff --git a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java index f7430eb40..5102e0629 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java @@ -1,9 +1,13 @@ package wooteco.prolog.roadmap.application; +import static wooteco.prolog.common.exception.BadRequestCode.ESSAY_ANSWER_NOT_FOUND_EXCEPTION; +import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_QUIZ_NOT_FOUND_EXCEPTION; + import org.hibernate.Hibernate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.application.MemberService; import wooteco.prolog.member.domain.Member; import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest; @@ -36,7 +40,7 @@ public EssayAnswerService(EssayAnswerRepository essayAnswerRepository, public Long createEssayAnswer(EssayAnswerRequest essayAnswerRequest, Long memberId) { Long quizId = essayAnswerRequest.getQuizId(); Quiz quiz = quizRepository.findById(quizId) - .orElseThrow(() -> new IllegalArgumentException("퀴즈가 존재하지 않습니다. quizId=" + quizId)); + .orElseThrow(() -> new BadRequestException(ROADMAP_QUIZ_NOT_FOUND_EXCEPTION)); Member member = memberService.findById(memberId); EssayAnswer essayAnswer = new EssayAnswer(quiz, essayAnswerRequest.getAnswer(), member); @@ -56,16 +60,15 @@ public void updateEssayAnswer(Long answerId, EssayAnswerUpdateRequest request, L @Transactional public void deleteEssayAnswer(Long answerId, Long memberId) { - if (!essayAnswerRepository.findByIdAndMemberId(answerId, memberId).isPresent()) { - throw new IllegalArgumentException("답변이 존재하지 않습니다. answerId=" + answerId); - } - essayAnswerRepository.deleteById(answerId); + EssayAnswer essayAnswer = essayAnswerRepository.findByIdAndMemberId(answerId, memberId) + .orElseThrow(() -> new BadRequestException(ESSAY_ANSWER_NOT_FOUND_EXCEPTION)); + essayAnswerRepository.deleteById(essayAnswer.getId()); } @Transactional(readOnly = true) public EssayAnswer getById(Long answerId) { EssayAnswer essayAnswer = essayAnswerRepository.findById(answerId) - .orElseThrow(() -> new IllegalArgumentException("답변이 존재하지 않습니다. answerId=" + answerId)); + .orElseThrow(() -> new BadRequestException(ESSAY_ANSWER_NOT_FOUND_EXCEPTION)); Hibernate.initialize(essayAnswer.getQuiz()); Hibernate.initialize(essayAnswer.getMember()); diff --git a/backend/src/main/java/wooteco/prolog/roadmap/domain/EssayAnswer.java b/backend/src/main/java/wooteco/prolog/roadmap/domain/EssayAnswer.java index 547d66af5..e0da72786 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/domain/EssayAnswer.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/domain/EssayAnswer.java @@ -1,5 +1,8 @@ package wooteco.prolog.roadmap.domain; +import static wooteco.prolog.common.exception.BadRequestCode.ESSAY_ANSWER_NOT_VALID_USER; +import static wooteco.prolog.common.exception.BadRequestCode.NOT_EMPTY_ESSAY_ANSWER_EXCEPTION; + import javax.persistence.Column; import javax.persistence.ConstraintMode; import javax.persistence.Entity; @@ -16,6 +19,7 @@ import lombok.NoArgsConstructor; import org.apache.commons.lang3.StringUtils; import wooteco.prolog.common.AuditingEntity; +import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.domain.Member; @Table(name = "essay_answer") @@ -52,10 +56,10 @@ public EssayAnswer(final Quiz quiz, final String answer, Member member) { public void update(String answer, Member member) { if (StringUtils.isBlank(answer)) { - throw new IllegalArgumentException("답변 내용은 공백일 수 없습니다."); + throw new BadRequestException(NOT_EMPTY_ESSAY_ANSWER_EXCEPTION); } if (!this.member.equals(member)) { - throw new IllegalArgumentException("본인이 작성한 답변만 수정할 수 있습니다."); + throw new BadRequestException(ESSAY_ANSWER_NOT_VALID_USER); } this.answer = answer; From 5e2531487796142698d27707af6974b180947f24 Mon Sep 17 00:00:00 2001 From: BGuga Date: Sun, 23 Jul 2023 22:51:36 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20MemberGroup=20=EC=9D=98=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=98=88=EC=99=B8=20=EC=83=81=ED=99=A9=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/wooteco/prolog/member/domain/MemberGroup.java | 8 ++++++-- .../studylog/application/PopularStudylogService.java | 4 ++-- .../wooteco/prolog/member/domain/MemberGroupTest.java | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/wooteco/prolog/member/domain/MemberGroup.java b/backend/src/main/java/wooteco/prolog/member/domain/MemberGroup.java index cfa6a76d0..f45b9dc3f 100644 --- a/backend/src/main/java/wooteco/prolog/member/domain/MemberGroup.java +++ b/backend/src/main/java/wooteco/prolog/member/domain/MemberGroup.java @@ -1,5 +1,7 @@ package wooteco.prolog.member.domain; +import static wooteco.prolog.common.exception.BadRequestCode.CANT_FIND_GROUP_TYPE; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -7,6 +9,8 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import wooteco.prolog.common.exception.BadRequestCode; +import wooteco.prolog.common.exception.BadRequestException; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -31,13 +35,13 @@ public MemberGroup(Long id, String name, String description) { this.description = description; } - public MemberGroupType getGroupType() { + public MemberGroupType groupType() { for (MemberGroupType groupType : MemberGroupType.values()) { if (groupType.isContainedBy(this.name)) { return groupType; } } - throw new IllegalArgumentException("그룹이 포함되는 타입이 없습니다. id=" + this.id); + throw new BadRequestException(CANT_FIND_GROUP_TYPE); } } diff --git a/backend/src/main/java/wooteco/prolog/studylog/application/PopularStudylogService.java b/backend/src/main/java/wooteco/prolog/studylog/application/PopularStudylogService.java index 67b1bbb5b..ba5b32355 100644 --- a/backend/src/main/java/wooteco/prolog/studylog/application/PopularStudylogService.java +++ b/backend/src/main/java/wooteco/prolog/studylog/application/PopularStudylogService.java @@ -49,7 +49,7 @@ public void updatePopularStudylogs(Pageable pageable) { List groupMembers = groupMemberRepository.findAll(); Map> memberGroupsBygroupType = memberGroupRepository.findAll() .stream() - .collect(Collectors.groupingBy(MemberGroup::getGroupType)); + .collect(Collectors.groupingBy(MemberGroup::groupType)); final List recentStudylogs = findRecentStudylogs(LocalDateTime.now(), pageable.getPageSize()); @@ -111,7 +111,7 @@ public PopularStudylogsResponse findPopularStudylogs(Pageable pageable, Long mem List allPopularStudylogs = getSortedPopularStudyLogs(pageable); List groupedMembers = groupMemberRepository.findAll(); Map> memberGroupsBygroupType = memberGroupRepository.findAll() - .stream().collect(Collectors.groupingBy(MemberGroup::getGroupType)); + .stream().collect(Collectors.groupingBy(MemberGroup::groupType)); return PopularStudylogsResponse.of( studylogsResponse(allPopularStudylogs, pageable, memberId), diff --git a/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java b/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java index c9d0f5b6c..ad1371b18 100644 --- a/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java +++ b/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java @@ -13,16 +13,16 @@ class MemberGroupTest { @Test void getGroupType_이름이_그룹명을_포함하면_그룹을_반환한다() { - assertThat(ANDROID_GROUP.getGroupType()).isEqualTo(MemberGroupType.ANDROID); - assertThat(BACKEND_GROUP.getGroupType()).isEqualTo(MemberGroupType.BACKEND); - assertThat(FRONTEND_GROUP.getGroupType()).isEqualTo(MemberGroupType.FRONTEND); + assertThat(ANDROID_GROUP.groupType()).isEqualTo(MemberGroupType.ANDROID); + assertThat(BACKEND_GROUP.groupType()).isEqualTo(MemberGroupType.BACKEND); + assertThat(FRONTEND_GROUP.groupType()).isEqualTo(MemberGroupType.FRONTEND); } @Test void getGroupType_이름이_포함하는_그룹명이_없으면_예외가_발생한다() { MemberGroup memberGroup = new MemberGroup(null, "테스트", "test"); - assertThatThrownBy(memberGroup::getGroupType) + assertThatThrownBy(memberGroup::groupType) .isInstanceOf(IllegalArgumentException.class) .hasMessage("그룹이 포함되는 타입이 없습니다. id=null"); } From 46372963d53e1152e7312f0203b7ba8a5b09faf4 Mon Sep 17 00:00:00 2001 From: BGuga Date: Sun, 23 Jul 2023 23:03:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=EC=9D=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EC=97=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wooteco/prolog/member/domain/MemberGroupTest.java | 6 ++++-- .../roadmap/application/EssayAnswerServiceTest.java | 5 +++-- .../wooteco/prolog/roadmap/domain/EssayAnswerTest.java | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java b/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java index ad1371b18..702640ade 100644 --- a/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java +++ b/backend/src/test/java/wooteco/prolog/member/domain/MemberGroupTest.java @@ -4,6 +4,8 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import org.junit.jupiter.api.Test; +import wooteco.prolog.common.exception.BadRequestCode; +import wooteco.prolog.common.exception.BadRequestException; class MemberGroupTest { @@ -23,8 +25,8 @@ class MemberGroupTest { MemberGroup memberGroup = new MemberGroup(null, "테스트", "test"); assertThatThrownBy(memberGroup::groupType) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("그룹이 포함되는 타입이 없습니다. id=null"); + .isInstanceOf(BadRequestException.class) + .hasMessage("해당 그룹의 타입을 결정할 수 없습니다."); } } diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java index fbae450bf..1f4a12766 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java @@ -18,6 +18,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import wooteco.prolog.common.exception.BadRequestCode; import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.application.MemberService; import wooteco.prolog.member.domain.Member; @@ -109,7 +110,7 @@ void deleteEssayAnswer_fail() { //when,then assertThatThrownBy(() -> essayAnswerService.deleteEssayAnswer(1L, 1L)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(BadRequestException.class); } @DisplayName("deleteEssayAnswer 에서 answerId memberId 에 매핑되는 EssayAnswer 가 있다면 삭제한다") @@ -135,7 +136,7 @@ void getById_fail() { //when,then assertThatThrownBy(() -> essayAnswerService.getById(1L)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(BadRequestException.class); } @DisplayName("getById 에서 answerId 에 해당하는 EssayAnswer 가있다면 반환해준다") diff --git a/backend/src/test/java/wooteco/prolog/roadmap/domain/EssayAnswerTest.java b/backend/src/test/java/wooteco/prolog/roadmap/domain/EssayAnswerTest.java index 04ffeeac2..00ff19f2d 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/domain/EssayAnswerTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/domain/EssayAnswerTest.java @@ -6,9 +6,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import wooteco.prolog.common.exception.BadRequestCode; +import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.domain.Member; -public class EssayAnswerTest { +class EssayAnswerTest { @ValueSource(strings = {"", " "}) @ParameterizedTest @@ -19,8 +21,8 @@ public class EssayAnswerTest { //expect assertThatThrownBy(() -> essayAnswer.update(answer, member)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("답변 내용은 공백일 수 없습니다."); + .isInstanceOf(BadRequestException.class) + .hasMessage("답변은 공백일 수 없습니다."); } @Test @@ -32,7 +34,7 @@ public class EssayAnswerTest { //expect assertThatThrownBy(() -> essayAnswer.update("answer", another)) - .isInstanceOf(IllegalArgumentException.class) + .isInstanceOf(BadRequestException.class) .hasMessage("본인이 작성한 답변만 수정할 수 있습니다."); }