Skip to content

Commit

Permalink
fix: add worker id to param
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Dec 9, 2024
1 parent a54f71b commit 9480baf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface WorkoutHistoryCustomRepository {
List<WorkoutHistory> getAllByWorkspaceId(Long workspaceId, Pageable pageable);

List<WorkoutHistory> getAllByDate(LocalDate localDate);
List<WorkoutHistory> getAllByDate(Long workerId, LocalDate localDate);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package gymmi.workspace.repository.custom;

import com.querydsl.core.Tuple;
import com.querydsl.jpa.impl.JPAQueryFactory;
import gymmi.workspace.domain.entity.Objection;
import gymmi.workspace.domain.entity.WorkoutHistory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand All @@ -11,7 +9,6 @@
import java.time.LocalDateTime;
import java.util.List;

import static gymmi.workspace.domain.entity.QObjection.objection;
import static gymmi.workspace.domain.entity.QWorker.worker;
import static gymmi.workspace.domain.entity.QWorkoutConfirmation.workoutConfirmation;
import static gymmi.workspace.domain.entity.QWorkoutHistory.workoutHistory;
Expand Down Expand Up @@ -46,4 +43,16 @@ public List<WorkoutHistory> getAllByDate(LocalDate now) {
.fetch();
}

@Override
public List<WorkoutHistory> getAllByDate(Long workerId, LocalDate now) {
LocalDateTime startDay = now.atStartOfDay();
LocalDateTime endDay = now.plusDays(1).atStartOfDay();
return jpaQueryFactory.select(workoutHistory)
.from(workoutHistory)
.where(workoutHistory.createdAt.goe(startDay).and(workoutHistory.createdAt.before(endDay)
.and(workoutHistory.worker.id.eq(workerId))
))
.fetch();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -113,7 +116,7 @@ public Integer workMissionsInWorkspace(
Worker worker = workerRepository.getByUserIdAndWorkspaceId(loginedUser.getId(), workspace.getId());
List<Mission> missions = missionRepository.getAllByWorkspaceId(workspace.getId());
Map<Mission, Integer> workouts = getWorkouts(workoutRequest.getMissions());
validateDailyWorkoutHistoryCount();
validateDailyWorkoutHistoryCount(worker.getId());

WorkspaceProgressManager workspaceProgressManager = new WorkspaceProgressManager(workspace, missions);

Expand All @@ -136,8 +139,8 @@ public Integer workMissionsInWorkspace(
return workoutHistory.getSum();
}

private void validateDailyWorkoutHistoryCount() {
List<WorkoutHistory> workoutHistories = workoutHistoryRepository.getAllByDate(LocalDate.now());
private void validateDailyWorkoutHistoryCount(Long workerId) {
List<WorkoutHistory> workoutHistories = workoutHistoryRepository.getAllByDate(workerId, LocalDate.now());
if (workoutHistories.size() >= 3) {
throw new InvalidStateException(ErrorCode.EXCEED_MAX_DAILY_WORKOUT_HISTORY_COUNT);
}
Expand Down

0 comments on commit 9480baf

Please sign in to comment.