Skip to content

Commit

Permalink
Merge pull request #42 from Link-MIND/feature/#41
Browse files Browse the repository at this point in the history
[#41] fix : toastListDto추가
  • Loading branch information
sss4920 authored Jan 11, 2024
2 parents 521ef7b + 4d81d42 commit 191beef
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import lombok.Builder;

@Builder
public record CategoriesReponse(Long CategoryId, String categoryTitle, int toastNum) {
public record CategoriesReponse(Long categoryId, String categoryTitle, int toastNum) {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.app.toaster.controller.response.main;

import com.app.toaster.controller.response.category.CategoriesReponse;
import com.app.toaster.controller.response.toast.MainToastDto;
import com.app.toaster.domain.RecommendSite;
import lombok.Builder;

import java.util.ArrayList;
import java.util.List;

@Builder
public record MainPageResponseDto(String nickname, int readToastNum, int allToastNum, List<CategoriesReponse> mainCategoryListDto, List<RecommendSite> recommendedSiteListDto) {
public record MainPageResponseDto(String nickname, int readToastNum, int allToastNum, List<CategoriesReponse> mainCategoryListDto, List<MainToastDto> toastListDto, List<RecommendSite> recommendedSiteListDto) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.app.toaster.controller.response.toast;

import com.app.toaster.domain.Toast;

public record MainToastDto(Long toastId, String toastTitle, String toastImg, String toastLink) {
public static MainToastDto of(Toast toast){
return new MainToastDto(toast.getId(), toast.getTitle(), toast.getThumbnailUrl(), toast.getLinkUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public interface ToastRepository extends JpaRepository<Toast, Long> {
Long countALLByUserAndIsReadTrue(User user);

Long countAllByUserAndIsReadFalse(User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<CategoriesReponse> getCategories(Long userId){
return categoryRepository.findAllByUserOrderByPriority(presentUser)
.stream()
.map(category -> CategoriesReponse.builder()
.CategoryId(category.getCategoryId())
.categoryId(category.getCategoryId())
.categoryTitle(category.getTitle())
.toastNum(toastRepository.getAllByCategory(category).size()).build()
).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.app.toaster.controller.response.category.CategoriesReponse;
import com.app.toaster.controller.response.main.MainPageResponseDto;
import com.app.toaster.controller.response.toast.MainToastDto;
import com.app.toaster.domain.Category;
import com.app.toaster.domain.User;
import com.app.toaster.exception.Error;
Expand Down Expand Up @@ -37,10 +38,12 @@ public MainPageResponseDto getMainPage(Long userId) {
MainPageResponseDto mainPageResponseDto = MainPageResponseDto.builder().nickname(user.getNickname())
.allToastNum(allToastNum)
.readToastNum(readToastNum)
.toastListDto(toastRepository.findAll().subList(0,Math.min(3,toastRepository.findAll().size()))
.stream().map(MainToastDto::of).toList())
.recommendedSiteListDto(recommedSiteRepository.findAll().subList(0, Math.min(9, recommedSiteRepository.findAll().size())))
.mainCategoryListDto(getCategory(user).stream()
.map(category -> CategoriesReponse.builder()
.CategoryId(category.getCategoryId())
.categoryId(category.getCategoryId())
.categoryTitle(category.getTitle())
.toastNum(toastRepository.getAllByCategory(category).size()).build()
).collect(Collectors.toList())).build();
Expand Down

0 comments on commit 191beef

Please sign in to comment.