-
Notifications
You must be signed in to change notification settings - Fork 3
오늘의문장 조회 목업API 작성 및 Subject, Question 관련 Entity 작성 #63
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
Open
jakalroni
wants to merge
2
commits into
main
Choose a base branch
from
feature/#45/question-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Submodule config
updated
from 11ecd5 to a6d017
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
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
34 changes: 34 additions & 0 deletions
34
be/src/main/java/com/example/be/core/domain/question/Question.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,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; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
be/src/main/java/com/example/be/core/domain/question/QuestionSubject.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,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; | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
be/src/main/java/com/example/be/core/domain/question/Subject.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.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; | ||
nathan29849 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public Subject(Long id, String content) { | ||
| this.id = id; | ||
| this.content = content; | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
be/src/main/java/com/example/be/core/domain/question/SubjectMember.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,38 @@ | ||
| package com.example.be.core.domain.question; | ||
nathan29849 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
| } | ||
| } | ||
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
33 changes: 33 additions & 0 deletions
33
be/src/test/java/com/example/be/core/web/question/InitQuestionControllerTest.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,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(); | ||
| } | ||
| } | ||
nathan29849 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
54 changes: 54 additions & 0 deletions
54
be/src/test/java/com/example/be/core/web/question/QuestionControllerFindTest.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,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"); | ||
nathan29849 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BaseResponse<QuestionResponse> 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)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.