-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: 문의사항 작성 기능 구현 (#32) - 사용자가 문의사항 작성 시 DB에 저장 기능 구현 * Feat: 문의사항 작성에 대한 예외처리(#32) - 작성자 ID가 없는 경우 - 본문 내용이 없는 경우 - 카테고리 선택을 안 한 경우 * Fix: Response 내용 변경 (#32) - Response Dto 추가 * Feat: 문의사항 테스트 코드 작성 (#32) - 문의사항 저장 기능 - 존재하는 멤버 ID인지 검사 * Feat: Swagger 추가 (#32) * Fix: PR message 수정 (#32) - URI 수정 - @parameters를 @Schema로 수정 - Member검사할 때 state 조건 수정 - question폴더 내부 ExampleDto파일 삭제 - gitignore수정
- Loading branch information
1 parent
bbf1459
commit bde3b3d
Showing
12 changed files
with
230 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Temp Data ### | ||
src/main/resources/data.sql |
45 changes: 45 additions & 0 deletions
45
src/main/java/kea/enter/enterbe/api/question/controller/QuestionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kea.enter.enterbe.api.question.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import kea.enter.enterbe.api.question.controller.dto.request.QuestionRequestDto; | ||
import kea.enter.enterbe.api.question.controller.dto.response.QuestionResponseDto; | ||
import kea.enter.enterbe.api.question.service.QuestionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
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; | ||
|
||
@RestController | ||
@RequestMapping("/questions") | ||
@RequiredArgsConstructor | ||
@Tag(name = "문의사항 작성", description = "문의사항 작성 API") | ||
public class QuestionController { | ||
|
||
private final QuestionService questionService; | ||
|
||
@Operation(summary = "사용자가 작성한 문의사항 저장") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "작성이 완료되었습니다.", content = @Content(mediaType = "application/json")), | ||
@ApiResponse(responseCode = "MEM-ERR-001", description = "멤버가 존재하지 않습니다.", content = @Content(mediaType = "application/json")), | ||
@ApiResponse(responseCode = "GLB-ERR-001", description = "필수 입력칸이 입력되지 않았습니다.", content = @Content(mediaType = "application/json")), | ||
}) | ||
@PostMapping | ||
public ResponseEntity<QuestionResponseDto> createQuestion( | ||
@Valid @RequestBody QuestionRequestDto dto) { | ||
|
||
questionService.createQuestion(dto); | ||
|
||
QuestionResponseDto responseDto = new QuestionResponseDto("작성이 완료되었습니다."); | ||
return new ResponseEntity<>(responseDto, HttpStatus.CREATED); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/kea/enter/enterbe/api/question/controller/dto/request/QuestionRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package kea.enter.enterbe.api.question.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import kea.enter.enterbe.domain.question.entity.QuestionCategory; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class QuestionRequestDto { | ||
|
||
@NotNull(message = "멤버 아이디를 입력해야 합니다.") | ||
@Schema(description = "멤버 ID", example = "2") | ||
private Long memberId; | ||
@NotBlank(message = "내용을 입력해야 합니다.") | ||
@Schema(description = "문의사항 내용", example = "추첨 날짜는 언제인가요?") | ||
private String content; | ||
@NotNull(message = "카테고리를 입력해야 합니다.") | ||
@Schema(description = "문의사항 카테고리(USER, SERVICE, VEHICLE, ETC)", example = "USER") | ||
private QuestionCategory category; | ||
|
||
} | ||
|
11 changes: 11 additions & 0 deletions
11
...main/java/kea/enter/enterbe/api/question/controller/dto/response/QuestionResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kea.enter.enterbe.api.question.controller.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class QuestionResponseDto { | ||
|
||
private String message; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/kea/enter/enterbe/api/question/service/QuestionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kea.enter.enterbe.api.question.service; | ||
|
||
import kea.enter.enterbe.api.question.controller.dto.request.QuestionRequestDto; | ||
import kea.enter.enterbe.domain.member.entity.Member; | ||
import kea.enter.enterbe.domain.member.entity.MemberState; | ||
import kea.enter.enterbe.domain.member.repository.MemberRepository; | ||
import kea.enter.enterbe.domain.question.entity.Question; | ||
import kea.enter.enterbe.domain.question.entity.QuestionState; | ||
import kea.enter.enterbe.domain.question.repository.QuestionRepository; | ||
import kea.enter.enterbe.global.common.exception.CustomException; | ||
import kea.enter.enterbe.global.common.exception.ResponseCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class QuestionService { | ||
|
||
private final QuestionRepository questionRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public void createQuestion(QuestionRequestDto dto) { | ||
Member member = memberRepository.findByIdAndState(dto.getMemberId(), MemberState.ACTIVE) | ||
.orElseThrow(() -> new CustomException(ResponseCode.NOT_FOUND_MEMBER)); | ||
|
||
// state는 작성시에 WAIT로 기본값 고정 | ||
Question question = Question.of(member, dto.getContent(), dto.getCategory(), | ||
QuestionState.WAIT); | ||
questionRepository.save(question); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/kea/enter/enterbe/domain/question/repository/QuestionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kea.enter.enterbe.domain.question.repository; | ||
|
||
import kea.enter.enterbe.domain.question.entity.Question; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface QuestionRepository extends JpaRepository<Question, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/java/kea/enter/enterbe/api/question/service/QuestionServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package kea.enter.enterbe.api.question.service; | ||
|
||
import kea.enter.enterbe.IntegrationTestSupport; | ||
import kea.enter.enterbe.api.question.controller.dto.request.QuestionRequestDto; | ||
import kea.enter.enterbe.domain.member.entity.Member; | ||
import kea.enter.enterbe.domain.member.entity.MemberRole; | ||
import kea.enter.enterbe.domain.member.entity.MemberState; | ||
import kea.enter.enterbe.domain.question.entity.Question; | ||
import kea.enter.enterbe.domain.question.entity.QuestionCategory; | ||
import kea.enter.enterbe.global.common.exception.CustomException; | ||
import kea.enter.enterbe.global.common.exception.ResponseCode; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.tuple; | ||
|
||
public class QuestionServiceTest extends IntegrationTestSupport { | ||
|
||
@DisplayName(value = "문의사항을 저장한다") | ||
@Test | ||
public void testCreateQuestion_Success() { | ||
String questionContentTest = "문의사항 테스트 문장"; | ||
Member member = createMember(); | ||
memberRepository.save(member); | ||
|
||
// given | ||
QuestionRequestDto requestDto = new QuestionRequestDto(member.getId(), questionContentTest, | ||
QuestionCategory.USER); | ||
|
||
// when | ||
questionService.createQuestion(requestDto); | ||
|
||
//then | ||
List<Question> questionList = questionRepository.findAll(); | ||
assertThat(questionList).hasSize(1) | ||
.extracting("member.id", "content", "category") | ||
.containsExactlyInAnyOrder( | ||
tuple(member.getId(), questionContentTest, QuestionCategory.USER) | ||
); | ||
} | ||
|
||
@DisplayName(value = "존재하는 멤버 ID인지 검사한다") | ||
@Test | ||
public void testCreateQuestion_MemberNotFound() { | ||
Long memberIdTest = 1L; | ||
String questionContentTest = "문의사항 테스트 문장"; | ||
Member member = createMember(); | ||
memberRepository.save(member); | ||
|
||
// given | ||
QuestionRequestDto requestDto = new QuestionRequestDto(memberIdTest, questionContentTest, | ||
QuestionCategory.USER); | ||
|
||
// when & then | ||
CustomException exception = assertThrows(CustomException.class, () -> { | ||
questionService.createQuestion(requestDto); | ||
}); | ||
|
||
assertThat(exception.getResponseCode()).isEqualTo(ResponseCode.NOT_FOUND_MEMBER); | ||
} | ||
|
||
private Member createMember() { | ||
return Member.of("2", "name", "[email protected]", "password", "licenseId", | ||
"licensePassword", true, true, 1, MemberRole.USER, MemberState.ACTIVE); | ||
} | ||
} |