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 @@ -54,4 +54,12 @@ public CustomResponse<?> createUserMealPlan(

return CustomResponse.onSuccess(GeneralSuccessCode.OK);
}

@GetMapping("/user")
@Operation(summary = "유저의 MealPlanId 존재 여부 확인 API")
public CustomResponse<?> getUserMealPlansId() {

User user = userService.getAuthenticatedUserInfo();
return CustomResponse.onSuccess(GeneralSuccessCode.OK, mealPlanQueryService.getMealPlans(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class MealPlanResponseDTO {
public static class MealPlanGetResponseDTO {

private Long userId;
private Long planMealId;
private Long mealPlanId;
private LocalDate startDate;
private LocalDate endDate;
private List<DailyMealInfoDTO> dailyMeals;

public static MealPlanGetResponseDTO from(Long userId, MealPlan mealPlan) {
return MealPlanGetResponseDTO.builder()
.userId(userId)
.planMealId(mealPlan.getId())
.mealPlanId(mealPlan.getId())
.startDate(mealPlan.getStartDate())
.endDate(mealPlan.getEndDate())
.dailyMeals(mealPlan.getDailyMeals().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
@RequiredArgsConstructor
public enum MealPlanErrorCode implements BaseErrorCode {

MEAL_PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "MEAL_PLAN_NOT_FOUND", "해당 Id의 일주일 식단이 없습니다.")
MEAL_PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "MEAL_PLAN_NOT_FOUND", "해당 Id의 일주일 식단이 없습니다."),
USER_MEAL_PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "USER_MEAL_PLAN_NOT_FOUND", "유저의 mealPlan(식단)이 존재 하지 않습니다.")
;



private final HttpStatus status;
private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import org.springframework.stereotype.Repository;
import umc7th.bulk.mealPlan.entity.MealPlan;

import java.util.List;

@Repository
public interface MealPlanRepository extends JpaRepository<MealPlan, Long> {
List<MealPlan> findByUserId(Long userId);

// @Query("SELECT mp FROM MealPlan mp WHERE mp.user.id = :userId ORDER BY mp.createdAt DESC")
MealPlan findByUserId(Long userId);

// List<MealPlan> findByIdWithDailyMeals(Long mealPlanId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package umc7th.bulk.mealPlan.service.query;

import umc7th.bulk.mealPlan.entity.MealPlan;
import umc7th.bulk.user.domain.User;

import java.util.List;

public interface MealPlanQueryService {

// MealPlan getMealPlan(Long userId, Long mealPlanId, int pageSize);
MealPlan getMealPlan(Long userId, Long mealPlanId);

List<Long> getMealPlans(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import umc7th.bulk.user.exception.UserException;
import umc7th.bulk.user.repository.UserRepository;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional
Expand All @@ -32,4 +34,18 @@ public MealPlan getMealPlan(Long userId, Long mealPlanId) {
}
return mealPlan;
}

@Override
public List<Long> getMealPlans(User user) {

List<MealPlan> userMealPlans = mealPlanRepository.findByUserId(user.getId());
if (userMealPlans.isEmpty()) {
throw new MealPlanException(MealPlanErrorCode.USER_MEAL_PLAN_NOT_FOUND);
}

return userMealPlans.stream()
.map(mealPlan -> mealPlan.getId())
.toList();

}
}