From 1d2fa8876eb065c6049d77cef963dac2b9009be2 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Wed, 11 Oct 2023 16:38:58 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=EB=B9=84=ED=81=AC=EB=A3=A8?= =?UTF-8?q?=EC=9D=B8=EC=9B=90=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20studyLog,=20?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=EB=A7=B5=20=EB=8B=B5=EB=B3=80,=20comment=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EB=A7=89=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prolog/roadmap/application/EssayAnswerService.java | 9 +++++++++ .../prolog/studylog/application/CommentService.java | 9 +++++++++ .../prolog/studylog/application/StudylogService.java | 10 ++++++++++ 3 files changed, 28 insertions(+) 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 5102e0629..aa6b74f22 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java @@ -1,6 +1,7 @@ package wooteco.prolog.roadmap.application; import static wooteco.prolog.common.exception.BadRequestCode.ESSAY_ANSWER_NOT_FOUND_EXCEPTION; +import static wooteco.prolog.common.exception.BadRequestCode.MEMBER_NOT_ALLOWED; import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_QUIZ_NOT_FOUND_EXCEPTION; import org.hibernate.Hibernate; @@ -10,6 +11,7 @@ import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.application.MemberService; import wooteco.prolog.member.domain.Member; +import wooteco.prolog.member.domain.Role; import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest; import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest; import wooteco.prolog.roadmap.domain.EssayAnswer; @@ -43,12 +45,19 @@ public Long createEssayAnswer(EssayAnswerRequest essayAnswerRequest, Long member .orElseThrow(() -> new BadRequestException(ROADMAP_QUIZ_NOT_FOUND_EXCEPTION)); Member member = memberService.findById(memberId); + validateMemberIsCrew(member); EssayAnswer essayAnswer = new EssayAnswer(quiz, essayAnswerRequest.getAnswer(), member); essayAnswerRepository.save(essayAnswer); return essayAnswer.getId(); } + private void validateMemberIsCrew(final Member member) { + if (member.hasLowerImportanceRoleThan(Role.CREW)) { + throw new BadRequestException(MEMBER_NOT_ALLOWED); + } + } + @Transactional public void updateEssayAnswer(Long answerId, EssayAnswerUpdateRequest request, Long memberId) { EssayAnswer essayAnswer = getById(answerId); diff --git a/backend/src/main/java/wooteco/prolog/studylog/application/CommentService.java b/backend/src/main/java/wooteco/prolog/studylog/application/CommentService.java index b0a818ab7..4ed007288 100644 --- a/backend/src/main/java/wooteco/prolog/studylog/application/CommentService.java +++ b/backend/src/main/java/wooteco/prolog/studylog/application/CommentService.java @@ -1,6 +1,7 @@ package wooteco.prolog.studylog.application; import static wooteco.prolog.common.exception.BadRequestCode.COMMENT_NOT_FOUND; +import static wooteco.prolog.common.exception.BadRequestCode.MEMBER_NOT_ALLOWED; import static wooteco.prolog.common.exception.BadRequestCode.MEMBER_NOT_FOUND; import static wooteco.prolog.common.exception.BadRequestCode.STUDYLOG_NOT_FOUND; @@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.member.domain.Member; +import wooteco.prolog.member.domain.Role; import wooteco.prolog.member.domain.repository.MemberRepository; import wooteco.prolog.studylog.application.dto.CommentResponse; import wooteco.prolog.studylog.application.dto.CommentSaveRequest; @@ -33,6 +35,7 @@ public class CommentService { public Long insertComment(CommentSaveRequest request) { Member findMember = memberRepository.findById(request.getMemberId()) .orElseThrow(() -> new BadRequestException(MEMBER_NOT_FOUND)); + validateMemberIsCrew(findMember); Studylog findStudylog = studylogRepository.findById(request.getStudylogId()) .orElseThrow(() -> new BadRequestException(STUDYLOG_NOT_FOUND)); @@ -41,6 +44,12 @@ public Long insertComment(CommentSaveRequest request) { return commentRepository.save(comment).getId(); } + private void validateMemberIsCrew(final Member member) { + if (member.hasLowerImportanceRoleThan(Role.CREW)) { + throw new BadRequestException(MEMBER_NOT_ALLOWED); + } + } + @Transactional(readOnly = true) public CommentsResponse findComments(Long studylogId) { Studylog findStudylog = studylogRepository.findById(studylogId) diff --git a/backend/src/main/java/wooteco/prolog/studylog/application/StudylogService.java b/backend/src/main/java/wooteco/prolog/studylog/application/StudylogService.java index edf5a0cc3..6e321724b 100644 --- a/backend/src/main/java/wooteco/prolog/studylog/application/StudylogService.java +++ b/backend/src/main/java/wooteco/prolog/studylog/application/StudylogService.java @@ -4,6 +4,7 @@ import static java.time.temporal.TemporalAdjusters.lastDayOfMonth; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; +import static wooteco.prolog.common.exception.BadRequestCode.MEMBER_NOT_ALLOWED; import static wooteco.prolog.common.exception.BadRequestCode.STUDYLOG_ARGUMENT; import static wooteco.prolog.common.exception.BadRequestCode.STUDYLOG_DOCUMENT_NOT_FOUND; import static wooteco.prolog.common.exception.BadRequestCode.STUDYLOG_NOT_FOUND; @@ -24,11 +25,13 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import wooteco.prolog.common.exception.BadRequestCode; import wooteco.prolog.common.exception.BadRequestException; import wooteco.prolog.login.ui.LoginMember; import wooteco.prolog.member.application.MemberService; import wooteco.prolog.member.application.MemberTagService; import wooteco.prolog.member.domain.Member; +import wooteco.prolog.member.domain.Role; import wooteco.prolog.session.application.MissionService; import wooteco.prolog.session.application.SessionService; import wooteco.prolog.session.domain.Mission; @@ -93,6 +96,7 @@ public List insertStudylogs(Long memberId, @Transactional public StudylogResponse insertStudylog(Long memberId, StudylogRequest studylogRequest) { Member member = memberService.findById(memberId); + validateMemberIsCrew(member); Tags tags = tagService.findOrCreate(studylogRequest.getTags()); Session session = sessionService.findSessionById(studylogRequest.getSessionId()) .orElse(null); @@ -113,6 +117,12 @@ public StudylogResponse insertStudylog(Long memberId, StudylogRequest studylogRe return StudylogResponse.of(persistStudylog); } + private void validateMemberIsCrew(final Member member) { + if (member.hasLowerImportanceRoleThan(Role.CREW)) { + throw new BadRequestException(MEMBER_NOT_ALLOWED); + } + } + @Transactional public StudylogTempResponse insertStudylogTemp(Long memberId, StudylogRequest studylogRequest) { StudylogTemp createdStudylogTemp = creteStudylogTemp(memberId, studylogRequest); From cafca779b9b350feb696a372b9ac473e3e7dbf4a Mon Sep 17 00:00:00 2001 From: hae-on Date: Wed, 11 Oct 2023 17:07:31 +0900 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20navbar&=ED=95=99=EC=8A=B5?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EA=B6=8C=ED=95=9C=20=EC=9E=88=EB=8A=94=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EB=A7=8C=20=EA=B8=80=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/NavBar/NavBar.tsx | 5 +++-- frontend/src/pages/StudylogListPage/index.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/NavBar/NavBar.tsx b/frontend/src/components/NavBar/NavBar.tsx index 6bfe8ac09..a4c727771 100644 --- a/frontend/src/components/NavBar/NavBar.tsx +++ b/frontend/src/components/NavBar/NavBar.tsx @@ -50,7 +50,8 @@ const NavBar = () => { const { user, onLogout } = useContext(UserContext); - const { username, imageUrl: userImage = NoProfileImage, isLoggedIn } = user; + const { username, imageUrl: userImage = NoProfileImage, isLoggedIn, role } = user; + const authorized = isLoggedIn && role !== 'GUEST'; const [isDropdownToggled, setDropdownToggled] = useState(false); const [isWritingDropdownToggled, setWritingDropdownToggled] = useState(false); @@ -118,7 +119,7 @@ const NavBar = () => { ))} - {isLoggedIn ? ( + {authorized ? ( <>