Skip to content

Commit

Permalink
Merge branch 'develop' into feature/authorization/#93
Browse files Browse the repository at this point in the history
  • Loading branch information
tioon authored May 21, 2024
2 parents 7faf76d + face14e commit c3d997c
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@NoArgsConstructor
public class AnswerCreateRequest {
private Long questionId;
private String nickname;
private Boolean profileOnOff;
private String content;
private String linkAttachments;
Expand All @@ -20,12 +19,11 @@ public class AnswerCreateRequest {



public AnswerCreateRequest(Long questionId, String content,String nickname,
public AnswerCreateRequest(Long questionId, String content,
Boolean profileOnOff, String linkAttachments,
String musicName, String musicSinger, String musicAudioUrl, String imageUrl, boolean updateImage) {
this.questionId = questionId;
this.content = content;
this.nickname = nickname;
this.profileOnOff = profileOnOff;
this.linkAttachments = linkAttachments;
this.musicName = musicName;
Expand All @@ -36,10 +34,10 @@ public AnswerCreateRequest(Long questionId, String content,String nickname,

}

public static AnswerCreateRequest of(Long questionId, String content, String nickname,
public static AnswerCreateRequest of(Long questionId, String content,
Boolean profileOnOff, String linkAttachments,
String musicName, String musicSinger, String musicAudioUrl, String imageUrl, boolean updateImage) {
return new AnswerCreateRequest(questionId, content, nickname, profileOnOff, linkAttachments,
return new AnswerCreateRequest(questionId, content, profileOnOff, linkAttachments,
musicName, musicSinger, musicAudioUrl, imageUrl, updateImage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class AnswerDetailResponse {
private String questionContent;
private Long memberId;
private String content;
private String senderNickname;
private String nickname;
private String memberNickname;
private Boolean profileOnOff;
private String linkAttachments;
private String musicName;
Expand All @@ -25,7 +24,7 @@ public class AnswerDetailResponse {


public AnswerDetailResponse(Long answerId, Long questionId, String questionContent, Long memberId,
String content, String senderNickname, String nickname, Boolean profileOnOff,
String content, String memberNickname, Boolean profileOnOff,
String linkAttachments, String musicName, String musicSinger, String musicAudioUrl,
String imageUrl, LocalDateTime createdDate) {

Expand All @@ -35,8 +34,7 @@ public AnswerDetailResponse(Long answerId, Long questionId, String questionConte
this.questionContent = questionContent;
this.memberId = memberId;
this.content = content;
this.senderNickname = senderNickname;
this.nickname = nickname;
this.memberNickname = memberNickname;
this.profileOnOff = profileOnOff;
this.linkAttachments = linkAttachments;
this.musicName = musicName;
Expand All @@ -47,11 +45,11 @@ public AnswerDetailResponse(Long answerId, Long questionId, String questionConte
}

public static AnswerDetailResponse of(Long answerId, Long questionId, String questionContent, Long memberId,
String content, String memberNickname, String nickname, Boolean profileOnOff,
String content, String memberNickname, Boolean profileOnOff,
String linkAttachments, String musicName, String musicSinger, String musicAudioUrl,
String imageUrl, LocalDateTime createdDate) {
return new AnswerDetailResponse(answerId, questionId, questionContent, memberId, content, memberNickname,
nickname, profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, imageUrl, createdDate);
profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, imageUrl, createdDate);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class Answer {
@OnDelete(action = OnDeleteAction.CASCADE)
private Member member;

@Column(name = "nickname")
private String nickname;

@Column(name = "image_file")
private String imageFile; // 이미지 파일 경로를 저장하는 리스트
Expand Down Expand Up @@ -67,10 +65,10 @@ public class Answer {
@Column(name = "profile_on_off", nullable = false)
private boolean profileOnOff;

public static Answer of(Long id, Question question, Member member, String nickname, String content,
public static Answer of(Long id, Question question, Member member, String content,
String imageFile, Music music, String linkAttachments, String imageUrl, LocalDateTime createdDate,
ReactionCount reactionCount, boolean profileOnOff) {
return new Answer(id, question, member, nickname, imageFile, content, music, linkAttachments, imageUrl, createdDate, null, reactionCount, profileOnOff);
return new Answer(id, question, member, imageFile, content, music, linkAttachments, imageUrl, createdDate, null, reactionCount, profileOnOff);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public Answer toEntity(AnswerCreateRequest request, Question question, Member me
Answer answer = Answer.builder()
.question(question)
.member(member)
.nickname(request.getNickname())
.content(request.getContent())
.linkAttachments(request.getLinkAttachments())
.profileOnOff(request.getProfileOnOff())
Expand All @@ -53,8 +52,7 @@ public AnswerDetailResponse toDomain(Answer answer) {
question.getContent(),
member.getId(),
answer.getContent(),
question.getSender().getNickname(),
answer.getNickname(),
member.getNickname(),
answer.isProfileOnOff(),
answer.getLinkAttachments(),
music != null ? music.getMusicName() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ public AnswerDetailResponse createAnswer(AnswerCreateRequest request, Long membe
return answerMapper.toDomain(savedAnswer);
}

@Transactional
public List<AnswerResponse> getAnswersByMemberId(Long memberId) {
List<Answer> answers = answerRepository.findByMemberId(memberId);
return answers.stream()
.map(answerMapper::toResponse)
.collect(Collectors.toList());
}

@Transactional
public Page<AnswerDetailResponse> getAllAnswers(Long memberId, Long categoryId, Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ public ResponseEntity<List<QuestionDetailResponse>> getUnansweredQuestions(
return ResponseEntity.ok(questions.getContent());
}

@PutMapping("/{questionId}")
@AuthorizationQuestion
public ResponseEntity<Void> updateQuestion(
@PathVariable Long questionId, @RequestParam String content) {
questionService.updateQuestion(questionId, content);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}

@DeleteMapping("/{questionId}")
@AuthorizationQuestion
public ResponseEntity<Void> deleteQuestion(@PathVariable Long questionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,6 @@ ResponseEntity<List<QuestionDetailResponse>> getAnsweredQuestions(
ResponseEntity<List<QuestionDetailResponse>> getUnansweredQuestions(
@PathVariable Long memberId, Pageable pageable);

@Operation(
summary = "질문 수정",
description = "기존 질문의 내용을 수정합니다.",
security = @SecurityRequirement(name = "bearerAuth")
)
@Parameter(
in = ParameterIn.HEADER,
name = "Authorization", required = true,
schema = @Schema(type = "string"),
description = "Bearer [Access 토큰]")
@ApiResponse(responseCode = "204", description = "질문 수정 성공")
@ApiResponse(responseCode = "401", description = "토큰 인증 실패",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"errorCode\": \"T-002\",\n" +
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" +
"}")))
@PutMapping("/{questionId}")
ResponseEntity<Void> updateQuestion(
@PathVariable Long questionId,
@RequestParam String content);

@Operation(
summary = "질문 삭제",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Question {

public void updateContent(String content) {
this.content = content;

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ public Page<QuestionDetailResponse> getQuestionsByMemberId(Long memberId, Pageab
return questions.map(question -> questionMapper.toDomain(question));
}

@Transactional
public QuestionDetailResponse updateQuestion(Long questionId, String content) {
Question question = questionRepository.findById(questionId)
.orElseThrow(() -> new BusinessException(QuestionError.NO_EXIST_QUESTION));
question.updateContent(content);
Question updatedQuestion = questionRepository.save(question);

//firebaseNotificationService.notifyNewQuestion(updatedQuestion.getSender(), updatedQuestion); // 파이어베이스 메세지 송신

return questionMapper.toDomain(updatedQuestion);
}

@Transactional
public void deleteQuestion(Long questionId) {
Question question = questionRepository.findById(questionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.web.baebaeBE.domain.member.entity.Member;
import com.web.baebaeBE.domain.member.entity.MemberType;
import com.web.baebaeBE.domain.member.repository.MemberRepository;
import com.web.baebaeBE.domain.oauth2.controller.Oauth2Controller;
import com.web.baebaeBE.domain.question.entity.Question;
import com.web.baebaeBE.domain.question.repository.QuestionJpaRepository;
import com.web.baebaeBE.domain.question.repository.QuestionRepository;
Expand Down Expand Up @@ -67,6 +68,10 @@ public class AnswerTest {
@Autowired
private JwtTokenProvider tokenProvider;

@MockBean
private Oauth2Controller oauth2Controller;

@Autowired
private final ObjectMapper objectMapper = new ObjectMapper();
private Member testMember;
private Member testReceiver;
Expand Down Expand Up @@ -141,30 +146,22 @@ public void createAnswerTest() throws Exception {

}

@Test
@DisplayName("회원별 답변 조회 테스트(): 해당 회원의 답변을 조회한다.")
public void getAnswersByMemberIdTest() throws Exception {
AnswerResponse answerResponse = new AnswerResponse();
List<AnswerResponse> answerResponseList = List.of(answerResponse);
when(answerService.getAnswersByMemberId(testMember.getId())).thenReturn(answerResponseList);

mockMvc.perform(get("/api/answers/member/{memberId}", testMember.getId())
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0]").exists());
}

@Test
@DisplayName("모든 답변 조회 테스트(): 모든 답변을 조회한다.")
public void getAllAnswersTest() throws Exception {
AnswerDetailResponse answerDetailResponse = new AnswerDetailResponse(1L, testQuestion.getId(), testQuestion.getContent(), testMember.getId(), "이것은 답변입니다.", testMember.getNickname(), "장지효", true, "https://link.com", "노래 제목", "가수 이름", "https://audio.url", "https://image.url", LocalDateTime.now());
AnswerDetailResponse answerDetailResponse = new AnswerDetailResponse(
1L, testQuestion.getId(), testQuestion.getContent(), testMember.getId(),
"이것은 답변입니다.", testMember.getNickname(), "장지효", true, "https://link.com",
"노래 제목", "가수 이름", "https://audio.url", "https://image.url", LocalDateTime.now()
);
List<AnswerDetailResponse> answerDetailResponseList = List.of(answerDetailResponse);
Page<AnswerDetailResponse> answerDetailResponsePage = new PageImpl<>(answerDetailResponseList, Pageable.unpaged(), 1);

when(answerService.getAllAnswers(eq(testMember.getId()), any(Long.class), any(Pageable.class))).thenReturn(answerDetailResponsePage);
when(answerService.getAllAnswers(eq(testMember.getId()), any(Long.class), any(Pageable.class)))
.thenReturn(answerDetailResponsePage);

mockMvc.perform(get("/api/answers")
.param("memberId", String.valueOf(testMember.getId()))
mockMvc.perform(get("/api/answers/member/{memberId}", testMember.getId())
.param("categoryId", "1")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,24 @@ void tearDown() {
// }


@Test
@DisplayName("알림 삭제 테스트(): 새로운 알림을 생성하고 삭제한다.")
void deleteNotificationTest() {
// Given
NotificationRequest.create createRequest = new NotificationRequest.create(
testMember.getId(),
"배승우님이 질문을 남기셨습니다! 확인해보세요",
"가은아! 넌 무슨색상을 좋아해?",
NotificationRequest.EventType.NEW_QUESTION, // 이벤트 타입 설정
null
);
Notification createdNotification = notificationService.createNotification(createRequest);

// When
notificationService.deleteNotification(createdNotification.getId());

// Then
assertTrue(notificationRepository.findById(createdNotification.getId()).isEmpty());
}
// @Test
// @DisplayName("알림 삭제 테스트(): 새로운 알림을 생성하고 삭제한다.")
// void deleteNotificationTest() {
// // Given
// NotificationRequest.create createRequest = new NotificationRequest.create(
// testMember.getId(),
// "배승우님이 질문을 남기셨습니다! 확인해보세요",
// "가은아! 넌 무슨색상을 좋아해?",
// NotificationRequest.EventType.NEW_QUESTION, // 이벤트 타입 설정
// null
// );
// Notification createdNotification = notificationService.createNotification(createRequest);
//
// // When
// notificationService.deleteNotification(createdNotification.getId());
//
// // Then
// assertTrue(notificationRepository.findById(createdNotification.getId()).isEmpty());
// }

}
Loading

0 comments on commit c3d997c

Please sign in to comment.