Skip to content

Commit

Permalink
fix/83: 템플릿 조회 리뷰 사항 반영 (#85)
Browse files Browse the repository at this point in the history
* chore: 필요없는 로그 코드 삭제

* chore: 모든 템플릿 조회 FormType으로 변경

* chore: 기본 템플릿 아이디 리스트 삭제

* chore: application-dev 수정
  • Loading branch information
clean2001 authored Aug 3, 2024
1 parent e86b86b commit c9e5f54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import org.layer.domain.template.repository.TemplateMetadataRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static org.layer.domain.form.entity.FormType.TEMPLATE;

@Slf4j
@RequiredArgsConstructor
@Service
Expand All @@ -27,8 +28,6 @@ public class TemplateService {
private final QuestionRepository questionRepository;
private final QuestionDescriptionRepository questionDescriptionRepository;

private static List<Long> templateIds = new ArrayList<>(List.of(10000L, 10001L, 10002L, 10003L, 10004L, 10005L));

//== 간단 정보 단건 조회 ==//
public TemplateSimpleInfoResponse getTemplateSimpleInfo(Long formId) {
Form form = formRepository.findByIdOrThrow(formId);
Expand All @@ -42,7 +41,6 @@ public TemplateDetailInfoResponse getTemplateDetailInfo(Long formId) {
TemplateMetadata template = templateMetadataRepository.findByFormIdOrThrow(formId);
List<Question> questionList = questionRepository.findAllByFormId(formId);

log.info("line 40: {}", questionList);

List<TemplateDetailQuestionResponse> questionDesList = questionList.stream().map(q -> {
QuestionDescription description = questionDescriptionRepository.findByQuestionIdOrThrow(q.getId());
Expand All @@ -58,7 +56,7 @@ public TemplateDetailInfoResponse getTemplateDetailInfo(Long formId) {

//== 모든 템플릿 리스트 간단 정보 조회 ==//
public List<TemplateSimpleInfoResponse> getAllTemplates() {
List<Form> forms = formRepository.findAllById(templateIds);
List<Form> forms = formRepository.findByFormTypeOrderById(TEMPLATE);

return forms.stream().map(form -> {
TemplateMetadata metadata = templateMetadataRepository.findByFormIdOrThrow(form.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.layer.domain.form.repository;

import static org.layer.common.exception.FormExceptionType.*;

import org.layer.domain.form.entity.Form;
import org.layer.domain.form.entity.FormType;
import org.layer.domain.form.exception.FormException;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

import static org.layer.common.exception.FormExceptionType.NOT_FOUND_FORM;

public interface FormRepository extends JpaRepository<Form, Long> {
default Form findByIdOrThrow(Long formId) {
return findById(formId)
.orElseThrow(() -> new FormException(NOT_FOUND_FORM));
}

List<Form> findByFormTypeOrderById(FormType formType);


}

0 comments on commit c9e5f54

Please sign in to comment.