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 @@ -18,7 +18,7 @@

@Getter
@Entity
@Table(name = "daily_record_contets")
@Table(name = "daily_record_contents")
@NoArgsConstructor
public class DailyRecordContent extends BaseTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public void deletePost(
@Operation(summary = "홈 화면 게시글 미리보기 (카테고리 별 각 6개씩)")
@GetMapping("/home")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<FindPostPreviewResponseDto>> getLatestPosts(
@OptionalLogIn Long userId
) {
return ApiResponseDto.of(postQueryService.findLatestPostByCategory(userId));
public ApiResponseDto<List<FindPostPreviewResponseDto>> getLatestPosts() {
return ApiResponseDto.of(postQueryService.findLatestPostByCategory());
}

@Operation(summary = "카테고리별 게시글 목록 조회 (pageNumber는 1부터 시작)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ Optional<FindPostDto> findPost(
Long userId
);

List<FindPostPreviewResponseDto> findTop6TodayByCategoryWithUserName(
Long loginUserId,
Long categoryId
);
List<FindPostPreviewResponseDto> findTop6TodayByCategoryWithUserName(Long categoryId);

Page<FindAllPostResponseDto> findAllByCategoryWithUserName(
Long loginUserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public record FindPostPreviewResponseDto(
Long likeCount,
Long commentCount,
LocalDateTime createdAt,
LocalDateTime lastModifiedAt,
boolean isLike
LocalDateTime lastModifiedAt
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ Optional<FindPostDto> findPost(
@Override
@Query("""
SELECT new swyp.team5.greening.post.dto.response.FindPostPreviewResponseDto(
post.id, post.categoryId, post.userId, user.userName, post.title, c.content,
post.likeCount, post.commentCount, post.createdAt, post.updatedAt,
case when likes.id is not null then true else false end)
post.id, post.categoryId, post.userId, user.userName, post.title,
case when c.type = 'IMAGE' then '이미지' else c.content end,
post.likeCount, post.commentCount, post.createdAt, post.updatedAt)
FROM Post post
INNER JOIN User user
ON user.id = post.userId
LEFT JOIN PostContent c
ON c.post = post
AND c.sequence = 1
LEFT JOIN Like likes
ON likes.postId = post.id
AND likes.userId = :loginUserId
WHERE post.categoryId = :categoryId
AND post.state = 'IN_PROGRESS'
ORDER BY post.likeCount DESC
LIMIT 6
""")
List<FindPostPreviewResponseDto> findTop6TodayByCategoryWithUserName(
@Param("loginUserId") Long loginUserId,
@Param("categoryId") Long categoryId
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -43,10 +44,10 @@ public FindPostResponseDto findPost(Long postId, Long userId) {

// 홈 화면 게시글
@Transactional(readOnly = true)
public List<FindPostPreviewResponseDto> findLatestPostByCategory(Long userId) {
return List.of(1L, 2L, 3L).stream()
public List<FindPostPreviewResponseDto> findLatestPostByCategory() {
return Stream.of(1L, 2L, 3L)
.flatMap(categoryId ->
postQueryRepository.findTop6TodayByCategoryWithUserName(userId, categoryId)
postQueryRepository.findTop6TodayByCategoryWithUserName(categoryId)
.stream())
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,8 @@ void getLatestPosts() throws Exception {
mockMvc.perform(get("/api/posts/home"))
.andExpect(jsonPath("$.data.size()").value(2))
.andExpect(jsonPath("$.data[0].postId").value(post.getId()))
.andExpect(jsonPath("$.data[0].isLike").value(false))
.andExpect(jsonPath("$.data[0].userId").value(loginUser.getId()))
.andExpect(jsonPath("$.data[1].postId").value(anotherPost.getId()))
.andExpect(jsonPath("$.data[1].isLike").value(false))
.andExpect(jsonPath("$.data[1].userId").value(anotherUser.getId()));
}

Expand All @@ -260,10 +258,8 @@ void getLatestPosts2() throws Exception {
.header(HttpHeaders.AUTHORIZATION, accessToken))
.andExpect(jsonPath("$.data.size()").value(2))
.andExpect(jsonPath("$.data[0].postId").value(post.getId()))
.andExpect(jsonPath("$.data[0].isLike").value(false))
.andExpect(jsonPath("$.data[0].userId").value(loginUser.getId()))
.andExpect(jsonPath("$.data[1].postId").value(anotherPost.getId()))
.andExpect(jsonPath("$.data[1].isLike").value(true))
.andExpect(jsonPath("$.data[1].userId").value(anotherUser.getId()));
}

Expand Down
Loading