Skip to content

Commit

Permalink
fix: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 24, 2024
1 parent 16c9a0f commit acd4d97
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.foodgo.apimodule.community.dto.FriendRequestList;
import com.foodgo.apimodule.community.dto.FriendSearchList;
import com.foodgo.coremodule.community.domain.Challenge;
import com.foodgo.coremodule.community.domain.ChallengeType;
import com.foodgo.coremodule.community.domain.Friendship;
import com.foodgo.coremodule.community.service.ChallengeQueryService;
import com.foodgo.coremodule.community.service.FriendQueryService;
Expand All @@ -12,7 +13,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

Expand All @@ -26,68 +26,22 @@ public class FriendFindUseCase {
private final ChallengeQueryService challengeQueryService;

public List<FriendSearchList> findFriendList(User myUser) {

// 전체 친구 목록을 가져옴
List<User> users = userQueryService.findAllUsers();

return users.stream()
.filter(user -> friendQueryService.checkFriendShipYn(myUser.getId(), user.getId()))
.map(user -> {

Challenge challenge = challengeQueryService.findRecentChallenge(user.getId());
if (challenge == null) {
challenge = Challenge.builder()
.totalCalorie(0)
.carbRate(0)
.proteinRate(0)
.fatRate(0)
.year(0)
.month(0)
.date(0)
.build();
}

Friendship friendship = friendQueryService.findByUserIdAndFriendId(myUser.getId(), user.getId());
if (friendship == null) {
friendship = Friendship.createFriendship(myUser, user);
}

Boolean challengeYn = challengeQueryService.checkChallengeYn(friendship.getId());

return new FriendSearchList(
user.getId(),
user.getUsername(),
user.getImageUrl(),
challenge.getTotalCalorie(),
challenge.getCarbRate(),
challenge.getProteinRate(),
challenge.getFatRate(),
true,
friendship.getIsMutual(),
challengeYn
);
}).toList();
return processFriendSearchList(users, myUser);
}

public List<FriendSearchList> findFriendName(User myUser, String nickname) {

List<User> users = friendQueryService.findFriendWithNickname(nickname);
return processFriendSearchList(users, myUser);
}

private List<FriendSearchList> processFriendSearchList(List<User> users, User myUser) {
return users.stream()
.filter(user -> friendQueryService.checkFriendShipYn(myUser.getId(), user.getId()))
.map(user -> {

Challenge challenge = challengeQueryService.findRecentChallenge(user.getId());
if (challenge == null) {
challenge = Challenge.builder()
.totalCalorie(0)
.carbRate(0)
.proteinRate(0)
.fatRate(0)
.year(0)
.month(0)
.date(0)
.build();
challenge = createDefaultChallenge();
}

Friendship friendship = friendQueryService.findByUserIdAndFriendId(myUser.getId(), user.getId());
Expand All @@ -101,17 +55,25 @@ public List<FriendSearchList> findFriendName(User myUser, String nickname) {
user.getId(),
user.getUsername(),
user.getImageUrl(),
challenge.getTotalCalorie(),
challenge.getCarbRate(),
challenge.getProteinRate(),
challenge.getFatRate(),
challenge.getType(),
challenge.getValue(),
true,
friendship.getIsMutual(),
challengeYn
);
}).toList();
}

private Challenge createDefaultChallenge() {
return Challenge.builder()
.type(ChallengeType.NONE)
.value(0)
.year(0)
.month(0)
.date(0)
.build();
}

public List<FriendRequestList> findFriendRequestList(Long userId) {

return friendQueryService.findFriendRequestList(userId).stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.foodgo.apimodule.community.dto;

import com.foodgo.coremodule.community.domain.ChallengeType;

public record FriendSearchList(
Long userId,
String name,
String profileImg,
Integer recentTotalCalorie,
Integer recentCarbRate,
Integer recentProteinRate,
Integer recentFatRate,
ChallengeType challengeType,
Integer challengeValue,
Boolean friendYn,
Boolean friendRequestYn,
Boolean challengeYn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ApplicationResponse<String> makeChallenge(
}

// 챌린지 삭제
@PostMapping("/{challengeId}")
@DeleteMapping("/{challengeId}")
@ApiResponses(
value = {
@ApiResponse(
Expand All @@ -68,7 +68,7 @@ public ApplicationResponse<String> deleteChallenge(
}

// 챌린지 조회 (달성률 포함)
@PostMapping("/{challengeId}")
@GetMapping("/{challengeId}")
@ApiResponses(
value = {
@ApiResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public enum ChallengeType {
CARB("탄수화물"),
PROTEIN("단백질"),
FAT("지방"),
FREQUENCY("식사주기")
FREQUENCY("식사주기"),
NONE("없음")
;

private final String description;
Expand Down

0 comments on commit acd4d97

Please sign in to comment.