|
|
@@ -0,0 +1,54 @@
|
|
|
+package com.seec.bok.service;
|
|
|
+
|
|
|
+import com.seec.bok.back.entity.CodeQuestion;
|
|
|
+import com.seec.bok.back.entity.Question;
|
|
|
+import com.seec.bok.back.repository.CodeQuestionRepository;
|
|
|
+import com.seec.bok.service.exception.EntityNotFoundException;
|
|
|
+import com.seec.bok.web.vo.CodeQuestionVO;
|
|
|
+import com.seec.bok.web.vo.PageVO;
|
|
|
+import com.seec.bok.web.vo.QuestionVO;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class CodeQuestionService {
|
|
|
+ @Autowired
|
|
|
+ private CodeQuestionRepository codeQuestionRepository;
|
|
|
+
|
|
|
+ public CodeQuestionVO saveNewOne(CodeQuestionVO s){
|
|
|
+ CodeQuestion codeQuestion = s.toEntity();
|
|
|
+ codeQuestion.setLastModifiedAt(DateTime.now());
|
|
|
+ codeQuestion.setId(UUID.randomUUID().toString());
|
|
|
+ codeQuestion = codeQuestionRepository.save(codeQuestion);
|
|
|
+ return CodeQuestionVO.of(codeQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CodeQuestionVO updateOne(CodeQuestionVO s){
|
|
|
+ CodeQuestion question = codeQuestionRepository.findById(s.getId()).orElseThrow(EntityNotFoundException::new);
|
|
|
+ question.setLastModifiedAt(DateTime.now());
|
|
|
+ question = codeQuestionRepository.save(question);
|
|
|
+ return CodeQuestionVO.of(question);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CodeQuestionVO findById(String id){
|
|
|
+ final CodeQuestion question = codeQuestionRepository.findById(id).orElseThrow(EntityNotFoundException::new);
|
|
|
+ return CodeQuestionVO.of(question);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<CodeQuestionVO> findAllByTitle(String title, Pageable pageable){
|
|
|
+ Page<CodeQuestion> questionPage = codeQuestionRepository.findAllByTitleLike(title,pageable);
|
|
|
+ return questionPage.map(CodeQuestionVO::of);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<CodeQuestionVO> findAll(Pageable pageable){
|
|
|
+ Page<CodeQuestion> questionPage = codeQuestionRepository.findAll(pageable);
|
|
|
+ return questionPage.map(CodeQuestionVO::of);
|
|
|
+ }
|
|
|
+}
|