Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -129,6 +129,33 @@ List<Community> findFeedByType(
Pageable pageable
);

/**
* CARDNEWS 탭 피드 조회.
*
* 정책/공모전 중 카드뉴스 이미지가 연결된 커뮤니티만 조회한다.
* 지역 조건은 사용하지 않는다.
*/
@Query("""
select c
from Community c
join fetch c.pin p
join fetch p.user
where c.communityType in :types
and c.cardnewsImages is not empty
and (
cast(:cursorCreatedAt as LocalDateTime) is null
or c.createdAt < :cursorCreatedAt
or (c.createdAt = :cursorCreatedAt and c.communityId < :cursorId)
)
order by c.createdAt desc, c.communityId desc
""")
List<Community> findCardnewsFeedByTypesWithImages(
@Param("types") Collection<CommunityType> types,
@Param("cursorCreatedAt") LocalDateTime cursorCreatedAt,
@Param("cursorId") Long cursorId,
Pageable pageable
);

/**
* ALL 피드 조회.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public class CommunityQueryServiceImpl implements CommunityQueryService {
CommunityType.CARDNEWS
);

private static final List<CommunityType> CARDNEWS_FEED_SOURCE_TYPES = List.of(
CommunityType.POLICY,
CommunityType.CONTEST
);

// HOT 인기 점수 계산용
private static final int HOT_DAYS = 7;
// 홈에서 사용
Expand Down Expand Up @@ -149,6 +154,26 @@ public CommunityCursorPageResDTO getCommunityFeed(
List<Community> pageItems = hasNext ? communities.subList(0, size) : communities;

List<CommunityFeedItemResDTO> content = toFeedItems(pageItems);
if (tab == CommunityTab.CARDNEWS) {
content = content.stream()
.map(item -> new CommunityFeedItemResDTO(
CommunityType.CARDNEWS,
item.communityId(),
item.pinId(),
item.title(),
item.content(),
item.thumbnailUrl(),
item.writerNickname(),
item.writerProfileUrl(),
item.detailAddress(),
item.viewCount(),
item.likeCount(),
item.discount(),
item.eventStartTime(),
item.eventEndTime()
))
.toList();
}
Comment on lines +157 to +176

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

CommunityFeedItemResDTO 객체의 모든 필드를 수동으로 복사하여 CommunityType.CARDNEWSkind만 변경하는 방식은 유지보수 관점에서 취약합니다. 향후 CommunityFeedItemResDTO에 필드가 추가되거나 삭제, 타입 변경이 일어날 경우 이 부분의 생성자 호출 코드도 함께 수정해야 하므로 에러가 발생하기 쉽습니다.

이를 개선하기 위해 CommunityFeedItemResDTO 레코드 내부에 특정 필드만 변경하여 새로운 인스턴스를 반환하는 withKind와 같은 메서드를 추가하는 것을 권장합니다.

추천 개선 방향:

  1. CommunityFeedItemResDTO 레코드에 아래와 같은 메서드를 추가합니다:
public CommunityFeedItemResDTO withKind(CommunityType newKind) {
    return new CommunityFeedItemResDTO(
            newKind,
            this.communityId,
            this.pinId,
            this.title,
            this.content,
            this.thumbnailUrl,
            this.writerNickname,
            this.writerProfileUrl,
            this.detailAddress,
            this.viewCount,
            this.likeCount,
            this.discount,
            this.eventStartTime,
            this.eventEndTime
    );
}
  1. 서비스 레이어에서는 제공된 코드 제안과 같이 간결하게 처리할 수 있습니다.
        if (tab == CommunityTab.CARDNEWS) {
            content = content.stream()
                    .map(item -> item.withKind(CommunityType.CARDNEWS))
                    .toList();
        }


String nextCursor = hasNext
? CursorKey.from(pageItems.get(pageItems.size() - 1)).encode()
Expand Down Expand Up @@ -272,8 +297,8 @@ private List<Community> fetchCommunities(CommunityTab tab, Long locationId, Curs
limit
);

case CARDNEWS -> communityRepository.findFeedByType(
CommunityType.CARDNEWS,
case CARDNEWS -> communityRepository.findCardnewsFeedByTypesWithImages(
CARDNEWS_FEED_SOURCE_TYPES,
cursorKey.createdAt(),
cursorKey.communityId(),
limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public OpenAPI openAPI() {
.description("IssueIssyu Local Server");

Server httpServer = new Server()
.url("http://issueissyu-backend-prod-env.eba-x2fpm3aq.ap-northeast-2.elasticbeanstalk.com")
.url("https://spring.issueissyu.cloud")
.description("IssueIssyu Prod Server");


Expand Down
Loading