-
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: 문의사항 삭제 API 구현 (#32) - 문의사항 삭제 기능 - 잘못된 문의사항 ID -> 예외처리 * Feat: 문의사항 삭제 API 테스트코드 작성 (#57) - 삭제 기능 테스트코드 - Question ID가 없을 때 예외 처리 테스트코드 * Fix: 테스트용 반복문 삭제
- Loading branch information
1 parent
fc32917
commit 5d6698f
Showing
7 changed files
with
144 additions
and
6 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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/kea/enter/enterbe/api/question/service/dto/DeleteQuestionServiceDto.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,26 @@ | ||
package kea.enter.enterbe.api.question.service.dto; | ||
|
||
import kea.enter.enterbe.api.penalty.service.dto.DeletePenaltyServiceDto; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class DeleteQuestionServiceDto { | ||
private Long memberId; | ||
private Long questionId; | ||
|
||
@Builder | ||
public DeleteQuestionServiceDto(Long memberId, Long questionId) { | ||
this.memberId = memberId; | ||
this.questionId = questionId; | ||
} | ||
|
||
public static DeleteQuestionServiceDto of(Long memberId, Long questionId) { | ||
return DeleteQuestionServiceDto.builder() | ||
.memberId(memberId) | ||
.questionId(questionId) | ||
.build(); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package kea.enter.enterbe.domain.question.repository; | ||
|
||
import kea.enter.enterbe.domain.member.entity.Member; | ||
import kea.enter.enterbe.domain.penalty.entity.Penalty; | ||
import kea.enter.enterbe.domain.question.entity.Question; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface QuestionRepository extends JpaRepository<Question, Long> { | ||
Optional<Question> findByIdAndMemberId(Long penaltyId, Long memberId); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package kea.enter.enterbe.api.question.service; | ||
|
||
import kea.enter.enterbe.IntegrationTestSupport; | ||
import kea.enter.enterbe.api.penalty.service.dto.DeletePenaltyServiceDto; | ||
import kea.enter.enterbe.api.question.controller.dto.request.QuestionRequestDto; | ||
import kea.enter.enterbe.api.question.service.dto.DeleteQuestionServiceDto; | ||
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.penalty.entity.Penalty; | ||
import kea.enter.enterbe.domain.penalty.entity.PenaltyState; | ||
import kea.enter.enterbe.domain.question.entity.Question; | ||
import kea.enter.enterbe.domain.question.entity.QuestionCategory; | ||
import kea.enter.enterbe.domain.question.entity.QuestionState; | ||
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 java.util.Optional; | ||
|
||
import static kea.enter.enterbe.domain.penalty.entity.PenaltyLevel.BLACKLIST; | ||
import static kea.enter.enterbe.domain.penalty.entity.PenaltyReason.BROKEN; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.tuple; | ||
|
@@ -62,8 +70,56 @@ public void testCreateQuestion_MemberNotFound() { | |
assertThat(exception.getResponseCode()).isEqualTo(ResponseCode.NOT_FOUND_MEMBER); | ||
} | ||
|
||
@DisplayName(value = "문의사항을 삭제한다.") | ||
@Test | ||
public void deleteQuestion() { | ||
//given | ||
Member member = memberRepository.save(createMember()); | ||
Long memberId = member.getId(); | ||
|
||
Question question = questionRepository.save(createQuestion(member)); | ||
Long questionId = question.getId(); | ||
|
||
DeleteQuestionServiceDto dto = DeleteQuestionServiceDto.of(memberId, questionId); | ||
|
||
//when | ||
questionService.deleteQuestion(dto); | ||
|
||
//then | ||
Optional<Question> result = questionRepository.findByIdAndMemberId(questionId, memberId); | ||
assertThat(result).isPresent(); | ||
|
||
assertThat(result.get()) | ||
.extracting("state") | ||
.isEqualTo(QuestionState.INACTIVE); | ||
} | ||
|
||
@DisplayName(value = "존재하는 문의사항 ID인지 검사한다") | ||
@Test | ||
public void questionNotFound() { | ||
// given | ||
Member member = memberRepository.save(createMember()); | ||
Long memberId = member.getId(); | ||
Long testQuestionId = 5L; | ||
|
||
Question question = questionRepository.save(createQuestion(member)); | ||
|
||
DeleteQuestionServiceDto dto = DeleteQuestionServiceDto.of(memberId, testQuestionId); | ||
|
||
// when & then | ||
CustomException exception = assertThrows(CustomException.class, () -> { | ||
questionService.deleteQuestion(dto); | ||
}); | ||
|
||
assertThat(exception.getResponseCode()).isEqualTo(ResponseCode.NOT_FOUND_QUESTION); | ||
} | ||
|
||
private Member createMember() { | ||
return Member.of("2", "name", "[email protected]", "password", "licenseId", | ||
"licensePassword", true, true, 1, MemberRole.USER, MemberState.ACTIVE); | ||
} | ||
|
||
private Question createQuestion(Member member) { | ||
return Question.of(member, "content", QuestionCategory.USER, QuestionState.WAIT); | ||
} | ||
} |