diff --git a/backend/src/main/java/in/backend/core/question/application/QuestionSaveCommand.java b/backend/src/main/java/in/backend/core/question/application/QuestionSaveCommand.java new file mode 100644 index 0000000..5408b5e --- /dev/null +++ b/backend/src/main/java/in/backend/core/question/application/QuestionSaveCommand.java @@ -0,0 +1,12 @@ +package in.backend.core.question.application; + +import in.backend.global.entity.ActionType; + +public record QuestionSaveCommand( + ActionType action, + Long questionId, + Long questionSetId, + Integer sequence, + String question +) { +} diff --git a/backend/src/main/java/in/backend/core/question/application/QuestionService.java b/backend/src/main/java/in/backend/core/question/application/QuestionService.java new file mode 100644 index 0000000..557a0c9 --- /dev/null +++ b/backend/src/main/java/in/backend/core/question/application/QuestionService.java @@ -0,0 +1,21 @@ +package in.backend.core.question.application; + + +import in.backend.core.question.application.QuestionWriter.QuestionInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class QuestionService { + private final QuestionWriter questionWriter; + + public Long save(QuestionSaveCommand command) { + return switch (command.action()) { + case CREATE -> questionWriter.write(new QuestionInfo(command)); + case UPDATE -> questionWriter.write(command.questionId(), new QuestionInfo(command)); + case DELETE -> throw new UnsupportedOperationException(); + }; + } + +} diff --git a/backend/src/main/java/in/backend/core/question/application/QuestionWriter.java b/backend/src/main/java/in/backend/core/question/application/QuestionWriter.java index 47b66fa..252262c 100644 --- a/backend/src/main/java/in/backend/core/question/application/QuestionWriter.java +++ b/backend/src/main/java/in/backend/core/question/application/QuestionWriter.java @@ -15,25 +15,31 @@ public class QuestionWriter { private final QuestionReader questionReader; - public Long execute(QuestionInfo questionInfo) { - return questionRepository.save(questionInfo.toEntity()).getId(); + public Long write(QuestionInfo questionInfo) { + return questionRepository.save(questionInfo.toEntity()) + .getId(); } - public void update(Long questionId, QuestionInfo questionInfo) { + public Long write(Long questionId, QuestionInfo questionInfo) { var question = questionReader.read(questionId); question.update(questionInfo); + + return question.getId(); } public record QuestionInfo( String content, - String referenceLinks, int sequence ) { + + public QuestionInfo(QuestionSaveCommand command) { + this(command.question(), command.sequence()); + } + public QuestionEntity toEntity() { return QuestionEntity.builder() .content(content) - .referenceLinks(referenceLinks) .sequence(sequence) .build(); } diff --git a/backend/src/main/java/in/backend/core/question/entity/QuestionEntity.java b/backend/src/main/java/in/backend/core/question/entity/QuestionEntity.java index c44d1ef..a9e213c 100644 --- a/backend/src/main/java/in/backend/core/question/entity/QuestionEntity.java +++ b/backend/src/main/java/in/backend/core/question/entity/QuestionEntity.java @@ -66,7 +66,6 @@ public QuestionEntity( public void update(QuestionInfo questionInfo) { applyIfPresent(questionInfo.content(), value -> this.content = value); - applyIfPresent(questionInfo.referenceLinks(), value -> this.referenceLinks = value); applyIfPresent(questionInfo.sequence(), value -> this.sequence = value); } diff --git a/backend/src/main/java/in/backend/core/question/presentation/QuestionApi.java b/backend/src/main/java/in/backend/core/question/presentation/QuestionApi.java new file mode 100644 index 0000000..2e437bb --- /dev/null +++ b/backend/src/main/java/in/backend/core/question/presentation/QuestionApi.java @@ -0,0 +1,26 @@ +package in.backend.core.question.presentation; + + +import in.backend.core.auth.domain.Visitor; +import in.backend.core.auth.domain.attributes.Auth; +import in.backend.core.question.presentation.payload.QuestionSaveRequest; +import lombok.RequiredArgsConstructor; +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 +@RequiredArgsConstructor +@RequestMapping("/api/questions") +public class QuestionApi { + + + @PostMapping + public void save( + @RequestBody QuestionSaveRequest questionSaveRequest, + @Auth Visitor visitor + ) { + + } +} diff --git a/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionDetailResponse.java b/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionDetailResponse.java new file mode 100644 index 0000000..74f3511 --- /dev/null +++ b/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionDetailResponse.java @@ -0,0 +1,9 @@ +package in.backend.core.question.presentation.payload; + +public record QuestionDetailResponse( + Long questionId, + Long questionSetId, + String question, + Integer sequence +) { +} diff --git a/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionSaveRequest.java b/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionSaveRequest.java new file mode 100644 index 0000000..f1bdeb0 --- /dev/null +++ b/backend/src/main/java/in/backend/core/question/presentation/payload/QuestionSaveRequest.java @@ -0,0 +1,12 @@ +package in.backend.core.question.presentation.payload; + +import in.backend.global.entity.ActionType; + +public record QuestionSaveRequest( + ActionType action, + Long questionId, + Long questionSetId, + Integer sequence, + String question +) { +} diff --git a/backend/src/main/java/in/backend/global/entity/ActionType.java b/backend/src/main/java/in/backend/global/entity/ActionType.java new file mode 100644 index 0000000..e41a08a --- /dev/null +++ b/backend/src/main/java/in/backend/global/entity/ActionType.java @@ -0,0 +1,7 @@ +package in.backend.global.entity; + +public enum ActionType { + CREATE, + UPDATE, + DELETE +}