Skip to content

Commit

Permalink
Feat: QuestionPaper 생성 로직 구현
Browse files Browse the repository at this point in the history
[#49]
  • Loading branch information
MuseopKim committed Jun 28, 2021
1 parent 7cfd9dc commit 2df95c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface QuestionPaperFormRepository extends JpaRepository<QuestionPaperForm, Long> {

QuestionPaperForm findFirstByOrderByIdDesc();
}
15 changes: 15 additions & 0 deletions src/main/java/com/careerzip/global/admin/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@
import com.careerzip.domain.question.service.QuestionService;
import com.careerzip.domain.questionpaper.entity.QuestionPaper;
import com.careerzip.domain.questionpaper.repository.QuestionPaperRepository;
import com.careerzip.domain.questionpaperform.entity.QuestionPaperForm;
import com.careerzip.domain.questionpaperform.repository.QuestionPaperFormRepository;
import com.careerzip.global.admin.dto.request.CreateQuestionPaperRequest;
import com.careerzip.global.admin.dto.request.DateParameters;
import com.careerzip.global.admin.dto.response.AdminArchiveResponse;
import com.careerzip.global.admin.dto.response.AdminArchivesResponse;
import com.careerzip.global.admin.dto.response.AdminQuestionPaperDetail;
import com.careerzip.global.admin.dto.response.ArchiveRelatedData;
import com.careerzip.global.error.exception.entity.ArchiveNotFoundException;
import com.careerzip.global.error.exception.entity.QuestionPaperNotFoundException;
import com.careerzip.global.pagination.CustomPageRequest;
import com.careerzip.global.pagination.Pagination;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;
Expand All @@ -34,6 +39,7 @@ public class AdminService {

private final ArchiveRepository archiveRepository;
private final QuestionPaperRepository questionPaperRepository;
private final QuestionPaperFormRepository questionPaperFormRepository;
private final ProjectService projectService;
private final QuestionService questionService;
private final AnswerService answerService;
Expand All @@ -59,4 +65,13 @@ public List<AdminQuestionPaperDetail> findAllQuestionPapers() {
List<QuestionPaper> questionPapers = questionPaperRepository.findAllByOrderByIdDesc();
return AdminQuestionPaperDetail.listOf(questionPapers);
}

@Transactional
public AdminQuestionPaperDetail createQuestionPaper(CreateQuestionPaperRequest request) {
QuestionPaper questionPaper = questionPaperRepository.findLatest().orElseThrow(QuestionPaperNotFoundException::new);
questionPaper.finishPaper();
QuestionPaperForm questionPaperForm = questionPaperFormRepository.findFirstByOrderByIdDesc();
QuestionPaper newQuestionPaper = questionPaperRepository.save(request.toEntity(questionPaperForm));
return AdminQuestionPaperDetail.from(newQuestionPaper);
}
}

0 comments on commit 2df95c0

Please sign in to comment.