diff --git a/src/main/java/com/fubao/project/domain/api/post/PostController.java b/src/main/java/com/fubao/project/domain/api/post/PostController.java index 8bcda6d..33e370d 100644 --- a/src/main/java/com/fubao/project/domain/api/post/PostController.java +++ b/src/main/java/com/fubao/project/domain/api/post/PostController.java @@ -113,4 +113,9 @@ public ResponseEntity> postFubaoLove() { postService.addFubaoLove(); return ResponseEntity.ok(DataResponse.of(CustomResponseCode.FUBAO_LOVE_ADD)); } + @Operation(summary = "푸바오받은 사랑") + @GetMapping(value = "/fubao/love") + public ResponseEntity> getFubaoLove() { + return ResponseEntity.ok(DataResponse.of(postService.getFubaoLove())); + } } \ No newline at end of file diff --git a/src/main/java/com/fubao/project/domain/api/post/dto/response/PostGetFubaoLoveResponse.java b/src/main/java/com/fubao/project/domain/api/post/dto/response/PostGetFubaoLoveResponse.java new file mode 100644 index 0000000..918d299 --- /dev/null +++ b/src/main/java/com/fubao/project/domain/api/post/dto/response/PostGetFubaoLoveResponse.java @@ -0,0 +1,16 @@ +package com.fubao.project.domain.api.post.dto.response; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class PostGetFubaoLoveResponse { + @Schema(description = "푸바오가 받은 사랑", example = "123456788") + private Long love; +} diff --git a/src/main/java/com/fubao/project/domain/service/PostService.java b/src/main/java/com/fubao/project/domain/service/PostService.java index 8f5e64d..9e4249a 100644 --- a/src/main/java/com/fubao/project/domain/service/PostService.java +++ b/src/main/java/com/fubao/project/domain/service/PostService.java @@ -25,4 +25,6 @@ public interface PostService { void deletePost(Long postId, UUID memberId); void addFubaoLove(); + + PostGetFubaoLoveResponse getFubaoLove(); } diff --git a/src/main/java/com/fubao/project/domain/service/PostServiceImp.java b/src/main/java/com/fubao/project/domain/service/PostServiceImp.java index 514267a..ba111b2 100644 --- a/src/main/java/com/fubao/project/domain/service/PostServiceImp.java +++ b/src/main/java/com/fubao/project/domain/service/PostServiceImp.java @@ -151,6 +151,17 @@ public void addFubaoLove() { addFubaoLove(1L); } + @Override + @Transactional + public PostGetFubaoLoveResponse getFubaoLove() { + FubaoLove fubaoLove = fubaoLoveRepository.getReferenceById(1L); + if (!redisUtil.hasKey(FUBAO_LOVE)) { + redisUtil.setStringData(FUBAO_LOVE, String.valueOf(fubaoLove.getLove()), Duration.ofHours(6)); + return new PostGetFubaoLoveResponse(fubaoLove.getLove()); + } + return new PostGetFubaoLoveResponse(Long.valueOf(redisUtil.getData(FUBAO_LOVE))); + } + private Post findPostById(Long postId) { return postRepository.findById(postId).orElseThrow(() -> new CustomException(ResponseCode.POST_NOT_FOUND)); }