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 @@ -2,6 +2,7 @@

import com.potato.balbambalbam.data.entity.UserAttendance;
import java.time.LocalDate;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -36,4 +37,7 @@ List<UserAttendance> findWeeklyAttendance(@Param("userId") Long userId,

@Query("SELECT COUNT(ua) FROM user_attendance ua WHERE ua.userId = :userId AND ua.isPresent = :isPresent")
Long countByUserIdAndIsPresent(@Param("userId") Long userId, @Param("isPresent") Boolean isPresent);

Optional<UserAttendance> findTopByUserIdAndAttendanceDateBeforeOrderByAttendanceDateDesc(Long userId, LocalDate today);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
@Tag(name = "Home API", description = "홈 화면에 필요한 사용자 레벨, 레벨 경험치, 사용자 경험치, 주간 출석 상황, 오늘의 추천 단어를 반환한다. ")
public class HomeController {

private final JoinService joinService;
private final JWTUtil jwtUtil;
private final HomeInfoService homeInfoService;
private final NotificationService notificationService;


@Operation(summary = "홈 화면 정보 조회", description = "사용자의 홈 화면에 필요한 모든 정보를 반환한다.")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.potato.balbambalbam.user.home.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -33,4 +34,6 @@ public class HomeInfoDto {
private Long customCardNumber;
@Schema(description = "읽지 않은 알림 존재 여부", example = "true")
private boolean hasUnreadNotifications;
@Schema(description = "최근 로그인 날짜", example = "2025-02-17")
private LocalDate lastLoginDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -47,6 +48,7 @@ public HomeInfoDto getHomeInfo(Long userId) {
setDailyWordInfo(homeInfoDto);
setUserNumInfo(userId, homeInfoDto);
homeInfoDto.setHasUnreadNotifications(notificationService.hasUnreadNotifications(userId));
setLastLoginDate(userId, homeInfoDto);

return homeInfoDto;
}
Expand Down Expand Up @@ -129,4 +131,16 @@ private void setUserNumInfo(Long userId, HomeInfoDto homeInfoDto) {
homeInfoDto.setCustomCardNumber(customCards);
}

private void setLastLoginDate(Long userId, HomeInfoDto homeInfoDto) {
LocalDate today = LocalDate.now();
Optional<UserAttendance> lastAttendance = userAttendanceRepository
.findTopByUserIdAndAttendanceDateBeforeOrderByAttendanceDateDesc(userId, today);

if (lastAttendance.isPresent()) {
homeInfoDto.setLastLoginDate(lastAttendance.get().getAttendanceDate());
} else {
homeInfoDto.setLastLoginDate(null);
}
}

}