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

2024-09-03 [Release Note] #157

Merged
merged 14 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
7bab2fa
chore(application.yml) : JPA ์„ค์ •์„ secret์œผ๋กœ ์ด๋™
mjj111 Sep 3, 2024
1967952
refactor(BaseIntegrationTest) : ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ดˆ๊ธฐํ™” ์ž‘์—…์„ after๋กœ ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
f2f3588
style (BaseRestDocsTest) : bean ๋‚˜์—ด ์Šคํƒ€์ผ ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
c9a0c97
fix (NotificationService) : ํšŒ์› ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ fcm์„ ์ฐพ๋„๋ก ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
b68110b
fix (CommentService) : ๋Œ“๊ธ€ ๋“ฑ๋ก์‹œ, ์˜ฌ๋ฐ”๋ฅธ ํšŒ์›์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋„๋ก ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
3dd0771
fix (BoardController) : ์ด๋ฏธ์ง€ ์—†์ด ๊ฒŒ์‹œ๊ธ€ ๋“ฑ๋ก ๊ฐ€๋Šฅํ•˜๋„๋ก ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
e4cf809
style (DummyGenerator) : ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ ์‚ญ์ œ
mjj111 Sep 3, 2024
c544601
fix (EmailService) : ํšŒ์› ์ด๋ฉ”์ผ์„ ์ธ์ฝ”๋”ฉํ•˜๋„๋ก ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
fdef781
fix (MatchingProcessService) : ์ฒซ ํšŒ์ฐจ์™€ ์ดํ›„ ํšŒ์ฐจ์— ๋Œ€ํ•ด ๋ถ„๋ฆฌ ๋™์ž‘ํ•˜๋„๋ก ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
f132c96
refactor (NotificationController) : ๋ฉ”์„œ๋“œ ๋„ค์ž„ ๋ณ€๊ฒฝ
mjj111 Sep 3, 2024
12a26a9
refactor (MatchingProcessService) : ๋งค์นญ ์‹ ์ฒญ์„ ํ•˜์ง€ ์•Š์€ ์ผ€์ด์Šค ์ถ”๊ฐ€
mjj111 Sep 3, 2024
8a05725
style (MatchingProcessService) : ์˜คํƒ€ ์‚ญ์ œ
mjj111 Sep 3, 2024
0be6a29
test (MatchingRestDocsTest) : ๋งค์นญ ๋™์ž‘ ํ›„ ์ƒˆ๋กœ์šด ๋ผ์šด๋“œ ์ถ”๊ฐ€ํ•˜์—ฌ ๋งค์นญํŒŒํŠธ๋„ˆ ์กฐํšŒ ๊ฐ€๋Šฅํ† ๋ก ์ˆ˜์ •
mjj111 Sep 3, 2024
b7e13d8
Merge pull request #156 from Re-4aliens/fix/#150_front_report_errors
mjj111 Sep 3, 2024
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 @@ -37,7 +37,7 @@ public BoardController(final BoardService boardService, final BoardReadService b
@PostMapping("/normal")
public SuccessResponse<?> createBoard(@Login final LoginMember loginMember,
@RequestPart final BoardCreateRequest request,
@RequestPart final List<MultipartFile> boardImages) {
@RequestPart(required = false) final List<MultipartFile> boardImages) {
boardService.postNormalBoard(request, boardImages, loginMember);
return SuccessResponse.of(BoardSuccess.POST_BOARD_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.aliens.backend.board.service;

import com.aliens.backend.board.controller.dto.request.ChildCommentCreateRequest;
import com.aliens.backend.board.controller.dto.request.ParentCommentCreateRequest;
import com.aliens.backend.board.domain.Board;
import com.aliens.backend.notification.controller.dto.NotificationRequest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CommentEventPublisher {
private final ApplicationEventPublisher eventPublisher;

public CommentEventPublisher(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}

public void sendParentCommentNotification(Board board,
ParentCommentCreateRequest request) {

eventPublisher.publishEvent(new NotificationRequest(
board.getCategory(),
board.getId(),
"\"" + request.content() + "\" ๋ผ๋Š” ๋Œ“๊ธ€์ด ๋‹ฌ๋ ธ์Šต๋‹ˆ๋‹ค.",
List.of(board.getWriterId())));
}

public void sendChildCommentNotification(Board board,
ChildCommentCreateRequest request,
Long parentCommentMemberId) {
System.out.println("์ž‘์„ฑ์ž Id" + board.getWriterId());
System.out.println("๋ถ€๋ชจ๋Œ“๊ธ€ Id" + parentCommentMemberId);
eventPublisher.publishEvent(new NotificationRequest(
board.getCategory(),
board.getId(),
"\"" + request.content() + "\" ๋ผ๋Š” ๋Œ“๊ธ€์ด ๋‹ฌ๋ ธ์Šต๋‹ˆ๋‹ค.",
List.of(board.getWriterId(), parentCommentMemberId)));
}
}
50 changes: 22 additions & 28 deletions src/main/java/com/aliens/backend/board/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import com.aliens.backend.global.exception.RestApiException;
import com.aliens.backend.global.response.error.BoardError;
import com.aliens.backend.global.response.error.MemberError;
import com.aliens.backend.notification.controller.dto.NotificationRequest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -30,10 +28,14 @@ public class CommentService {
private final MemberRepository memberRepository;
private final BoardRepository boardRepository;
private final CommentCustomRepository commentCustomRepository;
private final ApplicationEventPublisher eventPublisher;
private final CommentEventPublisher eventPublisher;


public CommentService(final CommentRepository commentRepository, final MemberRepository memberRepository, final BoardRepository boardRepository, final CommentCustomRepository commentCustomRepository, final ApplicationEventPublisher eventPublisher) {
public CommentService(final CommentRepository commentRepository,
final MemberRepository memberRepository,
final BoardRepository boardRepository,
final CommentCustomRepository commentCustomRepository,
final CommentEventPublisher eventPublisher) {
this.commentRepository = commentRepository;
this.memberRepository = memberRepository;
this.boardRepository = boardRepository;
Expand All @@ -46,27 +48,19 @@ public void postParentComment(final ParentCommentCreateRequest request,
final LoginMember loginMember) {
Member member = getMember(loginMember);
Board board = findBoard(request.boardId());

Comment comment = Comment.parentOf(request.content(), board, member);
board.addComment(comment);

commentRepository.save(comment);

if(!comment.isWriter(board.getWriterId())) {
sendParentCommentNotification(board, request);
eventPublisher.sendParentCommentNotification(board, request);
}
}

private void sendParentCommentNotification(Board board,
ParentCommentCreateRequest request) {
eventPublisher.publishEvent(new NotificationRequest(
board.getCategory(),
board.getId(),
"\"" + request.content() + "\" ๋ผ๋Š” ๋Œ“๊ธ€์ด ๋‹ฌ๋ ธ์Šต๋‹ˆ๋‹ค.",
List.of(board.getWriterId())));
}

private Board findBoard(final Long boardId) {
return boardRepository.findById(boardId).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER));
return boardRepository.findById(boardId).orElseThrow(() -> new RestApiException(BoardError.INVALID_BOARD_ID));
}

private Member getMember(final LoginMember loginMember) {
Expand All @@ -78,26 +72,20 @@ public void postChildComment(final ChildCommentCreateRequest request,
final LoginMember loginMember) {
Member member = getMember(loginMember);
Board board = findBoard(request.boardId());
Comment parentComment = commentRepository.findById(request.parentCommentId()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER));
Comment parentComment = findComment(request);

Comment childComment = Comment.childOf(request, board, member);
board.addComment(childComment);

commentRepository.save(childComment);

if(!parentComment.isWriter(member.getId())) {
sendChildCommentNotification(board, request, parentComment.getWriterId());
eventPublisher.sendChildCommentNotification(board, request, parentComment.getWriterId());
}
}

private void sendChildCommentNotification(Board board,
ChildCommentCreateRequest request,
Long parentCommentMemberId) {
eventPublisher.publishEvent(new NotificationRequest(
board.getCategory(),
board.getId(),
"\"" + request.content() + "\" ๋ผ๋Š” ๋Œ“๊ธ€์ด ๋‹ฌ๋ ธ์Šต๋‹ˆ๋‹ค.",
List.of(board.getWriterId(), parentCommentMemberId)));
private Comment findComment(ChildCommentCreateRequest request) {
return commentRepository.findById(request.parentCommentId()).orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER));
}

@Transactional(readOnly = true)
Expand All @@ -108,28 +96,34 @@ public List<BoardResponse> getCommentedBoardPage(final LoginMember loginMember,
@Transactional(readOnly = true)
public List<CommentResponse> getCommentsByBoardId(final Long boardId) {
List<Comment> comments = commentCustomRepository.getCommentsByBoardId(boardId);

ArrayList<CommentResponse> result = new ArrayList<>();
sortComments(comments, result);

return result;
}

private void sortComments(List<Comment> comments, ArrayList<CommentResponse> result) {
for(Comment comment : comments) {
if (!comment.isParent()){
continue;
}

CommentResponse parentComment = comment.getCommentResponse();

List<CommentResponse> childrenComment = comments.stream()
.filter(c -> (c.isChildFrom(comment.getId())))
.map(Comment::getCommentResponse)
.toList();

if(isNotEmtyChildren(childrenComment)) {
if(isNotEmptyChildren(childrenComment)) {
parentComment.setChildren(childrenComment);
}
result.add(parentComment);
}
return result;
}

private boolean isNotEmtyChildren(final List<CommentResponse> childrenComment) {
private boolean isNotEmptyChildren(final List<CommentResponse> childrenComment) {
return childrenComment != null && !childrenComment.isEmpty();
}

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/aliens/backend/email/service/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ public class EmailService {

private final EmailAuthenticationRepository emailAuthenticationRepository;
private final EmailSender emailSender;
private final SymmetricKeyEncoder symmetricKeyEncoder;
private final MemberRepository memberRepository;

public EmailService(final EmailAuthenticationRepository emailRepository,
final EmailSender emailSender,
final SymmetricKeyEncoder symmetricKeyEncoder, final MemberRepository memberRepository) {
final MemberRepository memberRepository) {
this.emailAuthenticationRepository = emailRepository;
this.emailSender = emailSender;
this.symmetricKeyEncoder = symmetricKeyEncoder;
this.memberRepository = memberRepository;
}

Expand All @@ -50,7 +48,7 @@ public String sendAuthenticationEmail(final String email) {
EmailAuthentication emailEntity = new EmailAuthentication(email);
emailAuthenticationRepository.save(emailEntity);

String emailToken = symmetricKeyEncoder.encrypt(String.valueOf(emailEntity.getId()));
String emailToken = SymmetricKeyEncoder.encrypt(email);
emailSender.sendAuthenticationEmail(email, emailToken);

return EmailResponse.EMAIL_SEND_SUCCESS.getMessage();
Expand All @@ -70,14 +68,14 @@ private void deleteExistsEmail(final String email) {

@Transactional
public String authenticateEmail(final String token) {
Long emailEntityId = Long.valueOf(symmetricKeyEncoder.decrypt(token));
EmailAuthentication emailEntity = getEmailAuthentication(emailEntityId);
String email = SymmetricKeyEncoder.decrypt(token);
EmailAuthentication emailEntity = getEmailAuthenticationByEmail(email);
emailEntity.authenticate();
return EmailResponse.EMAIL_AUTHENTICATION_SUCCESS.getMessage();
}

private EmailAuthentication getEmailAuthentication(final Long emailEntityId) {
return emailAuthenticationRepository.findById(emailEntityId).orElseThrow(() -> new RestApiException(EmailError.NULL_EMAIL));
private EmailAuthentication getEmailAuthenticationByEmail(final String email) {
return emailAuthenticationRepository.findByEmail(email).orElseThrow(() -> new RestApiException(EmailError.NULL_EMAIL));
}

@EventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,10 @@ public Long getRound() {
return round;
}

public LocalDateTime getRequestStartTime() {
return requestStartTime;
}

public LocalDateTime getRequestEndTime() {
return requestEndTime;
}

public LocalDateTime getValidStartTime() {
return validStartTime;
}

public LocalDateTime getValidEndTime() {
return validEndTime;
}

public DayOfWeek getDayOfWeek() {
return requestStartTime.getDayOfWeek();
}
Expand Down Expand Up @@ -90,4 +78,8 @@ public String toString() {
", validEndTime=" + validEndTime +
'}';
}

public boolean isFirstTime() {
return round == 1;
}
}
Loading
Loading