|
16 | 16 | import com.example.cp_main_be.domain.social.follow.domain.repository.FollowRepository; |
17 | 17 | import com.example.cp_main_be.global.common.CustomApiException; |
18 | 18 | import com.example.cp_main_be.global.common.ErrorCode; |
| 19 | +import com.example.cp_main_be.global.util.TimeUtil; |
19 | 20 | import java.time.LocalDateTime; |
20 | | -import java.time.ZoneId; |
21 | 21 | import java.util.*; |
22 | 22 | import java.util.stream.Collectors; |
23 | 23 | import lombok.RequiredArgsConstructor; |
@@ -165,10 +165,12 @@ public List<Long> getMyGardenIds(User user) { |
165 | 165 | * @return UserProfileResponse DTO |
166 | 166 | */ |
167 | 167 | public UserProfileResponse getUserProfile(Long currentUserId, Long profileUserId) { |
| 168 | + // 현재 로그인한 유저 |
168 | 169 | User currentUser = |
169 | 170 | userRepository |
170 | 171 | .findById(currentUserId) // ID로 최신 유저 정보를 조회합니다. |
171 | 172 | .orElseThrow(() -> new CustomApiException(ErrorCode.USER_NOT_FOUND)); |
| 173 | + // 프로필 조회할 유저 |
172 | 174 | User profileUser = |
173 | 175 | userRepository |
174 | 176 | .findByIdWithGardensAndAvatars(profileUserId) |
@@ -208,7 +210,7 @@ public UserProfileResponse getUserProfile(Long currentUserId, Long profileUserId |
208 | 210 | } |
209 | 211 |
|
210 | 212 | // 2. 남에게 물 줄 수 있는 남은 횟수 계산 |
211 | | - LocalDateTime startOfWateringDay = getStartOfCurrentWateringDay(); |
| 213 | + LocalDateTime startOfWateringDay = TimeUtil.getStartOfCurrentWateringDay(); |
212 | 214 |
|
213 | 215 | // 2-1. 프로필 주인이 남에게 물을 줄 수 있는 남은 횟수 (응답 DTO용) |
214 | 216 | int profileUserWateringCount = |
@@ -237,6 +239,7 @@ public UserProfileResponse getUserProfile(Long currentUserId, Long profileUserId |
237 | 239 | .map( |
238 | 240 | garden -> { |
239 | 241 | // DB를 반복 조회하는 대신, 미리 조회한 Set에서 확인하여 성능을 개선합니다. |
| 242 | + // 로그인한 유저가 해당 정원에 물을 아직 안줬고 횟수가 남았다면 true |
240 | 243 | boolean alreadyWateredByMe = wateredGardenIds.contains(garden.getId()); |
241 | 244 | boolean isWateringAbleByMe = |
242 | 245 | leftWaterCountForCurrentUser > 0 && !alreadyWateredByMe; |
@@ -268,16 +271,4 @@ public UserProfileResponse getUserProfile(Long currentUserId, Long profileUserId |
268 | 271 | .userGardens(userGardens) |
269 | 272 | .build(); |
270 | 273 | } |
271 | | - |
272 | | - // GardenService에 있던 private 메서드를 가져오거나 공통 유틸 클래스로 분리해야 합니다. |
273 | | - private LocalDateTime getStartOfCurrentWateringDay() { |
274 | | - LocalDateTime now = LocalDateTime.now(ZoneId.of("Asia/Seoul")); |
275 | | - LocalDateTime todayNoon = now.toLocalDate().atTime(12, 0); |
276 | | - |
277 | | - if (now.isBefore(todayNoon)) { |
278 | | - return todayNoon.minusDays(1); |
279 | | - } else { |
280 | | - return todayNoon; |
281 | | - } |
282 | | - } |
283 | 274 | } |
0 commit comments