Skip to content

Commit

Permalink
[Feat] 더미데이터 삭제 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
iiqcov committed Sep 6, 2024
1 parent af3eecb commit 972aed9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,23 @@ public ResponseEntity<Void> createQuiz(@RequestBody QuizCreateRequest request) {
return ResponseEntity.status(HttpStatus.OK)
.build();
}

@Operation(summary = "퀴즈 삭제")
@DeleteMapping("/quiz/{quizId}")
public void deleteQuiz(@PathVariable Long quizId) {
quizService.deleteQuiz(quizId);
}

@Operation(summary = "FAQ 삭제")
@DeleteMapping("/question/{quizId}")
public void deleteQuestion(@PathVariable Long questionId) {
questionService.deleteQuestion(questionId);
}

@Operation(summary = "배너 삭제")
@DeleteMapping("/banner/{bannerId}")
public void deleteBanner(@PathVariable Long bannerId) {
bannerService.deleteBanner(bannerId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import appjjang.fitpet.domain.banner.dao.BannerRepository;
import appjjang.fitpet.domain.banner.domain.Banner;
import appjjang.fitpet.domain.common.service.ImageService;
import appjjang.fitpet.global.error.exception.CustomException;
import appjjang.fitpet.global.error.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,4 +30,9 @@ public List<String> getBannerUrlList() {
.map(Banner::getBannerUrl)
.collect(Collectors.toList());
}

public void deleteBanner(Long bannerId) {
bannerRepository.delete(bannerRepository.findById(bannerId)
.orElseThrow(() -> new CustomException(ErrorCode.SAMPLE_ERROR)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import appjjang.fitpet.domain.question.dao.QuestionRepository;
import appjjang.fitpet.domain.question.domain.Question;
import appjjang.fitpet.domain.question.dto.request.FaqCreateRequest;
import appjjang.fitpet.global.error.exception.CustomException;
import appjjang.fitpet.global.error.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -35,4 +37,9 @@ public QuestionDto getQuestionTitleList() {
.map(Question::getTitle)
.collect(Collectors.toList()));
}

public void deleteQuestion(Long questionId) {
questionRepository.delete(questionRepository.findById(questionId)
.orElseThrow(() -> new CustomException(ErrorCode.SAMPLE_ERROR)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import appjjang.fitpet.domain.quiz.dao.QuizRepository;
import appjjang.fitpet.domain.quiz.domain.Quiz;
import appjjang.fitpet.domain.quiz.dto.QuizCreateRequest;
import appjjang.fitpet.global.error.exception.CustomException;
import appjjang.fitpet.global.error.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,6 +20,11 @@ public void saveQuiz(QuizCreateRequest request) {
quizRepository.save(Quiz.createQuiz(request.getQuestion(), request.isAnswer(), request.getDescription()));
}

public void deleteQuiz(Long quizId) {
quizRepository.delete(quizRepository.findById(quizId)
.orElseThrow(() -> new CustomException(ErrorCode.SAMPLE_ERROR)));
}

public QuizDto getRandomQuiz() {
return new QuizDto(quizRepository.findRandomQuiz());
}
Expand Down

0 comments on commit 972aed9

Please sign in to comment.