Skip to content

Commit

Permalink
Merge pull request #65 from BbeumbungE/hotfix/BACK-257
Browse files Browse the repository at this point in the history
fix: 주제별 게시물 조회 누락 정보 수정 [BACK-257]
  • Loading branch information
Fishphobiagg authored Sep 26, 2023
2 parents 594fbaa + 225d1ff commit e5d1aca
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.siliconvalley.domain.item.subject.dao;

import com.siliconvalley.domain.item.subject.domain.Subject;
import com.siliconvalley.domain.item.subject.dto.SubjectCachingDto;
import com.siliconvalley.domain.item.subject.exception.SubjectNotFoundException;
import com.siliconvalley.domain.pix2pix.dto.Pix2PixAndSubjectDto;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
Expand All @@ -29,9 +29,9 @@ public Subject findById(Long subjectId) {
}

@Cacheable(key = "'subject:' + #subjectId", value = "subjectCache")
public Pix2PixAndSubjectDto findSubjectForCachingById(Long subjectId){
public SubjectCachingDto findSubjectForCachingById(Long subjectId){
Optional<Subject> subject = subjectRepository.findById(subjectId);
subject.orElseThrow(() -> new SubjectNotFoundException(subjectId));
return new Pix2PixAndSubjectDto(subject.get());
return new SubjectCachingDto(subject.get());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.siliconvalley.domain.item.subject.dto;

import com.siliconvalley.domain.item.subject.domain.Subject;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SubjectCachingDto {

private Long subjectId;
private String subjectName;
private String subjectImage;

@Builder
public SubjectCachingDto(Subject subject){
this.subjectId = subject.getId();
this.subjectName = subject.getSubjectName();
this.subjectImage = subject.getSubjectImage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Pix2PixFindDao {

private final Pix2PixRepository pix2PixRepository;

@Cacheable(key = "'subject:'+ #subject", value = "subjectCache")
@Cacheable(key = "'subject:'+ #subject", value = "subjectAndModelCache")
public UseModelDto findBySubjectId(Long subjectId){
Pix2Pix pix2Pix = pix2PixRepository.findBySubjectId(subjectId);
return new UseModelDto(pix2Pix);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/siliconvalley/domain/post/dao/PostFindDao.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.siliconvalley.domain.post.dao;

import com.siliconvalley.domain.item.subject.dao.SubjectFindDao;
import com.siliconvalley.domain.item.subject.domain.Subject;
import com.siliconvalley.domain.item.subject.dto.SubjectCachingDto;
import com.siliconvalley.domain.post.code.PostCode;
import com.siliconvalley.domain.post.domain.Post;
import com.siliconvalley.domain.post.dto.PostListResponse;
import com.siliconvalley.domain.post.dto.PostDetailResponse;
import com.siliconvalley.domain.post.dto.PostSubjectResponse;
import com.siliconvalley.domain.post.exception.PostNotFoundException;
import com.siliconvalley.global.common.dto.Response;
Expand All @@ -15,9 +14,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


@Service
@RequiredArgsConstructor
Expand All @@ -26,6 +24,7 @@ public class PostFindDao {

private final PostRepository postRepository;
private final PostCustomRepository postCustomRepository;
private final SubjectFindDao subjectFindDao;

public Post findById(Long targetId){
final Optional<Post> post = postRepository.findById(targetId);
Expand All @@ -40,7 +39,8 @@ public Response findAll(Pageable pageable){

public Response getPostsBySubjectName(Long subjectId, Pageable pageable) {
Page<PostListResponse> postListResponses = postCustomRepository.findBySubjectId(subjectId, pageable);
return Response.of(PostCode.POST_RETRIEVE_SUCCESS, postListResponses);
SubjectCachingDto dto = subjectFindDao.findSubjectForCachingById(subjectId);
return Response.of(PostCode.POST_RETRIEVE_SUCCESS, new PostSubjectResponse(dto, postListResponses));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.siliconvalley.domain.post.dto;

import com.siliconvalley.domain.item.subject.domain.Subject;
import com.siliconvalley.domain.item.subject.dto.SubjectCachingDto;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -18,10 +19,10 @@ public class PostSubjectResponse {
private int currentPage;
private int totalPages;

public PostSubjectResponse(Subject subject, Page<PostListResponse> postPage){
this.subjectId = subject.getId();
this.subjectName = subject.getSubjectName();
this.subjectImage = subject.getSubjectImage();
public PostSubjectResponse(SubjectCachingDto dto, Page<PostListResponse> postPage){
this.subjectId = dto.getSubjectId();
this.subjectName = dto.getSubjectName();
this.subjectImage = dto.getSubjectImage();
this.postLists = postPage.getContent();
this.currentPage = postPage.getNumber();
this.totalPages = postPage.getTotalPages();
Expand Down

0 comments on commit e5d1aca

Please sign in to comment.