Skip to content

Commit

Permalink
Merge pull request #1597 from woowacourse/article-develop
Browse files Browse the repository at this point in the history
article develop, develop 브랜치에 머지
  • Loading branch information
hong-sile authored Oct 11, 2023
2 parents aa035e7 + 2fdb718 commit 5a1297d
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Feature: 아티클 관련 기능
# When 아티클을 전체 조회 하면
# Then 아티클이 전체 조회 된다


Scenario: 아티클을 수정하기
Given 아티클을 여러개 작성하고
When 1번 아티클을 수정하면
Expand Down
11 changes: 11 additions & 0 deletions backend/src/documentation/java/wooteco/prolog/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import java.util.HashMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -45,6 +47,15 @@ public void setUp(RestDocumentationContextProvider restDocumentation) {
.then().log().all()
.extract().body().as(TokenResponse.class);

HashMap<String, Object> data = new HashMap<>();
data.put("role", "CREW");

final RequestSpecification requestSpecification = RestAssured
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(로그인_사용자.getAccessToken());
requestSpecification.patch("/members/" + 1 + "/role");

this.spec = new RequestSpecBuilder()
.addFilter(documentationConfiguration(restDocumentation))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION;
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 static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_SESSION_NOT_FOUND_EXCEPTION;

Expand All @@ -16,6 +17,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.EssayAnswerSearchRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest;
Expand All @@ -30,6 +32,7 @@
import wooteco.prolog.session.domain.repository.SessionRepository;
import wooteco.prolog.studylog.application.dto.EssayAnswersResponse;


@Transactional
@Service
public class EssayAnswerService {
Expand Down Expand Up @@ -60,12 +63,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);
Expand Down Expand Up @@ -129,7 +139,8 @@ public EssayAnswersResponse searchEssayAnswers(
.and(EssayAnswerSpecification.inMemberIds(request.getMemberIds()))
.and(EssayAnswerSpecification.orderByIdDesc());

final Page<EssayAnswer> essayAnswers = essayAnswerRepository.findAll(essayAnswerSpecification,
final Page<EssayAnswer> essayAnswers = essayAnswerRepository.findAll(
essayAnswerSpecification,
pageable);
return EssayAnswersResponse.of(essayAnswers);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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));

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -93,6 +96,7 @@ public List<StudylogResponse> 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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;
Expand Down Expand Up @@ -75,7 +76,7 @@ void createEssayAnswer() {
when(quizRepository.findById(anyLong())).thenReturn(
Optional.of(new Quiz(null, "question")));
when(memberService.findById(anyLong())).thenReturn(
new Member(null, null, null, null, null));
new Member(null, null, Role.CREW, null, null));

//when
final Long essayAnswer = essayAnswerService.createEssayAnswer(ESSAY_ANSWER_REQUEST, 1L);
Expand Down
Loading

0 comments on commit 5a1297d

Please sign in to comment.