Skip to content

Commit 2457ff8

Browse files
authored
Merge pull request #66 from Phonesonal-Trainer/mong/feat/report#2
리포트 기능 추가
2 parents 0b5732c + cec3a26 commit 2457ff8

File tree

15 files changed

+542
-6
lines changed

15 files changed

+542
-6
lines changed

src/main/java/Phonesonal/PhoneBE/apiPayload/code/status/ErrorStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum ErrorStatus implements BaseErrorCode {
3232

3333
// 목표 관리 에러
3434
INVALID_GOAL_PERIOD(HttpStatus.BAD_REQUEST, "GOAL4002","해당 목표 기간이 존재하지 않습니다."),
35+
INVALID_WEEK(HttpStatus.BAD_REQUEST, "GOAL4003","범위에 해당하지 않는 주차입니다."),
3536

3637
//운동 관련 에러
3738
EXERCISE_NOT_FOUND(HttpStatus.NOT_FOUND, "EXERCISE4041", "운동을 찾을 수 없습니다."),

src/main/java/Phonesonal/PhoneBE/apiPayload/code/util/DateUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,23 @@ public static int calculateWeek(LocalDate startDate, LocalDate now) {
1616
long weeksBetween = ChronoUnit.WEEKS.between(startMonday, currentMonday);
1717
return (int) weeksBetween+1;
1818
}
19+
20+
public static LocalDate[] getWeekDateRange(LocalDate startDate, LocalDate endDate, int week) {
21+
// 기준일의 주의 월요일 구하기
22+
LocalDate startMonday = startDate.with(DayOfWeek.MONDAY);
23+
24+
// 입력된 주차에 해당하는 주의 월요일 구하기
25+
LocalDate targetMonday = startMonday.plusWeeks(week - 1);
26+
LocalDate targetSunday = targetMonday.plusDays(6);
27+
28+
// endDate를 넘지 않도록 조정
29+
if (targetMonday.isAfter(endDate)) {
30+
return null; // 유효하지 않은 주차
31+
}
32+
if (targetSunday.isAfter(endDate)) {
33+
targetSunday = endDate; // 범위를 endDate까지 제한
34+
}
35+
36+
return new LocalDate[]{targetMonday, targetSunday};
37+
}
1938
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package Phonesonal.PhoneBE.domain.enums;
22

33
public enum ExerciseFeedback {
4-
LONG, SHORT, HIGH, LOW;
4+
MANY, LESS, HIGH, LOW, DISLIKE;
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package Phonesonal.PhoneBE.domain.enums;
22

33
public enum FoodFeedback {
4-
LESS, MUCH, DISLIKE;
4+
LESS, MANY, DISLIKE;
55
}

src/main/java/Phonesonal/PhoneBE/repository/DailyExerciseRecordRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import org.springframework.data.jpa.repository.JpaRepository;
66

77
import java.time.LocalDate;
8+
import java.util.List;
89
import java.util.Optional;
910

1011
public interface DailyExerciseRecordRepository extends JpaRepository<DailyExerciseRecord, Long> {
1112
Optional<DailyExerciseRecord> findByUserAndDate(User user, LocalDate date);
13+
List<DailyExerciseRecord> findAllByUserIdAndDateBetween(Long userId, LocalDate start, LocalDate end);
1214
}

src/main/java/Phonesonal/PhoneBE/repository/FeedbackRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public interface FeedbackRepository extends JpaRepository<Feedback, Long> {
1010
Optional<Feedback> findByUserIdAndGoalPeriod_IdAndWeek(Long userId, Long goalPeriodId, Integer week);
11-
11+
boolean existsByUserIdAndGoalPeriod_IdAndWeek(Long userId, Long goalPeriodId, int week);
1212

1313

1414
}

src/main/java/Phonesonal/PhoneBE/repository/RecommendMealRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public interface RecommendMealRepository extends JpaRepository<RecommendMeal, Lo
1717

1818
// 특정 날짜, mealTime 별 (식단 플랜)
1919
List<RecommendMeal> findByGoalPeriodAndDateAndMealTime(GoalPeriod goalPeriod, LocalDate date, MealTime mealTime);
20+
List<RecommendMeal> findByUserIdAndGoalPeriodIdAndDateBetweenAndComplete(
21+
Long userId, Long goalPeriodId, LocalDate weekStart, LocalDate weekEnd, CompleteStatus completeStatus
22+
);
23+
List<RecommendMeal> findByUserIdAndGoalPeriodIdAndDateBetween(
24+
Long userId, Long goalPeriodId, LocalDate weekStart, LocalDate weekEnd
25+
);
2026

2127
// completeStatus 수정용
2228
@Modifying(clearAutomatically = true)

src/main/java/Phonesonal/PhoneBE/repository/UserExerciseRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package Phonesonal.PhoneBE.repository;
22

3+
import Phonesonal.PhoneBE.domain.User;
4+
import Phonesonal.PhoneBE.domain.common.GoalPeriod;
35
import Phonesonal.PhoneBE.domain.enums.exercise.ExerciseType;
46
import Phonesonal.PhoneBE.domain.mapping.UserExercise;
57
import org.springframework.data.jpa.repository.JpaRepository;
@@ -19,6 +21,10 @@ public interface UserExerciseRepository extends JpaRepository<UserExercise, Long
1921
// 사용자의 북마크된 운동 목록 조회
2022
List<UserExercise> findByUserIdAndBookmarkTrue(Long userId);
2123

24+
List<UserExercise> findByUserIdAndGoalPeriodIdAndExerciseDateBetween(
25+
Long userId, Long goalPeriodId, LocalDate start, LocalDate end
26+
);
27+
2228
// 특정 사용자의 특정 운동 조회
2329
@Query("SELECT ue FROM UserExercise ue WHERE ue.user.id = :userId AND ue.exercise.id = :exerciseId")
2430
List<UserExercise> findByUserIdAndExerciseId(@Param("userId") Long userId, @Param("exerciseId") Long exerciseId);

src/main/java/Phonesonal/PhoneBE/repository/UserMealRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
public interface UserMealRepository extends JpaRepository<UserMeal, Long> {
1616
// 특정 날짜, 식사 시간 별 조회 (추가 식단)
1717
List<UserMeal> findByGoalPeriodAndDateAndMealTime(GoalPeriod goalPeriod, LocalDate date, MealTime mealTime);
18+
List<UserMeal> findByUserIdAndGoalPeriodIdAndDateBetween(
19+
Long userId, Long goalPeriodId, LocalDate weekStart, LocalDate weekEnd
20+
);
1821

1922
//홈화면 오늘 섭취 칼로리를 위한 데이터
2023
@Query("SELECT um FROM UserMeal um JOIN FETCH um.food WHERE um.user.id = :userId AND um.date = :date")

src/main/java/Phonesonal/PhoneBE/repository/WeightRecordRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
import org.springframework.data.jpa.repository.Query;
66
import org.springframework.data.repository.query.Param;
77

8+
import java.time.LocalDateTime;
9+
import java.util.List;
810
import java.util.Optional;
911

1012

1113
public interface WeightRecordRepository extends JpaRepository<WeightRecord, Long> {
1214
@Query(value = "SELECT * FROM weight_record WHERE user_id = :userId ORDER BY record_date DESC LIMIT 1", nativeQuery = true)
1315
Optional<WeightRecord> findLatestByUserId(@Param("userId") Long userId);
16+
17+
List<WeightRecord> findByUserIdAndGoalPeriodIdAndRecordDateBetween(
18+
Long userId,
19+
Long goalPeriodId,
20+
LocalDateTime start,
21+
LocalDateTime end
22+
);
1423
}

0 commit comments

Comments
 (0)