Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy 2.1 #199

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum ErrorStatus implements BaseErrorCode {
QUESTION_ALARM_ALREADY_EXISTS(HttpStatus.CONFLICT, "QUESTION_2004", "해당 질문에 대한 알람 설정이 이미 존재 하는 유저 입니다."),
QUESTION_ALARM_NOT_FOUND_BY_USER(HttpStatus.NOT_FOUND, "QUESTION_2005", "해당 유저가 설정한 알람은 존재 하지 않습니다."),
QUESTION_NOT_EXIST_BY_USER(HttpStatus.NOT_FOUND, "QUESTION_2006", "해당 유저가 작성한 질문은 존재 하지 않습니다."),
QUESTION_NOT_MATCH_BY_USER(HttpStatus.BAD_REQUEST, "QUESTION_2007", "질문을 작성한 유저 본인만 삭제할 수 있습니다."),

// 답변 관련 에러 3000
ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER_3001", "찾고있는 답변이 없습니다."),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/qp/official/qp/domain/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import qp.official.qp.domain.enums.ChildStatus;
import qp.official.qp.domain.enums.Role;
import qp.official.qp.domain.mapping.QuestionHashTag;
import qp.official.qp.domain.mapping.UserQuestionAlarm;
import qp.official.qp.web.dto.QuestionRequestDTO;

import javax.persistence.*;
Expand Down Expand Up @@ -52,6 +53,10 @@ public class Question extends BaseEntity {
@Builder.Default
private List<Answer> answers = new ArrayList<>();

@OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
@Builder.Default
private List<UserQuestionAlarm> alarms = new ArrayList<>();

public Question addHit() {
this.hit++;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface QuestionCommandService {

Question updateQuestion(Long questionId, QuestionRequestDTO.UpdateDTO request);

void deleteQuestion(Long questionId);
void deleteQuestion(Long questionId, Long userId);

UserQuestionAlarm saveQuestionAlarm(Long questionId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ public Question updateQuestion(Long questionId, QuestionRequestDTO.UpdateDTO req
}

@Override
public void deleteQuestion(Long questionId) {
public void deleteQuestion(Long questionId, Long userId) {
Question deleteQuestion = questionRepository.findById(questionId).get();
if (!deleteQuestion.getUser().getUserId().equals(userId)){
throw new QuestionHandler(ErrorStatus.QUESTION_NOT_MATCH_BY_USER);
}
questionRepository.delete(deleteQuestion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ApiResponse<?> deleteQuestion(
// accessToken으로 유효한 유저인지 인가
tokenService.isValidToken(userId);

questionCommandService.deleteQuestion(questionId);
questionCommandService.deleteQuestion(questionId,userId);
return ApiResponse.onSuccess(
SuccessStatus.Question_OK,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ void deleteQuestion() {
// when
// 질문 정보
Long questionId = 1L;
Long userId = 2L;
String title = "testTitle";
String content = "testContent";

User testUser = User.builder().userId(userId).build();

//예상 질문 객체 생성
// given
Question expectQuestion = Question.builder()
.questionId(questionId)
.user(testUser)
.title(title)
.content(content)
.questionHashTagList(new ArrayList<>())
Expand All @@ -175,7 +179,7 @@ void deleteQuestion() {
when(questionRepository.findById(questionId)).thenReturn(Optional.of(expectQuestion));

//질문 삭제
questionCommandService.deleteQuestion(questionId);
questionCommandService.deleteQuestion(questionId, userId);

//verify
verify(questionRepository).delete(expectQuestion);
Expand Down
Loading