Skip to content

Commit 7c17a3f

Browse files
authored
Merge pull request #135 from Capstone-4Potato/feature/withdrawal
[Feat] : home api에 lastlogindate 추가
2 parents b9f069c + 79ca410 commit 7c17a3f

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/main/java/com/potato/balbambalbam/data/repository/UserAttendanceRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.potato.balbambalbam.data.entity.UserAttendance;
44
import java.time.LocalDate;
5+
import java.util.Optional;
56
import org.springframework.data.jpa.repository.JpaRepository;
67
import org.springframework.data.jpa.repository.Modifying;
78
import org.springframework.data.jpa.repository.Query;
@@ -36,4 +37,7 @@ List<UserAttendance> findWeeklyAttendance(@Param("userId") Long userId,
3637

3738
@Query("SELECT COUNT(ua) FROM user_attendance ua WHERE ua.userId = :userId AND ua.isPresent = :isPresent")
3839
Long countByUserIdAndIsPresent(@Param("userId") Long userId, @Param("isPresent") Boolean isPresent);
40+
41+
Optional<UserAttendance> findTopByUserIdAndAttendanceDateBeforeOrderByAttendanceDateDesc(Long userId, LocalDate today);
42+
3943
}

src/main/java/com/potato/balbambalbam/user/home/controller/HomeController.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
@Tag(name = "Home API", description = "홈 화면에 필요한 사용자 레벨, 레벨 경험치, 사용자 경험치, 주간 출석 상황, 오늘의 추천 단어를 반환한다. ")
2424
public class HomeController {
2525

26-
private final JoinService joinService;
2726
private final JWTUtil jwtUtil;
2827
private final HomeInfoService homeInfoService;
29-
private final NotificationService notificationService;
30-
3128

3229
@Operation(summary = "홈 화면 정보 조회", description = "사용자의 홈 화면에 필요한 모든 정보를 반환한다.")
3330
@ApiResponses(value = {

src/main/java/com/potato/balbambalbam/user/home/dto/HomeInfoDto.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.potato.balbambalbam.user.home.dto;
22

33
import io.swagger.v3.oas.annotations.media.Schema;
4+
import java.time.LocalDate;
45
import lombok.Getter;
56
import lombok.Setter;
67

@@ -33,4 +34,6 @@ public class HomeInfoDto {
3334
private Long customCardNumber;
3435
@Schema(description = "읽지 않은 알림 존재 여부", example = "true")
3536
private boolean hasUnreadNotifications;
37+
@Schema(description = "최근 로그인 날짜", example = "2025-02-17")
38+
private LocalDate lastLoginDate;
3639
}

src/main/java/com/potato/balbambalbam/user/home/service/HomeInfoService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.time.temporal.TemporalAdjusters;
2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.Optional;
2324
import lombok.RequiredArgsConstructor;
2425
import lombok.extern.slf4j.Slf4j;
2526
import org.springframework.stereotype.Service;
@@ -47,6 +48,7 @@ public HomeInfoDto getHomeInfo(Long userId) {
4748
setDailyWordInfo(homeInfoDto);
4849
setUserNumInfo(userId, homeInfoDto);
4950
homeInfoDto.setHasUnreadNotifications(notificationService.hasUnreadNotifications(userId));
51+
setLastLoginDate(userId, homeInfoDto);
5052

5153
return homeInfoDto;
5254
}
@@ -129,4 +131,16 @@ private void setUserNumInfo(Long userId, HomeInfoDto homeInfoDto) {
129131
homeInfoDto.setCustomCardNumber(customCards);
130132
}
131133

134+
private void setLastLoginDate(Long userId, HomeInfoDto homeInfoDto) {
135+
LocalDate today = LocalDate.now();
136+
Optional<UserAttendance> lastAttendance = userAttendanceRepository
137+
.findTopByUserIdAndAttendanceDateBeforeOrderByAttendanceDateDesc(userId, today);
138+
139+
if (lastAttendance.isPresent()) {
140+
homeInfoDto.setLastLoginDate(lastAttendance.get().getAttendanceDate());
141+
} else {
142+
homeInfoDto.setLastLoginDate(null);
143+
}
144+
}
145+
132146
}

0 commit comments

Comments
 (0)