diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/application/question/QuestionApplication.java b/baebae-BE/src/main/java/com/web/baebaeBE/application/question/QuestionApplication.java index ddf63b90..63b49512 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/application/question/QuestionApplication.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/application/question/QuestionApplication.java @@ -24,24 +24,17 @@ public class QuestionApplication { private final QuestionMapper questionMapper; private final MemberRepository memberRepository; - public QuestionDetailResponse createQuestion(QuestionCreateRequest request, Long senderId, Long receiverId, String token) { - Member sender = memberRepository.findById(senderId) - .orElseThrow(() -> new BusinessException(MemberError.NOT_EXIST_MEMBER)); - Member receiver = memberRepository.findById(receiverId) + public QuestionDetailResponse createQuestion(QuestionCreateRequest request, Long memberId, String token) { + Member member = memberRepository.findById(memberId) .orElseThrow(() -> new BusinessException(MemberError.NOT_EXIST_MEMBER)); - Question questionEntity = questionMapper.toEntity(request, sender, receiver); + Question questionEntity = questionMapper.toEntity(request, member); Question savedQuestionEntity = questionService.createQuestion(questionEntity); return questionMapper.toDomain(savedQuestionEntity, token); } - public Page getAllQuestions(Long memberId, Pageable pageable, boolean isSender) { - Page questionPage; - if (isSender) { - questionPage = questionService.getQuestionsBySenderId(memberId, pageable); - } else { - questionPage = questionService.getQuestionsByReceiverId(memberId, pageable); - } + public Page getAllQuestions(Long memberId, Pageable pageable) { + Page questionPage = questionService.getQuestionsByMemberId(memberId, pageable); return questionPage.map(question -> questionMapper.toDomain(question, "appropriate token here")); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/domain/question/service/QuestionService.java b/baebae-BE/src/main/java/com/web/baebaeBE/domain/question/service/QuestionService.java index c9e6614d..88815024 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/domain/question/service/QuestionService.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/domain/question/service/QuestionService.java @@ -21,13 +21,8 @@ public Question createQuestion(Question question) { } @Transactional(readOnly = true) - public Page getQuestionsBySenderId(Long senderId, Pageable pageable) { - return questionRepository.findAllBySenderId(senderId, pageable); - } - - @Transactional(readOnly = true) - public Page getQuestionsByReceiverId(Long receiverId, Pageable pageable) { - return questionRepository.findAllByReceiverId(receiverId, pageable); + public Page getQuestionsByMemberId(Long memberId, Pageable pageable) { + return questionRepository.findAllByMemberId(memberId, pageable); } @Transactional diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/entity/Question.java b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/entity/Question.java index 04514a38..103a5138 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/entity/Question.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/entity/Question.java @@ -20,12 +20,8 @@ public class Question { private Long id; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "sender_id", nullable = false) - private Member sender; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "receiver_id", nullable = false) - private Member receiver; + @JoinColumn(name = "member_id", nullable = false) + private Member member; @Column(nullable = false, columnDefinition = "TEXT") private String content; @@ -42,9 +38,9 @@ public class Question { public void updateContent(String content) { this.content = content; } - public static Question of(Long id, Member sender, Member receiver, String content, String nickname, Boolean profileOnOff, + public static Question of(Long id, Member member, String content, String nickname, Boolean profileOnOff, LocalDateTime createdDate) { - return new Question(id, sender, receiver, content, nickname, profileOnOff, createdDate); + return new Question(id, member, content, nickname, profileOnOff, createdDate); } } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionJpaRepository.java b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionJpaRepository.java index 87985963..e0ac7bb3 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionJpaRepository.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionJpaRepository.java @@ -6,6 +6,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface QuestionJpaRepository extends JpaRepository { - Page findAllBySenderId(Long senderId, Pageable pageable); - Page findAllByReceiverId(Long receiverId, Pageable pageable); + Page findAllByMemberId(Long memberId, Pageable pageable); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionMapper.java b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionMapper.java index fa613060..02ffbb06 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionMapper.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionMapper.java @@ -12,10 +12,9 @@ @Component @RequiredArgsConstructor public class QuestionMapper { - public Question toEntity(QuestionCreateRequest request, Member sender, Member receiver) { + public Question toEntity(QuestionCreateRequest request, Member member) { return Question.builder() - .sender(sender) - .receiver(receiver) + .member(member) .content(request.getContent()) .nickname(request.getNickname()) .profileOnOff(request.getProfileOnOff()) diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepository.java b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepository.java index b6adf6b1..a5266eaa 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepository.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepository.java @@ -10,8 +10,7 @@ public interface QuestionRepository{ Optional findById(Long questionId); Question save(Question questionEntity); - Page findAllBySenderId(Long senderId, Pageable pageable); - Page findAllByReceiverId(Long receiverId, Pageable pageable); + Page findAllByMemberId(Long memberId, Pageable pageable); void delete(Question questionEntity); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepositoryImpl.java b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepositoryImpl.java index 5d7cbc1f..1f335737 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepositoryImpl.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/infra/question/repository/QuestionRepositoryImpl.java @@ -26,13 +26,8 @@ public Question save(Question questionEntity) { } @Override - public Page findAllBySenderId(Long senderId, Pageable pageable) { - return questionJpaRepository.findAllBySenderId(senderId, pageable); - } - - @Override - public Page findAllByReceiverId(Long receiverId, Pageable pageable) { - return questionJpaRepository.findAllByReceiverId(receiverId, pageable); + public Page findAllByMemberId(Long memberId, Pageable pageable) { + return questionJpaRepository.findAllByMemberId(memberId, pageable); } @Override diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/QuestionController.java b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/QuestionController.java index c4481eb1..27f5b15c 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/QuestionController.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/QuestionController.java @@ -29,13 +29,13 @@ public QuestionController(QuestionApplication questionApplication, JwtTokenProvi @Operation(summary = "질문 생성") @PostMapping("/member/{memberId}") public ResponseEntity createQuestion( - @RequestBody QuestionCreateRequest questionDTO, @PathVariable Long memberId, @RequestParam Long receiverId, + @RequestBody QuestionCreateRequest questionDTO, @PathVariable Long memberId, @RequestHeader("Authorization") String token) { if (!tokenProvider.validToken(token)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } - QuestionDetailResponse createdQuestion = questionApplication.createQuestion(questionDTO, memberId, receiverId, token); + QuestionDetailResponse createdQuestion = questionApplication.createQuestion(questionDTO, memberId, token); return ResponseEntity.status(HttpStatus.CREATED).body(createdQuestion); } @@ -43,15 +43,17 @@ public ResponseEntity createQuestion( @GetMapping() public ResponseEntity> getAllQuestions( @RequestParam Long memberId, - @RequestParam boolean isSender, Pageable pageable) { - Page questions = questionApplication.getAllQuestions(memberId, pageable, isSender); + Page questions = questionApplication.getAllQuestions(memberId, pageable); return ResponseEntity.ok(questions.getContent()); } @Operation(summary = "질문 수정") @PutMapping("/{questionId}") public ResponseEntity updateQuestion(@PathVariable Long questionId, @RequestParam String content, @RequestHeader("Authorization") String token) { + if (!tokenProvider.validToken(token)) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); + } questionApplication.updateQuestion(questionId, content, token); return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionCreateRequest.java b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionCreateRequest.java index d2f0f622..3e9116ee 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionCreateRequest.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionCreateRequest.java @@ -1,6 +1,5 @@ package com.web.baebaeBE.presentation.question.dto; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionDetailResponse.java b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionDetailResponse.java index 1a5577ef..a09d28e2 100644 --- a/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionDetailResponse.java +++ b/baebae-BE/src/main/java/com/web/baebaeBE/presentation/question/dto/QuestionDetailResponse.java @@ -10,18 +10,18 @@ public class QuestionDetailResponse { private Long questionId; private String content; - private String userEmail; + private String nickname; private LocalDateTime createdDate; private String token; - public QuestionDetailResponse(Long questionId, String content, String userEmail, LocalDateTime createdDate, String token) { + public QuestionDetailResponse(Long questionId, String content, String nickname, LocalDateTime createdDate, String token) { this.questionId = questionId; this.content = content; - this.userEmail = userEmail; + this.nickname = nickname; this.createdDate = createdDate; this.token = token; } - public static QuestionDetailResponse of(Long questionId, String content, String userEmail, LocalDateTime createdDate, String token) { - return new QuestionDetailResponse(questionId, content, userEmail, createdDate, token); + public static QuestionDetailResponse of(Long questionId, String content, String nickname, LocalDateTime createdDate, String token) { + return new QuestionDetailResponse(questionId, content, nickname, createdDate, token); } } \ No newline at end of file