From 60e3c617bf793982cf93e498a22c1bea1e9a3c4a Mon Sep 17 00:00:00 2001 From: jakalroni Date: Sat, 28 Jan 2023 00:46:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20[#45]=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=EC=9D=98=EB=AC=B8=EC=9E=A5=20=EC=A1=B0=ED=9A=8C=20=EB=AA=A9?= =?UTF-8?q?=EC=97=85=20API=20=EC=9E=91=EC=84=B1=20=EB=B0=8F=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/config | 2 +- .../be/core/application/QuestionService.java | 6 +-- .../dto/response/QuestionResponse.java | 8 ++- .../be/core/web/QuestionController.java | 2 +- .../question/InitQuestionControllerTest.java | 33 ++++++++++++ .../question/QuestionControllerFindTest.java | 54 +++++++++++++++++++ 6 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 be/src/test/java/com/example/be/core/web/question/InitQuestionControllerTest.java create mode 100644 be/src/test/java/com/example/be/core/web/question/QuestionControllerFindTest.java diff --git a/be/config b/be/config index 11ecd576..a6d0178c 160000 --- a/be/config +++ b/be/config @@ -1 +1 @@ -Subproject commit 11ecd576b96d12342b081cca42e7d94afffa6868 +Subproject commit a6d0178c4cbdb4517822066a2877acd3bc5a3362 diff --git a/be/src/main/java/com/example/be/core/application/QuestionService.java b/be/src/main/java/com/example/be/core/application/QuestionService.java index 5d08f78a..8e62a49b 100644 --- a/be/src/main/java/com/example/be/core/application/QuestionService.java +++ b/be/src/main/java/com/example/be/core/application/QuestionService.java @@ -6,12 +6,12 @@ import org.springframework.transaction.annotation.Transactional; @Slf4j -@Transactional(readOnly = true) @Service +@Transactional(readOnly = true) public class QuestionService { - - public QuestionResponse find() { + public QuestionResponse findById(Long questionId) { + log.debug("[오늘의 문장 조회] questionId = {}", questionId); return null; } } diff --git a/be/src/main/java/com/example/be/core/application/dto/response/QuestionResponse.java b/be/src/main/java/com/example/be/core/application/dto/response/QuestionResponse.java index e008950e..e18e2437 100644 --- a/be/src/main/java/com/example/be/core/application/dto/response/QuestionResponse.java +++ b/be/src/main/java/com/example/be/core/application/dto/response/QuestionResponse.java @@ -6,7 +6,10 @@ @Getter public class QuestionResponse { - @Schema(type = "String", description = "문장 주제, NOT NULL") + @Schema(type = "Long", description = "오늘의 문장 ID, NOT NULL") + private final Long questionId; + + @Schema(type = "String", description = "문장 제목, NOT NULL") private final String title; @Schema(type = "String", description = "음성 녹음 URL, NOT NULL") @@ -15,7 +18,8 @@ public class QuestionResponse { @Schema(type = "String", description = "음성 텍스트 URL, NOT NULL") private final String voiceText; - public QuestionResponse(String title, String voidRecord, String voiceText) { + public QuestionResponse(Long questionId, String title, String voidRecord, String voiceText) { + this.questionId = questionId; this.title = title; this.voidRecord = voidRecord; this.voiceText = voiceText; diff --git a/be/src/main/java/com/example/be/core/web/QuestionController.java b/be/src/main/java/com/example/be/core/web/QuestionController.java index b51f7689..18974404 100644 --- a/be/src/main/java/com/example/be/core/web/QuestionController.java +++ b/be/src/main/java/com/example/be/core/web/QuestionController.java @@ -24,7 +24,7 @@ public QuestionController(QuestionService questionService) { @GetMapping @ApiOperation(value = "오늘의 문장 조회입니다.") public BaseResponse find() { - QuestionResponse response = questionService.find(); + QuestionResponse response = questionService.findById(1L); return new BaseResponse<>(FIND_QUESTION_SUCCESS, response); } } diff --git a/be/src/test/java/com/example/be/core/web/question/InitQuestionControllerTest.java b/be/src/test/java/com/example/be/core/web/question/InitQuestionControllerTest.java new file mode 100644 index 00000000..25c46a71 --- /dev/null +++ b/be/src/test/java/com/example/be/core/web/question/InitQuestionControllerTest.java @@ -0,0 +1,33 @@ +package com.example.be.core.web.question; + +import com.example.be.core.application.QuestionService; +import com.example.be.core.web.QuestionController; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.filter.CharacterEncodingFilter; + +@WebMvcTest(QuestionController.class) +public abstract class InitQuestionControllerTest { + + @Autowired + protected MockMvc mockMvc; + + @MockBean + protected QuestionService questionService; + + @Autowired + protected ObjectMapper objectMapper; + + @BeforeEach + void init(WebApplicationContext wc) { + this.mockMvc = MockMvcBuilders.webAppContextSetup(wc) + .addFilter(new CharacterEncodingFilter("UTF-8", true)) + .build(); + } +} \ No newline at end of file diff --git a/be/src/test/java/com/example/be/core/web/question/QuestionControllerFindTest.java b/be/src/test/java/com/example/be/core/web/question/QuestionControllerFindTest.java new file mode 100644 index 00000000..aa49a4b3 --- /dev/null +++ b/be/src/test/java/com/example/be/core/web/question/QuestionControllerFindTest.java @@ -0,0 +1,54 @@ +package com.example.be.core.web.question; + +import static com.example.be.common.response.ResponseCodeAndMessages.FIND_QUESTION_SUCCESS; +import static org.mockito.ArgumentMatchers.refEq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.example.be.common.response.BaseResponse; +import com.example.be.core.application.dto.response.QuestionResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +public class QuestionControllerFindTest extends InitQuestionControllerTest{ + + @Nested + @DisplayName("오늘의 문장 조회할 때") + class QuestionFindTest { + + @Nested + @DisplayName("정상적인 요청이라면") + class NormalTest { + + @Test + @DisplayName("오늘의 문장 조회 시, 해당 ID를 가진 오늘의 문장이 조회된다.") + void find_question() throws Exception { + //given + Long questionId = 1L; + QuestionResponse response = new QuestionResponse(questionId, "어떤 영화를 가장 좋아하세요?", "rulsjaklsjrlkrjslarjsalrkj", "rulsjaklsjrlkrjslarjsalrkj"); + BaseResponse baseResponse = new BaseResponse<>(FIND_QUESTION_SUCCESS, response); + + when(questionService.findById(refEq(questionId))) + .thenReturn(response); + + //when + ResultActions resultActions = mockMvc.perform(get("/question") + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE)); + + //then + resultActions.andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(baseResponse))); + + verify(questionService).findById(refEq(questionId)); + } + } + } + +} From 6cc8c8455f4edcb19cae043a24deb177c8e50be4 Mon Sep 17 00:00:00 2001 From: jakalroni Date: Sat, 28 Jan 2023 16:09:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feature:=20[#45]=20Subject,=20Question=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20Entity=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../be/core/domain/question/Question.java | 34 +++++++++++++++++ .../core/domain/question/QuestionSubject.java | 38 +++++++++++++++++++ .../be/core/domain/question/Subject.java | 28 ++++++++++++++ .../core/domain/question/SubjectMember.java | 38 +++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 be/src/main/java/com/example/be/core/domain/question/Question.java create mode 100644 be/src/main/java/com/example/be/core/domain/question/QuestionSubject.java create mode 100644 be/src/main/java/com/example/be/core/domain/question/Subject.java create mode 100644 be/src/main/java/com/example/be/core/domain/question/SubjectMember.java diff --git a/be/src/main/java/com/example/be/core/domain/question/Question.java b/be/src/main/java/com/example/be/core/domain/question/Question.java new file mode 100644 index 00000000..8ac7d848 --- /dev/null +++ b/be/src/main/java/com/example/be/core/domain/question/Question.java @@ -0,0 +1,34 @@ +package com.example.be.core.domain.question; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Question { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "question_id") + private Long id; + + @Lob + private String voiceRecord; + + @Lob + private String voiceText; + + public Question(Long id, String voiceRecord, String voiceText) { + this.id = id; + this.voiceRecord = voiceRecord; + this.voiceText = voiceText; + } +} diff --git a/be/src/main/java/com/example/be/core/domain/question/QuestionSubject.java b/be/src/main/java/com/example/be/core/domain/question/QuestionSubject.java new file mode 100644 index 00000000..b9ee8c56 --- /dev/null +++ b/be/src/main/java/com/example/be/core/domain/question/QuestionSubject.java @@ -0,0 +1,38 @@ +package com.example.be.core.domain.question; + +import com.example.be.core.domain.member.Member; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class QuestionSubject { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "subject_question_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "subject_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private Question question; + + public QuestionSubject(Member member, Question question) { + this.member = member; + this.question = question; + } +} diff --git a/be/src/main/java/com/example/be/core/domain/question/Subject.java b/be/src/main/java/com/example/be/core/domain/question/Subject.java new file mode 100644 index 00000000..5d777ccf --- /dev/null +++ b/be/src/main/java/com/example/be/core/domain/question/Subject.java @@ -0,0 +1,28 @@ +package com.example.be.core.domain.question; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Subject { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "subject_id") + private Long id; + + private String content; + + public Subject(Long id, String content) { + this.id = id; + this.content = content; + } +} diff --git a/be/src/main/java/com/example/be/core/domain/question/SubjectMember.java b/be/src/main/java/com/example/be/core/domain/question/SubjectMember.java new file mode 100644 index 00000000..81b4ca75 --- /dev/null +++ b/be/src/main/java/com/example/be/core/domain/question/SubjectMember.java @@ -0,0 +1,38 @@ +package com.example.be.core.domain.question; + +import com.example.be.core.domain.member.Member; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class SubjectMember { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "subject_member_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "subject_id") + private Subject subject; + + public SubjectMember(Member member, Subject subject) { + this.member = member; + this.subject = subject; + } +}