Skip to content
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

Qna #190

Merged
merged 42 commits into from
Nov 18, 2023
Merged

Qna #190

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
524c66e
Merge pull request #41 from Funssion-SWM/develope
goathoon Aug 20, 2023
80ee3aa
Merge pull request #42 from Funssion-SWM/develope
goathoon Aug 20, 2023
3a2cf4d
Merge pull request #43 from Funssion-SWM/develope
goathoon Aug 20, 2023
87723b6
Merge pull request #44 from Funssion-SWM/develope
goathoon Aug 20, 2023
f9e32ca
Merge pull request #45 from Funssion-SWM/develope
comolove Aug 22, 2023
2f8c493
Merge pull request #46 from Funssion-SWM/develope
comolove Aug 22, 2023
10571be
Merge pull request #53 from Funssion-SWM/develope
comolove Sep 4, 2023
d9e08b1
Merge pull request #56 from Funssion-SWM/develope
comolove Sep 5, 2023
612cc2a
Merge pull request #57 from Funssion-SWM/develope
comolove Sep 6, 2023
aff70a7
Merge pull request #61 from Funssion-SWM/develope
comolove Sep 10, 2023
21e37e6
Merge pull request #63 from Funssion-SWM/develope
goathoon Sep 14, 2023
96f65a4
Merge pull request #64 from Funssion-SWM/develope
goathoon Sep 14, 2023
da21f57
Merge pull request #65 from Funssion-SWM/develope
goathoon Sep 14, 2023
6406426
Merge pull request #67 from Funssion-SWM/develope
goathoon Sep 14, 2023
91ad96d
Merge pull request #68 from Funssion-SWM/develope
goathoon Sep 14, 2023
9cade57
Merge pull request #77 from Funssion-SWM/develope
comolove Sep 18, 2023
addc9d9
Merge pull request #78 from Funssion-SWM/develope
goathoon Sep 18, 2023
1564d37
Merge pull request #80 from Funssion-SWM/develope
goathoon Sep 20, 2023
6f23e85
Merge pull request #81 from Funssion-SWM/develope
goathoon Sep 20, 2023
0cbc05b
Merge pull request #96 from Funssion-SWM/develope
comolove Oct 8, 2023
aaac535
Merge pull request #97 from Funssion-SWM/develope
comolove Oct 8, 2023
c51311d
Merge pull request #101 from Funssion-SWM/develope
goathoon Oct 8, 2023
8a353d7
Merge pull request #102 from Funssion-SWM/develope
goathoon Oct 8, 2023
28324aa
Merge pull request #105 from Funssion-SWM/develope
goathoon Oct 11, 2023
ce5a8e1
Merge pull request #106 from Funssion-SWM/develope
goathoon Oct 11, 2023
fa0c136
Merge pull request #107 from Funssion-SWM/develope
goathoon Oct 11, 2023
a26dd1b
Merge pull request #108 from Funssion-SWM/develope
goathoon Oct 11, 2023
2a859e9
Merge pull request #133 from Funssion-SWM/develope
comolove Oct 21, 2023
966b3c7
Merge pull request #139 from Funssion-SWM/develope
goathoon Oct 23, 2023
65ecbf3
Merge pull request #142 from Funssion-SWM/develope
goathoon Oct 23, 2023
88e7ab0
Merge pull request #144 from Funssion-SWM/develope
goathoon Oct 23, 2023
40473aa
Merge pull request #145 from Funssion-SWM/develope
comolove Oct 24, 2023
5a04d08
Merge pull request #175 from Funssion-SWM/develope
comolove Nov 7, 2023
6216b8e
Merge pull request #177 from Funssion-SWM/develope
comolove Nov 9, 2023
8599351
Merge pull request #178 from Funssion-SWM/develope
comolove Nov 12, 2023
49cb1a7
Merge pull request #179 from Funssion-SWM/develope
comolove Nov 12, 2023
2f7100a
Merge pull request #181 from Funssion-SWM/develope
goathoon Nov 14, 2023
6ff7d2c
Merge pull request #183 from Funssion-SWM/develope
goathoon Nov 14, 2023
a2f2d7b
Merge pull request #185 from Funssion-SWM/develope
goathoon Nov 14, 2023
bbd525b
Merge pull request #187 from Funssion-SWM/develope
goathoon Nov 14, 2023
d574dbb
Merge pull request #189 from Funssion-SWM/develope
goathoon Nov 14, 2023
5f744c8
fix: question create시 question id반환하게 수정
goathoon Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import Funssion.Inforum.common.dto.IsSuccessResponseDto;
import Funssion.Inforum.common.exception.etc.UnAuthorizedException;
import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.post.memo.dto.response.MemoListDto;
import Funssion.Inforum.domain.post.qna.Constant;
import Funssion.Inforum.domain.post.qna.domain.Question;
import Funssion.Inforum.domain.post.qna.dto.request.QuestionSaveDto;
import Funssion.Inforum.domain.post.qna.dto.response.CreateQuestionDto;
import Funssion.Inforum.domain.post.qna.dto.response.QuestionDto;
import Funssion.Inforum.domain.post.qna.service.QuestionService;
import Funssion.Inforum.domain.post.utils.AuthUtils;
Expand All @@ -33,10 +33,9 @@ public class QuestionController {
private final QuestionService questionService;
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public IsSuccessResponseDto createQuestion(@RequestBody @Validated QuestionSaveDto questionSaveDto,@RequestParam(required = false, defaultValue=Constant.NONE_MEMO_QUESTION) Long memoId){
public CreateQuestionDto createQuestion(@RequestBody @Validated QuestionSaveDto questionSaveDto,@RequestParam(required = false, defaultValue=Constant.NONE_MEMO_QUESTION) Long memoId){
Long authorId = AuthUtils.getUserId(CRUDType.CREATE);
questionService.createQuestion(questionSaveDto, authorId, memoId);
return new IsSuccessResponseDto(true,"성공적으로 질문이 등록되었습니다.");
return new CreateQuestionDto(questionService.createQuestion(questionSaveDto, authorId, memoId).getId(),"성공적으로 질문이 등록 되었습니다." );
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package Funssion.Inforum.domain.post.qna.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreateQuestionDto {
private Long questionId;
private String message;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package Funssion.Inforum.domain.notification;

import Funssion.Inforum.common.constant.NotificationType;
import Funssion.Inforum.common.constant.OrderType;
import Funssion.Inforum.common.constant.PostType;
import Funssion.Inforum.domain.follow.repository.FollowRepository;
import Funssion.Inforum.domain.member.constant.LoginType;
import Funssion.Inforum.domain.member.dto.response.SaveMemberResponseDto;
import Funssion.Inforum.domain.member.entity.Member;
import Funssion.Inforum.domain.member.entity.NonSocialMember;
import Funssion.Inforum.domain.member.entity.SocialMember;
import Funssion.Inforum.domain.member.repository.MemberRepository;
Expand All @@ -17,13 +12,10 @@
import Funssion.Inforum.domain.post.comment.repository.CommentRepository;
import Funssion.Inforum.domain.post.memo.domain.Memo;
import Funssion.Inforum.domain.post.memo.repository.MemoRepository;
import Funssion.Inforum.domain.post.qna.Constant;
import Funssion.Inforum.domain.post.qna.domain.Answer;
import Funssion.Inforum.domain.post.qna.domain.Question;
import Funssion.Inforum.domain.post.qna.repository.AnswerRepository;
import Funssion.Inforum.domain.post.qna.repository.QuestionRepository;
import Funssion.Inforum.domain.score.Rank;
import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -34,24 +26,22 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Collections;

import static Funssion.Inforum.common.constant.NotificationType.*;
import static Funssion.Inforum.common.constant.OrderType.*;
import static Funssion.Inforum.common.constant.OrderType.NEW;
import static Funssion.Inforum.common.constant.PostType.*;
import static Funssion.Inforum.domain.post.qna.Constant.*;
import static Funssion.Inforum.domain.score.Rank.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@Transactional
Expand Down Expand Up @@ -672,8 +662,7 @@ void newQuestionInMemo() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.param("memoId", createdMemo.getId().toString())
.with(user(testUser2Id.toString())))
.andExpect(status().isCreated())
.andExpect(content().string(containsString("\"isSuccess\":true")));
.andExpect(status().isCreated());

Question savedQuestion = questionRepository.getQuestionsOfMemo(testUser2Id, createdMemo.getId()).get(0);
assertThat(savedQuestion.getMemoId()).isEqualTo(createdMemo.getId());
Expand Down Expand Up @@ -891,8 +880,7 @@ void manyFollowingUserWriteNewQuestion() throws Exception {
.content(questionSaveForm)
.contentType(MediaType.APPLICATION_JSON)
.with(user(testUser1Id.toString())))
.andExpect(status().isCreated())
.andExpect(content().string(containsString("\"isSuccess\":true")));
.andExpect(status().isCreated());

Question savedQuestion = questionRepository.getMyQuestions(testUser1Id, NEW, DEFAULT_PAGE_NUM, DEFAULT_RESULT_SIZE_PER_PAGE).get(0);
assertThat(savedQuestion.getMemoId()).isEqualTo(Long.valueOf(NONE_MEMO_QUESTION));
Expand Down Expand Up @@ -999,8 +987,7 @@ void followingUserWriteNewQuestionInMyMemo() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.param("memoId", createdMemo.getId().toString())
.with(user(testUser2Id.toString())))
.andExpect(status().isCreated())
.andExpect(content().string(containsString("\"isSuccess\":true")));
.andExpect(status().isCreated());

Question savedQuestion = questionRepository.getMyQuestions(testUser2Id, NEW, DEFAULT_PAGE_NUM, DEFAULT_RESULT_SIZE_PER_PAGE).get(0);
assertThat(savedQuestion.getMemoId()).isEqualTo(createdMemo.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Funssion.Inforum.domain.post.qna.controller;

import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.post.qna.domain.Question;
import Funssion.Inforum.domain.post.qna.dto.request.QuestionSaveDto;
import Funssion.Inforum.domain.post.qna.dto.response.QuestionDto;
import Funssion.Inforum.domain.post.qna.service.QuestionService;
Expand All @@ -20,6 +21,7 @@
import java.time.LocalDateTime;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
Expand Down Expand Up @@ -69,6 +71,8 @@ class createQuestion{
@WithMockUser(username = AUTHORIZED_USER)
@DisplayName("로그인한 유저가 올바른 질문을 생성")
void createQuestionByAuthUser() throws Exception {
when(questionService.createQuestion(any(QuestionSaveDto.class),any(Long.class),any(Long.class)))
.thenReturn(Question.builder().id(1L).build());
mvc.perform(post("/questions")
.with(csrf())
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -79,6 +83,8 @@ void createQuestionByAuthUser() throws Exception {
@WithMockUser(username = AUTHORIZED_USER)
@DisplayName("로그인한 유저가 특정 메모랑 연관된 올바른 질문을 생성")
void createQuestionInMemoByAuthUser() throws Exception {
when(questionService.createQuestion(any(QuestionSaveDto.class),any(Long.class),any(Long.class)))
.thenReturn(Question.builder().id(1L).build());
mvc.perform(post("/questions")
.with(csrf())
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -102,6 +108,8 @@ void createInvalidQuestionByAuthUser() throws Exception {
@WithMockUser(username = SecurityContextUtils.ANONYMOUS_USER_ID_STRING)
@DisplayName("로그인하지 않은 유저가 올바르지 않은 질문을 생성")
void createQuestionByNonAuthUser() throws Exception {
when(questionService.createQuestion(any(QuestionSaveDto.class),any(Long.class),any(Long.class)))
.thenReturn(Question.builder().id(1L).build());
mvc.perform(post("/questions")
.with(csrf())
.contentType(MediaType.APPLICATION_JSON)
Expand Down