-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/#23 문항, 새끼문항 도메인 생성, 수정, 삭제 API 구현 #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b21007
Merge remote-tracking branch 'origin/develop' into feature/#23
sejoon00 8f5d865
[feat/#23] 문항 생성, 수정, 조회 api
sejoon00 6f03ad4
Merge remote-tracking branch 'origin/develop' into feature/#23
sejoon00 43c8501
[feat/#23] mapStruct를 통한 dto -> 객체 mapper 구현 및 테스트
sejoon00 4f07260
[fix/#23] insert-problem.sql에 childProblem 데이터 삭제 sql 추가
sejoon00 22c15cf
[fix/#23] updateChildProblem에서 필요없는 코드 삭제
sejoon00 c389d79
[feature/#23] 모의고사 목록 조회 swagger 설명 추가
sejoon00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...erated/com/moplus/moplus_server/domain/problem/service/mapper/ChildProblemMapperImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.moplus.moplus_server.domain.problem.service.mapper; | ||
|
|
||
| import com.moplus.moplus_server.domain.problem.domain.childProblem.ChildProblem; | ||
| import com.moplus.moplus_server.domain.problem.dto.request.ChildProblemPostRequest; | ||
| import com.moplus.moplus_server.domain.problem.dto.request.ChildProblemUpdateRequest; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import javax.annotation.processing.Generated; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2025-01-30T21:11:35+0900", | ||
| comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)" | ||
| ) | ||
| @Component | ||
| public class ChildProblemMapperImpl implements ChildProblemMapper { | ||
|
|
||
| @Override | ||
| public ChildProblem from(ChildProblemPostRequest request) { | ||
| if ( request == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| ChildProblem.ChildProblemBuilder childProblem = ChildProblem.builder(); | ||
|
|
||
| childProblem.imageUrl( request.imageUrl() ); | ||
| childProblem.problemType( request.problemType() ); | ||
| childProblem.answer( request.answer() ); | ||
| Set<Long> set = request.conceptTagIds(); | ||
| if ( set != null ) { | ||
| childProblem.conceptTagIds( new LinkedHashSet<Long>( set ) ); | ||
| } | ||
| childProblem.sequence( request.sequence() ); | ||
|
|
||
| return childProblem.build(); | ||
| } | ||
|
|
||
| @Override | ||
| public ChildProblem from(ChildProblemUpdateRequest request) { | ||
| if ( request == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| ChildProblem.ChildProblemBuilder childProblem = ChildProblem.builder(); | ||
|
|
||
| childProblem.imageUrl( request.imageUrl() ); | ||
| childProblem.problemType( request.problemType() ); | ||
| childProblem.answer( request.answer() ); | ||
| Set<Long> set = request.conceptTagIds(); | ||
| if ( set != null ) { | ||
| childProblem.conceptTagIds( new LinkedHashSet<Long>( set ) ); | ||
| } | ||
| childProblem.sequence( request.sequence() ); | ||
|
|
||
| return childProblem.build(); | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
...n/generated/com/moplus/moplus_server/domain/problem/service/mapper/ProblemMapperImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.moplus.moplus_server.domain.problem.service.mapper; | ||
|
|
||
| import com.moplus.moplus_server.domain.problem.domain.practiceTest.PracticeTestTag; | ||
| import com.moplus.moplus_server.domain.problem.domain.problem.Problem; | ||
| import com.moplus.moplus_server.domain.problem.domain.problem.ProblemId; | ||
| import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest; | ||
| import com.moplus.moplus_server.domain.problem.dto.request.ProblemUpdateRequest; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import javax.annotation.processing.Generated; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2025-01-30T21:11:35+0900", | ||
| comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)" | ||
| ) | ||
| @Component | ||
| public class ProblemMapperImpl implements ProblemMapper { | ||
|
|
||
| @Override | ||
| public Problem from(ProblemPostRequest request, ProblemId problemId, PracticeTestTag practiceTestTag) { | ||
| if ( request == null && problemId == null && practiceTestTag == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| Problem.ProblemBuilder problem = Problem.builder(); | ||
|
|
||
| if ( request != null ) { | ||
| problem.number( request.number() ); | ||
| problem.answer( request.answer() ); | ||
| problem.comment( request.comment() ); | ||
| problem.mainProblemImageUrl( request.mainProblemImageUrl() ); | ||
| problem.mainAnalysisImageUrl( request.mainAnalysisImageUrl() ); | ||
| problem.readingTipImageUrl( request.readingTipImageUrl() ); | ||
| problem.seniorTipImageUrl( request.seniorTipImageUrl() ); | ||
| problem.prescriptionImageUrl( request.prescriptionImageUrl() ); | ||
| Set<Long> set = request.conceptTagIds(); | ||
| if ( set != null ) { | ||
| problem.conceptTagIds( new LinkedHashSet<Long>( set ) ); | ||
| } | ||
| } | ||
| problem.id( problemId ); | ||
| problem.practiceTestTag( practiceTestTag ); | ||
|
|
||
| return problem.build(); | ||
| } | ||
|
|
||
| @Override | ||
| public Problem from(ProblemUpdateRequest request, ProblemId problemId, PracticeTestTag practiceTestTag) { | ||
| if ( request == null && problemId == null && practiceTestTag == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| Problem.ProblemBuilder problem = Problem.builder(); | ||
|
|
||
| if ( request != null ) { | ||
| problem.answer( String.valueOf( request.answer() ) ); | ||
| problem.comment( request.comment() ); | ||
| problem.mainProblemImageUrl( request.mainProblemImageUrl() ); | ||
| problem.mainAnalysisImageUrl( request.mainAnalysisImageUrl() ); | ||
| problem.readingTipImageUrl( request.readingTipImageUrl() ); | ||
| problem.seniorTipImageUrl( request.seniorTipImageUrl() ); | ||
| problem.prescriptionImageUrl( request.prescriptionImageUrl() ); | ||
| Set<Long> set = request.conceptTagIds(); | ||
| if ( set != null ) { | ||
| problem.conceptTagIds( new LinkedHashSet<Long>( set ) ); | ||
| } | ||
| } | ||
| problem.id( problemId ); | ||
| problem.practiceTestTag( practiceTestTag ); | ||
|
|
||
| return problem.build(); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/moplus/moplus_server/domain/concept/controller/ConceptTagController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.moplus.moplus_server.domain.concept.controller; | ||
|
|
||
| import com.moplus.moplus_server.domain.concept.dto.response.ConceptTagResponse; | ||
| import com.moplus.moplus_server.domain.concept.repository.ConceptTagRepository; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/v1/conceptTags") | ||
| @RequiredArgsConstructor | ||
| public class ConceptTagController { | ||
|
|
||
| ConceptTagRepository conceptTagRepository; | ||
|
|
||
| @GetMapping("") | ||
| @Operation(summary = "모든 개념 태그 리스트 조회") | ||
| public ResponseEntity<List<ConceptTagResponse>> getConceptTags( | ||
| ) { | ||
| List<ConceptTagResponse> responses = conceptTagRepository.findAll().stream() | ||
| .map(ConceptTagResponse::of) | ||
| .toList(); | ||
| return ResponseEntity.ok(responses); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/moplus/moplus_server/domain/concept/dto/response/ConceptTagResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.moplus.moplus_server.domain.concept.dto.response; | ||
|
|
||
| import com.moplus.moplus_server.domain.concept.domain.ConceptTag; | ||
|
|
||
| public record ConceptTagResponse( | ||
| Long id, | ||
| String name | ||
| ) { | ||
| public static ConceptTagResponse of(ConceptTag entity) { | ||
| return new ConceptTagResponse( | ||
| entity.getId(), | ||
| entity.getName() | ||
| ); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/moplus/moplus_server/domain/concept/repository/ConceptTagRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,21 @@ | ||
| package com.moplus.moplus_server.domain.concept.repository; | ||
|
|
||
| import com.moplus.moplus_server.domain.concept.domain.ConceptTag; | ||
| import com.moplus.moplus_server.global.error.exception.ErrorCode; | ||
| import com.moplus.moplus_server.global.error.exception.NotFoundException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ConceptTagRepository extends JpaRepository<ConceptTag, Long> { | ||
|
|
||
| default void existsByIdElseThrow(Set<Long> ids) { | ||
| List<Long> foundIds = findAllById(ids).stream() | ||
| .map(ConceptTag::getId) // 엔티티의 ID 추출 | ||
| .toList(); | ||
|
|
||
| if (ids.size() != foundIds.size()) { | ||
| throw new NotFoundException(ErrorCode.CONCEPT_TAG_NOT_FOUND_IN_LIST); | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...in/java/com/moplus/moplus_server/domain/problem/controller/PracticeTestTagController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.moplus.moplus_server.domain.problem.controller; | ||
|
|
||
| import com.moplus.moplus_server.domain.problem.dto.response.PracticeTestTagResponse; | ||
| import com.moplus.moplus_server.domain.problem.repository.PracticeTestTagRepository; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/v1/practiceTestTags") | ||
| @RequiredArgsConstructor | ||
| public class PracticeTestTagController { | ||
|
|
||
| private final PracticeTestTagRepository practiceTestTagRepository; | ||
|
|
||
| @GetMapping("") | ||
| @Operation(summary = "모의고사 목록 조회") | ||
| public ResponseEntity<List<PracticeTestTagResponse>> getPracticeTestTags() { | ||
| List<PracticeTestTagResponse> responses = practiceTestTagRepository.findAll().stream() | ||
| .map(PracticeTestTagResponse::of) | ||
| .toList(); | ||
| return ResponseEntity.ok(responses); | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
src/main/java/com/moplus/moplus_server/domain/problem/controller/ProblemController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.moplus.moplus_server.domain.problem.controller; | ||
|
|
||
| import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest; | ||
| import com.moplus.moplus_server.domain.problem.dto.request.ProblemUpdateRequest; | ||
| import com.moplus.moplus_server.domain.problem.dto.response.ProblemGetResponse; | ||
| import com.moplus.moplus_server.domain.problem.service.ProblemDeleteService; | ||
| import com.moplus.moplus_server.domain.problem.service.ProblemGetService; | ||
| import com.moplus.moplus_server.domain.problem.service.ProblemSaveService; | ||
| import com.moplus.moplus_server.domain.problem.service.ProblemUpdateService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| 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; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/v1/problems") | ||
| @RequiredArgsConstructor | ||
| public class ProblemController { | ||
|
|
||
| private final ProblemSaveService problemSaveService; | ||
| private final ProblemUpdateService problemUpdateService; | ||
| private final ProblemGetService problemGetService; | ||
| private final ProblemDeleteService problemDeleteService; | ||
|
|
||
| @GetMapping("/{id}") | ||
| @Operation(summary = "문항 조회", description = "문항를 조회합니다.") | ||
| public ResponseEntity<ProblemGetResponse> getProblem( | ||
| @PathVariable("id") String id | ||
| ) { | ||
| return ResponseEntity.ok(problemGetService.getProblem(id)); | ||
| } | ||
|
|
||
| @PostMapping("") | ||
| @Operation(summary = "문항 생성", description = "문제를 생성합니다. 새끼 문항은 list 순서대로 sequence를 저장합니다.") | ||
| public ResponseEntity<String> createProblem( | ||
| @RequestBody ProblemPostRequest request | ||
| ) { | ||
| return ResponseEntity.ok(problemSaveService.createProblem(request).toString()); | ||
| } | ||
|
|
||
| @PostMapping("/{id}") | ||
| @Operation(summary = "문항 업데이트", description = "문제를 업데이트합니다. 문항 번호, 모의고사는 수정할 수 없습니다. 새로 추가되는 새끼문항 id는 빈 값입니다.") | ||
| public ResponseEntity<ProblemGetResponse> updateProblem( | ||
| @PathVariable("id") String id, | ||
| @RequestBody ProblemUpdateRequest request | ||
| ) { | ||
| return ResponseEntity.ok(problemUpdateService.updateProblem(id, request)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| @Operation(summary = "문항 삭제") | ||
| public ResponseEntity<ProblemGetResponse> updateProblem( | ||
| @PathVariable("id") String id | ||
| ) { | ||
| problemDeleteService.deleteProblem(id); | ||
| return ResponseEntity.ok().body(null); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/moplus/moplus_server/domain/problem/domain/Answer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.moplus.moplus_server.domain.problem.domain; | ||
|
|
||
| import com.moplus.moplus_server.domain.problem.domain.problem.ProblemType; | ||
| import com.moplus.moplus_server.global.error.exception.ErrorCode; | ||
| import com.moplus.moplus_server.global.error.exception.InvalidValueException; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Embeddable; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Embeddable | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Answer { | ||
|
|
||
| @Column(name = "answer") | ||
| private String value; | ||
|
|
||
| public Answer(String value, ProblemType problemType) { | ||
| validateByType(value, problemType); | ||
| this.value = value; | ||
| } | ||
|
|
||
| private void validateByType(String answer, ProblemType problemType) { | ||
| if (answer.isBlank()) { | ||
| throw new InvalidValueException(ErrorCode.BLANK_INPUT_VALUE); | ||
| } | ||
| if (problemType == ProblemType.MULTIPLE_CHOICE) { | ||
| if (!answer.matches("^[1-5]*$")) { | ||
| throw new InvalidValueException(ErrorCode.INVALID_MULTIPLE_CHOICE_ANSWER); | ||
| } | ||
| } | ||
| if (problemType == ProblemType.SHORT_NUMBER_ANSWER) { | ||
| try { | ||
| int numericAnswer = Integer.parseInt(answer); | ||
| if (numericAnswer < 0 || numericAnswer > 999) { | ||
| throw new InvalidValueException(ErrorCode.INVALID_SHORT_NUMBER_ANSWER); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| throw new InvalidValueException(ErrorCode.INVALID_SHORT_NUMBER_ANSWER); | ||
| } | ||
| } | ||
|
Comment on lines
+25
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answer 클래스로 분리하여 유효성 검증까지 도메인 레벨에서 수행하는거 너무 좋은 것 같습니다! |
||
| } | ||
| } | ||
35 changes: 0 additions & 35 deletions
35
src/main/java/com/moplus/moplus_server/domain/problem/domain/ChildProblem.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단순 조회기 떄문에 로직이 무겁지 않아서, 서비스 레이어를 사용하지 않은 걸까요? 컨트롤러 레이어에서 바로 DB를 조회한 이유가 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조회 이외에 다른 로직이 없고 조회로직이라 트랜잭션이 필요하지 않아 굳이 서비스 레이어를 만들면 복잡도만 올릴 것이라 판단했습니다!