diff --git a/src/main/java/com/daon/onjung/suggestion/application/controller/command/SuggestionCommandV1Controller.java b/src/main/java/com/daon/onjung/suggestion/application/controller/command/SuggestionCommandV1Controller.java index 5dbbf1a..393648e 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/controller/command/SuggestionCommandV1Controller.java +++ b/src/main/java/com/daon/onjung/suggestion/application/controller/command/SuggestionCommandV1Controller.java @@ -5,6 +5,7 @@ import com.daon.onjung.suggestion.application.dto.request.CreateBoardRequestDto; import com.daon.onjung.suggestion.application.dto.request.CreateCommentRequestDto; import com.daon.onjung.suggestion.application.dto.response.CreateCommentResponseDto; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import com.daon.onjung.suggestion.application.usecase.CreateBoardUseCase; import com.daon.onjung.suggestion.application.usecase.CreateCommentUseCase; import com.daon.onjung.suggestion.application.usecase.CreateOrDeleteLikeUseCase; @@ -44,11 +45,10 @@ public ResponseDto createComment( } @PutMapping("/api/v1/boards/{id}/likes") - public ResponseDto likeBoard( + public ResponseDto likeBoard( @AccountID UUID accountId, @PathVariable Long id ) { - createOrDeleteLikeUseCase.execute(accountId, id); - return ResponseDto.ok(null); + return ResponseDto.ok(createOrDeleteLikeUseCase.execute(accountId, id)); } } diff --git a/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/CommentV1Consumer.java b/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/CommentV1Consumer.java index f34c1e3..7f2ada4 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/CommentV1Consumer.java +++ b/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/CommentV1Consumer.java @@ -14,7 +14,6 @@ import com.daon.onjung.suggestion.repository.mysql.CommentRepository; import lombok.RequiredArgsConstructor; import org.hibernate.dialect.lock.OptimisticEntityLockException; -import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Service; @@ -35,7 +34,7 @@ public class CommentV1Consumer { @Transactional @RabbitListener(queues = "comment-queue-1") - public CreateCommentResponseDto processCommentMessage1(CommentMessage commentMessage, Message amqpMessage) { + public CreateCommentResponseDto processCommentMessage1(CommentMessage commentMessage) { try { // 게시글 조회 @@ -66,7 +65,7 @@ public CreateCommentResponseDto processCommentMessage1(CommentMessage commentMes @Transactional @RabbitListener(queues = "comment-queue-2") - public CreateCommentResponseDto processCommentMessage2(CommentMessage commentMessage, Message amqpMessage) { + public CreateCommentResponseDto processCommentMessage2(CommentMessage commentMessage) { try { // 게시글 조회 diff --git a/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/LikeV1Consumer.java b/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/LikeV1Consumer.java index e4a278d..7222abc 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/LikeV1Consumer.java +++ b/src/main/java/com/daon/onjung/suggestion/application/controller/consumer/LikeV1Consumer.java @@ -5,6 +5,7 @@ import com.daon.onjung.core.exception.error.ErrorCode; import com.daon.onjung.core.exception.type.CommonException; import com.daon.onjung.suggestion.application.dto.request.LikeMessage; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import com.daon.onjung.suggestion.domain.Board; import com.daon.onjung.suggestion.domain.Like; import com.daon.onjung.suggestion.domain.service.BoardService; @@ -30,7 +31,7 @@ public class LikeV1Consumer { @Transactional @RabbitListener(queues = "like-queue") - public void processLikeMessage(LikeMessage likeMessage) { + public Boolean processLikeMessage(LikeMessage likeMessage) { try { // 게시글 조회 @@ -52,6 +53,7 @@ public void processLikeMessage(LikeMessage likeMessage) { // 게시글 좋아요 수 감소 board = boardService.subtractLikeCount(board); boardRepository.save(board); + return false; } else { // 좋아요가 존재하지 않으면 생성 @@ -60,6 +62,7 @@ public void processLikeMessage(LikeMessage likeMessage) { // 게시글 좋아요 수 증가 board = boardService.addLikeCount(board); boardRepository.save(board); + return true; } } catch (OptimisticEntityLockException e) { throw new CommonException(ErrorCode.OPTIMISTIC_EXCEPTION); diff --git a/src/main/java/com/daon/onjung/suggestion/application/controller/producer/LikeV1Producer.java b/src/main/java/com/daon/onjung/suggestion/application/controller/producer/LikeV1Producer.java index 2da27c5..432bd77 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/controller/producer/LikeV1Producer.java +++ b/src/main/java/com/daon/onjung/suggestion/application/controller/producer/LikeV1Producer.java @@ -1,6 +1,7 @@ package com.daon.onjung.suggestion.application.controller.producer; import com.daon.onjung.suggestion.application.dto.request.LikeMessage; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import com.daon.onjung.suggestion.application.usecase.SendLikeRequestUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,8 +12,8 @@ public class LikeV1Producer { private final SendLikeRequestUseCase sendLikeRequestUseCase; - public void sendLike (LikeMessage likeMessage) { - sendLikeRequestUseCase.execute(likeMessage); + public CreateOrDeleteLikeResponseDto sendLike (LikeMessage likeMessage) { + return sendLikeRequestUseCase.execute(likeMessage); } } diff --git a/src/main/java/com/daon/onjung/suggestion/application/dto/response/CreateOrDeleteLikeResponseDto.java b/src/main/java/com/daon/onjung/suggestion/application/dto/response/CreateOrDeleteLikeResponseDto.java new file mode 100644 index 0000000..5ce7ea7 --- /dev/null +++ b/src/main/java/com/daon/onjung/suggestion/application/dto/response/CreateOrDeleteLikeResponseDto.java @@ -0,0 +1,26 @@ +package com.daon.onjung.suggestion.application.dto.response; + +import com.daon.onjung.core.dto.SelfValidating; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class CreateOrDeleteLikeResponseDto extends SelfValidating { + + @JsonProperty("is_like") + private final Boolean isLike; + + @Builder + public CreateOrDeleteLikeResponseDto(Boolean isLike) { + this.isLike = isLike; + + this.validateSelf(); + } + + public static CreateOrDeleteLikeResponseDto of(Boolean isLike) { + return CreateOrDeleteLikeResponseDto.builder() + .isLike(isLike) + .build(); + } +} diff --git a/src/main/java/com/daon/onjung/suggestion/application/service/CreateOrDeleteLikeService.java b/src/main/java/com/daon/onjung/suggestion/application/service/CreateOrDeleteLikeService.java index 6c0089d..2e21dda 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/service/CreateOrDeleteLikeService.java +++ b/src/main/java/com/daon/onjung/suggestion/application/service/CreateOrDeleteLikeService.java @@ -2,6 +2,7 @@ import com.daon.onjung.suggestion.application.controller.producer.LikeV1Producer; import com.daon.onjung.suggestion.application.dto.request.LikeMessage; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import com.daon.onjung.suggestion.application.usecase.CreateOrDeleteLikeUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,9 +18,9 @@ public class CreateOrDeleteLikeService implements CreateOrDeleteLikeUseCase { @Override @Transactional - public void execute(UUID accountId, Long boardId) { + public CreateOrDeleteLikeResponseDto execute(UUID accountId, Long boardId) { - likeProducer.sendLike(LikeMessage.builder() + return likeProducer.sendLike(LikeMessage.builder() .boardId(boardId) .userId(accountId) .build()); diff --git a/src/main/java/com/daon/onjung/suggestion/application/service/SendLikeRequestService.java b/src/main/java/com/daon/onjung/suggestion/application/service/SendLikeRequestService.java index 7fea94b..e4833ea 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/service/SendLikeRequestService.java +++ b/src/main/java/com/daon/onjung/suggestion/application/service/SendLikeRequestService.java @@ -1,6 +1,7 @@ package com.daon.onjung.suggestion.application.service; import com.daon.onjung.suggestion.application.dto.request.LikeMessage; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import com.daon.onjung.suggestion.application.usecase.SendLikeRequestUseCase; import lombok.RequiredArgsConstructor; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -13,7 +14,9 @@ public class SendLikeRequestService implements SendLikeRequestUseCase { private final RabbitTemplate rabbitTemplate; @Override - public void execute(LikeMessage likeMessage) { - rabbitTemplate.convertAndSend("like-queue", likeMessage); + public CreateOrDeleteLikeResponseDto execute(LikeMessage likeMessage) { + + Boolean response = (Boolean) rabbitTemplate.convertSendAndReceive("like-queue", likeMessage); + return CreateOrDeleteLikeResponseDto.of(response); } } diff --git a/src/main/java/com/daon/onjung/suggestion/application/usecase/CreateOrDeleteLikeUseCase.java b/src/main/java/com/daon/onjung/suggestion/application/usecase/CreateOrDeleteLikeUseCase.java index 17bdde5..f50b048 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/usecase/CreateOrDeleteLikeUseCase.java +++ b/src/main/java/com/daon/onjung/suggestion/application/usecase/CreateOrDeleteLikeUseCase.java @@ -1,11 +1,12 @@ package com.daon.onjung.suggestion.application.usecase; import com.daon.onjung.core.annotation.bean.UseCase; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; import java.util.UUID; @UseCase public interface CreateOrDeleteLikeUseCase { - void execute(UUID accountId, Long boardId); + CreateOrDeleteLikeResponseDto execute(UUID accountId, Long boardId); } diff --git a/src/main/java/com/daon/onjung/suggestion/application/usecase/SendLikeRequestUseCase.java b/src/main/java/com/daon/onjung/suggestion/application/usecase/SendLikeRequestUseCase.java index 4742a64..333567d 100644 --- a/src/main/java/com/daon/onjung/suggestion/application/usecase/SendLikeRequestUseCase.java +++ b/src/main/java/com/daon/onjung/suggestion/application/usecase/SendLikeRequestUseCase.java @@ -2,8 +2,9 @@ import com.daon.onjung.core.annotation.bean.UseCase; import com.daon.onjung.suggestion.application.dto.request.LikeMessage; +import com.daon.onjung.suggestion.application.dto.response.CreateOrDeleteLikeResponseDto; @UseCase public interface SendLikeRequestUseCase { - void execute(LikeMessage likeMessage); + CreateOrDeleteLikeResponseDto execute(LikeMessage likeMessage); }