-
Notifications
You must be signed in to change notification settings - Fork 0
[MOISAM-246] 유저의 로그인 로그를 저장하여 일별 로그인 유저 수를 어드민에서 확인한다 #172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b053420
FEAT: (MOISAM-246) 유저 로그인 로그 엔티티, 리포지토리를 설계한다
anxi01 4e05867
FEAT: (MOISAM-246) 로그인 성공/실패 log를 저장한다
anxi01 a614c79
REFACTOR: (MOISAM-246) UserAgent를 Spring Http 상수로 변경한다
anxi01 39ec7d2
REFACTOR: (MOISAM-246) X-Real-IP에서 IP주소를 받아오도록 변경한다
anxi01 9d7835f
FEAT: (MOISAM-246) 로그인 이력 저장 실패 시 로깅을 수행한다
anxi01 d7a0131
FEAT: (MOISAM-246) 사이드바 프래그먼트를 추가한다
anxi01 937e52d
FEAT: (MOISAM-246) 어드민에서 금일 가입자 수, 로그인 유저 수 및 가입 유저 정보를 조회한다
anxi01 576bb21
FEAT: (MOISAM-246) 어드민 User View를 추가한다
anxi01 8615c6b
FEAT: (MOISAM-246) 유저 탈퇴 여부 및 탈퇴 일시를 추가한다
anxi01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Submodule config
updated
from 293195 to 22ca0f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/meetup/server/admin/dto/response/AdminUserResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.meetup.server.admin.dto.response; | ||
|
|
||
| import com.meetup.server.user.domain.User; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record AdminUserResponse( | ||
| Long userId, | ||
| String nickname, | ||
| String email, | ||
| boolean isPersonalInfoAgreement, | ||
| boolean isMarketingAgreement, | ||
| LocalDateTime createdDateTime, | ||
| LocalDateTime deletedDateTime | ||
| ) { | ||
| public static AdminUserResponse from(User user) { | ||
| return new AdminUserResponse( | ||
| user.getUserId(), | ||
| user.getNickname(), | ||
| user.getEmail(), | ||
| user.isPersonalInfoAgreement(), | ||
| user.isMarketingAgreement(), | ||
| user.getCreatedAt(), | ||
| user.getDeletedAt() | ||
| ); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/meetup/server/admin/dto/response/DailyEventStatsResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.meetup.server.admin.dto.response; | ||
|
|
||
| public record DailyEventStatsResponse( | ||
| long dailyEventCount, | ||
| long dailyParticipantCount | ||
| ) { | ||
| public static DailyEventStatsResponse of(long eventCount, long participantCount) { | ||
| return new DailyEventStatsResponse(eventCount, participantCount); | ||
| } | ||
| } |
10 changes: 0 additions & 10 deletions
10
src/main/java/com/meetup/server/admin/dto/response/DailyStatsResponse.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
src/main/java/com/meetup/server/admin/dto/response/DailyUserStatsResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.meetup.server.admin.dto.response; | ||
|
|
||
| public record DailyUserStatsResponse( | ||
| long dailyLoginUserCount, | ||
| long dailyRegisterUserCount | ||
| ) { | ||
| public static DailyUserStatsResponse of(long loginCount, long registerCount) { | ||
| return new DailyUserStatsResponse(loginCount, registerCount); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/meetup/server/user/domain/LogUserLogin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.meetup.server.user.domain; | ||
|
|
||
| import com.meetup.server.global.domain.BaseEntity; | ||
| import com.meetup.server.global.util.StringUtil; | ||
| import com.meetup.server.user.domain.type.LoginStatus; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "log_user_login") | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Getter | ||
| public class LogUserLogin extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "log_user_login_id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "user_id") | ||
| private Long userId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "login_status", nullable = false) | ||
| private LoginStatus loginStatus; | ||
|
|
||
| @Column(name = "ip_address", length = 45) | ||
| private String ipAddress; | ||
|
|
||
| @Column(name = "user_agent") | ||
| private String userAgent; | ||
|
|
||
| @Column(name = "fail_reason") | ||
| private String failReason; | ||
|
|
||
| @Builder | ||
| public LogUserLogin(Long userId, LoginStatus loginStatus, String ipAddress, String userAgent, String failReason) { | ||
| this.userId = userId; | ||
| this.loginStatus = loginStatus; | ||
| this.ipAddress = ipAddress; | ||
| this.userAgent = StringUtil.truncate(userAgent, 255); | ||
| this.failReason = StringUtil.truncate(failReason, 255); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/meetup/server/user/domain/type/LoginStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.meetup.server.user.domain.type; | ||
|
|
||
| public enum LoginStatus { | ||
| SUCCESS, | ||
| FAILURE, | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/meetup/server/user/implement/LogUserLoginReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.meetup.server.user.implement; | ||
|
|
||
| import com.meetup.server.user.infrastructure.jpa.LogUserLoginRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class LogUserLoginReader { | ||
|
|
||
| private final LogUserLoginRepository logUserLoginRepository; | ||
|
|
||
| public long readDailyLoginUserCount(LocalDate todayDate) { | ||
| LocalDateTime startDateTime = todayDate.atStartOfDay(); | ||
| LocalDateTime endDateTime = todayDate.atTime(LocalTime.MAX); | ||
| return logUserLoginRepository.countUniqueLoginUsers(startDateTime, endDateTime); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/meetup/server/user/implement/LogUserLoginWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.meetup.server.user.implement; | ||
|
|
||
| import com.meetup.server.user.domain.LogUserLogin; | ||
| import com.meetup.server.user.domain.type.LoginStatus; | ||
| import com.meetup.server.user.infrastructure.jpa.LogUserLoginRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class LogUserLoginWriter { | ||
|
|
||
| private final LogUserLoginRepository logUserLoginRepository; | ||
|
|
||
| @Async | ||
| public CompletableFuture<Void> save(Long userId, LoginStatus loginStatus, String ipAddress, String userAgent, String failReason) { | ||
| try { | ||
| logUserLoginRepository.save( | ||
| LogUserLogin.builder() | ||
| .userId(userId) | ||
| .loginStatus(loginStatus) | ||
| .ipAddress(ipAddress) | ||
| .userAgent(userAgent) | ||
| .failReason(failReason) | ||
| .build() | ||
| ); | ||
| } catch (Exception e) { | ||
| log.error("[LogUserLoginWriter]: 유저 로그인 로그 저장에 실패했습니다. userId: {}", userId, e); | ||
| } | ||
| return CompletableFuture.completedFuture(null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.