-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 유저 로그인, 활동 시간 추적 #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package gg.agit.konect.domain.user.service; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import gg.agit.konect.domain.user.repository.UserRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class UserActivityService { | ||
|
|
||
| private final UserRepository userRepository; | ||
|
|
||
| @Transactional | ||
| public void updateLastLoginAt(Integer userId) { | ||
| if (userId == null) { | ||
| return; | ||
| } | ||
|
|
||
| userRepository.getById(userId).updateLastLoginAt(LocalDateTime.now()); | ||
| } | ||
|
Comment on lines
+19
to
+25
|
||
|
|
||
| @Transactional | ||
| public void updateLastActivityAt(Integer userId) { | ||
| if (userId == null) { | ||
| return; | ||
| } | ||
|
|
||
| userRepository.getById(userId).updateLastActivityAt(LocalDateTime.now()); | ||
| } | ||
|
Comment on lines
+30
to
+34
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||
| package gg.agit.konect.global.auth.aop; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import org.aspectj.lang.annotation.After; | ||||||||||||||||||||||||||
| import org.aspectj.lang.annotation.Aspect; | ||||||||||||||||||||||||||
| import org.springframework.stereotype.Component; | ||||||||||||||||||||||||||
| import org.springframework.web.context.request.RequestContextHolder; | ||||||||||||||||||||||||||
| import org.springframework.web.context.request.ServletRequestAttributes; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import gg.agit.konect.domain.user.service.UserActivityService; | ||||||||||||||||||||||||||
| import gg.agit.konect.global.auth.web.LoginCheckInterceptor; | ||||||||||||||||||||||||||
| import jakarta.servlet.http.HttpServletRequest; | ||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Aspect | ||||||||||||||||||||||||||
| @Component | ||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||
| public class UserActivityUpdateAspect { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private final UserActivityService userActivityService; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @After("execution(* gg.agit.konect..controller..*(..))") | ||||||||||||||||||||||||||
| public void updateLastActivity() { | ||||||||||||||||||||||||||
|
Comment on lines
+21
to
+22
|
||||||||||||||||||||||||||
| ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); | ||||||||||||||||||||||||||
| if (attributes == null) { | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| HttpServletRequest request = attributes.getRequest(); | ||||||||||||||||||||||||||
|
Comment on lines
+23
to
+28
|
||||||||||||||||||||||||||
| ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); | |
| if (attributes == null) { | |
| return; | |
| } | |
| HttpServletRequest request = attributes.getRequest(); | |
| Object attributes = RequestContextHolder.getRequestAttributes(); | |
| if (attributes == null || !(attributes instanceof ServletRequestAttributes)) { | |
| return; | |
| } | |
| HttpServletRequest request = ((ServletRequestAttributes) attributes).getRequest(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ALTER TABLE users | ||
| ADD COLUMN last_login_at DATETIME NULL, | ||
| ADD COLUMN last_activity_at DATETIME NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flyway 마이그레이션에서는 last_login_at/last_activity_at 컬럼 타입이 DATETIME인데, 엔티티는 columnDefinition="TIMESTAMP"로 선언되어 있어 spring.jpa.hibernate.ddl-auto=validate 환경에서 스키마 검증 실패가 발생할 수 있습니다. DB 타입과 엔티티 매핑을 동일하게 맞춰 주세요(마이그레이션을 TIMESTAMP로 바꾸거나, 엔티티의 columnDefinition을 DATETIME/기본 매핑으로 변경).