Skip to content

Commit

Permalink
Merge pull request #1364 from woowacourse/feature/1357-roadmap-update
Browse files Browse the repository at this point in the history
Feature/#1357 로드맵 답변 수정 기능
  • Loading branch information
nuyh99 authored Jul 5, 2023
2 parents 715af8e + 151bdef commit c86d537
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void invokeHttpGetWithToken(String path, Object... pathParams) {

public void invokeHttpGetWithTokenAndCookies(String path, Map<String, ?> cookies, Object... pathParams) {
request = RestAssured.given().log().all()
.cookies(cookies)
.auth().oauth2(accessToken);
.cookies(cookies)
.auth().oauth2(accessToken);
response = request.when().get(path, pathParams);
response.then().log().all();
}
Expand All @@ -82,6 +82,15 @@ public void invokeHttpPutWithToken(String path, Object data) {
response.then().log().all();
}

public void invokeHttpPatchWithToken(String path, Object data) {
request = RestAssured
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(accessToken);
response = request.patch(path);
response.then().log().all();
}

public void invokeHttpPostWithToken(String path) {
request = RestAssured
.given().log().all()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package wooteco.prolog.steps;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.springframework.http.HttpStatus;
import wooteco.prolog.AcceptanceSteps;
import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest;

import static org.assertj.core.api.Assertions.assertThat;

public final class EssayAnswerStepDefinitions extends AcceptanceSteps {

@Given("{long}번 퀴즈에 {string}(이)라는 답변을 생성하(면)(고)")
public void 퀴즈에답변을생성하면(final long quidId, final String answer) {
EssayAnswerRequest request = new EssayAnswerRequest(quidId, answer);
context.invokeHttpPostWithToken("/essay-answers", request);
}

@When("{long}번 답변을 조회하면")
public void 답변을조회하면(final long answerId) {
context.invokeHttpGet("essay-answers/" + answerId);
}

@When("{long}번 답변을 {string}(으)로 수정하면")
public void 답변을수정하면(final long answerId, final String answer) {
EssayAnswerUpdateRequest request = new EssayAnswerUpdateRequest(answer);
context.invokeHttpPatchWithToken("/essay-answers/" + answerId, request);
}

@When("{long}번 답변을 삭제하면")
public void 답변을삭제하면(final long answerId) {
context.invokeHttpDeleteWithToken("/essay-answers/" + answerId);
}

@When("{long}번 퀴즈에 대한 답변들을 조회하면")
public void 퀴즈에대한답변을들조회하면(final long quizId) {
context.invokeHttpGet("/quizzes/" + quizId + "/essay-answers");
}

@Then("답변이 생성된다")
public void 답변이생성된다() {
int statusCode = context.response.statusCode();
assertThat(statusCode).isEqualTo(HttpStatus.OK.value());
}

@Then("답변(들)이 조회된다")
public void 답변이조회된다() {
int statusCode = context.response.statusCode();
assertThat(statusCode).isEqualTo(HttpStatus.OK.value());
}

@Then("답변이 수정된다")
public void 답변이수정된다() {
int statusCode = context.response.statusCode();
assertThat(statusCode).isEqualTo(HttpStatus.OK.value());
}

@Then("답변이 삭제된다")
public void 답변이삭제된다() {
int statusCode = context.response.statusCode();
assertThat(statusCode).isEqualTo(HttpStatus.NO_CONTENT.value());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@api
Feature: 로드맵 답변 관련 기능

Background: 사전 작업
Given "2022 백엔드 레벨1" 세션을 생성하고 - 1번 세션
And 1번 세션에 "자바"라는 키워드를 순서 1, 중요도 1로 작성하고
And 1번 세션, 1번 키워드에 퀴즈를 작성하고
And "브라운"이 로그인을 하고

Scenario: 답변 생성하기
When 1번 퀴즈에 "varargs는 가변 인자"라는 답변을 생성하면
Then 답변이 생성된다

Scenario: 답변 조회하기
Given 1번 퀴즈에 "varargs는 가변 인자"라는 답변을 생성하고
When 1번 답변을 조회하면
Then 답변이 조회된다

Scenario: 답변 수정하기
Given 1번 퀴즈에 "varargs는 가변 인자"라는 답변을 생성하고
When 1번 답변을 "Integer은 wrapper 클래스"로 수정하면
Then 답변이 수정된다

Scenario: 답변 삭제하기
Given 1번 퀴즈에 "varargs는 가변 인자"라는 답변을 생성하고
When 1번 답변을 삭제하면
Then 답변이 삭제된다

Scenario: 퀴즈에 대한 모든 답변 조회하기
Given 1번 퀴즈에 "varargs는 가변 인자"라는 답변을 생성하고
When 1번 퀴즈에 대한 답변들을 조회하면
Then 답변들이 조회된다
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package wooteco.prolog.roadmap.application.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public final class EssayAnswerUpdateRequest {
private String answer;
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package wooteco.prolog.roadmap.ui;

import static java.util.stream.Collectors.toList;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import wooteco.prolog.login.domain.AuthMemberPrincipal;
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.roadmap.application.EssayAnswerService;
import wooteco.prolog.roadmap.application.QuizService;
import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerResponse;
import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest;
import wooteco.prolog.roadmap.application.dto.QuizResponse;
import wooteco.prolog.roadmap.domain.EssayAnswer;

import java.util.List;

import static java.util.stream.Collectors.toList;

@RestController
@RequestMapping
public class EssayAnswerController {
Expand Down Expand Up @@ -49,15 +45,23 @@ public ResponseEntity<EssayAnswerResponse> findById(@PathVariable Long essayAnsw
return ResponseEntity.ok(response);
}

@PatchMapping("/essay-answers/{essayAnswerId}")
public ResponseEntity<Void> updateById(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member,
@RequestBody EssayAnswerUpdateRequest request) {
essayAnswerService.updateEssayAnswer(essayAnswerId, request.getAnswer(), member.getId());
return ResponseEntity.ok().build();
}

@DeleteMapping("/essay-answers/{essayAnswerId}")
public ResponseEntity<Void> deleteQuiz(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member) {
public ResponseEntity<Void> deleteEssayAnswerById(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member) {
essayAnswerService.deleteEssayAnswer(essayAnswerId, member.getId());
return ResponseEntity.noContent().build();
}

@GetMapping("/quizzes/{quizId}")
public ResponseEntity<QuizResponse> findQuizById(@PathVariable Long quizId) {
public ResponseEntity<QuizResponse> findEssayAnswerById(@PathVariable Long quizId) {
return ResponseEntity.ok(quizService.findById(quizId));
}

Expand Down

0 comments on commit c86d537

Please sign in to comment.