Skip to content

Commit

Permalink
Feat: 푸바오 받은 사랑 (#61)
Browse files Browse the repository at this point in the history
redis에 있는 값 가져오고 없으면 rds에서 가져온 후 redis에 저장

#60
  • Loading branch information
wcorn authored Dec 31, 2023
1 parent 7ab1e32 commit 82fc96e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,9 @@ public ResponseEntity<DataResponse<CustomResponseCode>> postFubaoLove() {
postService.addFubaoLove();
return ResponseEntity.ok(DataResponse.of(CustomResponseCode.FUBAO_LOVE_ADD));
}
@Operation(summary = "푸바오받은 사랑")
@GetMapping(value = "/fubao/love")
public ResponseEntity<DataResponse<PostGetFubaoLoveResponse>> getFubaoLove() {
return ResponseEntity.ok(DataResponse.of(postService.getFubaoLove()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface PostService {
void deletePost(Long postId, UUID memberId);

void addFubaoLove();

PostGetFubaoLoveResponse getFubaoLove();
}
11 changes: 11 additions & 0 deletions src/main/java/com/fubao/project/domain/service/PostServiceImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 82fc96e

Please sign in to comment.