@@ -36,7 +36,7 @@ public class AdminUserBanService {
3636
3737 @ Transactional
3838 public void banUser (long userId , UserBanRequest request ) {
39- ZonedDateTime now = ZonedDateTime .now (UTC ); //TODO UTC 확인
39+ ZonedDateTime now = ZonedDateTime .now (UTC );
4040 validateNotAlreadyBanned (userId , now );
4141 validateReportExists (userId );
4242
@@ -45,27 +45,6 @@ public void banUser(long userId, UserBanRequest request) {
4545 updateUserStatus (userId , UserStatus .BANNED );
4646 }
4747
48- @ Transactional
49- public void unbanUser (long userId , long adminId ) {
50- UserBan userBan = findBannedUser (userId , ZonedDateTime .now (UTC ));
51- userBan .manuallyUnban (adminId );
52- processUnban (userId );
53- }
54-
55- @ Transactional
56- @ Scheduled (cron = "0 0 0 * * *" )
57- public void expireUserBans () {
58- List <UserBan > expiredBans = userBanRepository .findAllByIsUnbannedFalseAndExpiredAtBefore (ZonedDateTime .now (UTC ));
59- for (UserBan userBan : expiredBans ) {
60- processUnban (userBan .getBannedUserId ());
61- }
62- }
63-
64- public void processUnban (long userId ) {
65- updateReportedContentIsDeleted (userId , false );
66- updateUserStatus (userId , UserStatus .REPORTED );
67- }
68-
6948 private void validateNotAlreadyBanned (long userId , ZonedDateTime now ) {
7049 if (userBanRepository .existsByBannedUserIdAndIsUnbannedFalseAndExpiredAtAfter (userId , now )) {
7150 throw new CustomException (ErrorCode .ALREADY_BANNED_USER );
@@ -89,15 +68,36 @@ private void createUserBan(long userId, UserBanRequest request, ZonedDateTime no
8968 userBanRepository .save (userBan );
9069 }
9170
71+ private void updateUserStatus (long userId , UserStatus status ) {
72+ SiteUser user = siteUserRepository .findById (userId )
73+ .orElseThrow (() -> new CustomException (ErrorCode .USER_NOT_FOUND ));
74+ user .updateUserStatus (status );
75+ }
76+
77+ @ Transactional
78+ public void unbanUser (long userId , long adminId ) {
79+ UserBan userBan = findBannedUser (userId , ZonedDateTime .now (UTC ));
80+ userBan .manuallyUnban (adminId );
81+ processUnban (userId );
82+ }
83+
9284 private UserBan findBannedUser (long userId , ZonedDateTime now ) {
9385 return userBanRepository
9486 .findTopByBannedUserIdAndIsUnbannedFalseAndExpiredAtAfterOrderByCreatedAtDesc (userId , now )
9587 .orElseThrow (() -> new CustomException (ErrorCode .NOT_BANNED_USER ));
9688 }
9789
98- private void updateUserStatus (long userId , UserStatus status ) {
99- SiteUser user = siteUserRepository .findById (userId )
100- .orElseThrow (() -> new CustomException (ErrorCode .USER_NOT_FOUND ));
101- user .updateUserStatus (status );
90+ @ Transactional
91+ @ Scheduled (cron = "0 0 0 * * *" )
92+ public void expireUserBans () {
93+ List <UserBan > expiredBans = userBanRepository .findAllByIsUnbannedFalseAndExpiredAtBefore (ZonedDateTime .now (UTC ));
94+ for (UserBan userBan : expiredBans ) {
95+ processUnban (userBan .getBannedUserId ());
96+ }
97+ }
98+
99+ private void processUnban (long userId ) {
100+ updateReportedContentIsDeleted (userId , false );
101+ updateUserStatus (userId , UserStatus .REPORTED );
102102 }
103103}
0 commit comments