Skip to content

Commit

Permalink
feat: deletdQuestion API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
kyxxgsoo committed Feb 29, 2024
1 parent 7a3e3bf commit 3c21ead
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
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 java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
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;
Expand All @@ -32,4 +35,15 @@ public BaseResponse<QuestionId> createQuestion(

return BaseResponse.onSuccess(adminQuestionService.createQuestion(request));
}

@Operation(summary = "질문 삭제 API", description = "질문을 삭제합니다. 삭제할 질문의 ID를 입력하세요")
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "성공,")
})
@DeleteMapping("/{questionId}")
public BaseResponse<QuestionId> deleteQuestion(
@PathVariable(value = "questionId") Long questionId) {

return BaseResponse.onSuccess(adminQuestionService.deleteQuestion(questionId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface AdminQuestionService {

QuestionId createQuestion(QuestionCreate request);

QuestionId deleteQuestion(Long questionId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import com.server.capple.domain.question.entity.Question;
import com.server.capple.domain.question.mapper.QuestionMapper;
import com.server.capple.domain.question.repository.AdminQuestionRepository;
import com.server.capple.global.exception.RestApiException;
import com.server.capple.global.exception.errorCode.QuestionErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand All @@ -21,4 +24,15 @@ public QuestionId createQuestion(QuestionCreate request) {

return questionMapper.toQuestionId(question);
}

@Override
@Transactional
public QuestionId deleteQuestion(Long questionId) {
Question question = adminQuestionRepository.findById(questionId).orElseThrow(() -> new RestApiException(
QuestionErrorCode.EMPTY_QUESTION));

question.delete();

return questionMapper.toQuestionId(question);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.server.capple.global.exception.errorCode;

import com.server.capple.global.exception.ErrorCode;
import com.server.capple.global.exception.ErrorCodeInterface;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum QuestionErrorCode implements ErrorCodeInterface {
EMPTY_QUESTION("QUESTION001", "존재하지 않는 질문입니다.", HttpStatus.BAD_REQUEST),
;

private final String code;
private final String message;
private final HttpStatus httpStatus;

@Override
public ErrorCode getErrorCode() {
return ErrorCode.builder()
.code(code)
.message(message)
.httpStatus(httpStatus)
.build();
}
}

0 comments on commit 3c21ead

Please sign in to comment.