From bb4b9c1308073f2178aeae8564d147e5294cae20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 23 Nov 2024 15:13:37 +0900 Subject: [PATCH 01/15] =?UTF-8?q?fix:=20=EB=B0=98=ED=99=98=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koin/admin/history/dto/AdminHistoryResponse.java | 4 ++-- .../koin/admin/history/dto/AdminHistorysResponse.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java index 406ce536a..ef7e6ee0c 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java @@ -40,8 +40,8 @@ public record AdminHistoryResponse( ) String requestMessage, - @Schema(description = "요청 시간", example = "2019-08-16-23-01-52", requiredMode = REQUIRED) - @JsonFormat(pattern = "yyyy-MM-dd-HH-mm-ss") + @Schema(description = "요청 시간", example = "2019-08-16 23:01:52", requiredMode = REQUIRED) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdAt ) { public static AdminHistoryResponse from(AdminActivityHistory adminActivityHistory) { diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java index 26891b308..7c0e3b325 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java @@ -61,8 +61,8 @@ public record InnerAdminHistorysResponse( ) String requestMessage, - @Schema(description = "요청 시간", example = "2019-08-16-23-01-52", requiredMode = REQUIRED) - @JsonFormat(pattern = "yyyy-MM-dd-HH-mm-ss") + @Schema(description = "요청 시간", example = "2019-08-16 23:01:52", requiredMode = REQUIRED) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdAt ) { public static InnerAdminHistorysResponse from(AdminActivityHistory adminActivityHistory) { From e341850f97ce9b636324e786e891593e9212dcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 23 Nov 2024 15:49:45 +0900 Subject: [PATCH 02/15] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/history/controller/HistoryApi.java | 2 ++ .../history/controller/HistoryController.java | 4 +++- .../history/dto/AdminHistorysCondition.java | 23 +++++++++++++++---- .../admin/history/service/HistoryService.java | 13 +++++++---- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java index 70bdba8fd..fdff5152e 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java @@ -1,6 +1,7 @@ package in.koreatech.koin.admin.history.controller; import static in.koreatech.koin.domain.user.model.UserType.ADMIN; +import static in.koreatech.koin.global.model.Criteria.Sort; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -36,6 +37,7 @@ ResponseEntity getHistorys( @RequestParam(required = false) String requestMethod, @RequestParam(required = false) String domainName, @RequestParam(required = false) Integer domainId, + @RequestParam(required = false) Sort sort, @Auth(permit = {ADMIN}) Integer adminId ); diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java index efc11bbbf..7671e88ac 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java @@ -1,6 +1,7 @@ package in.koreatech.koin.admin.history.controller; import static in.koreatech.koin.domain.user.model.UserType.ADMIN; +import static in.koreatech.koin.global.model.Criteria.Sort; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -28,10 +29,11 @@ public ResponseEntity getHistorys( @RequestParam(required = false) String requestMethod, @RequestParam(required = false) String domainName, @RequestParam(required = false) Integer domainId, + @RequestParam(required = false) Sort sort, @Auth(permit = {ADMIN}) Integer adminId ) { AdminHistorysCondition adminHistorysCondition = new AdminHistorysCondition(page, limit, requestMethod, - domainName, domainId); + domainName, domainId, sort); AdminHistorysResponse historys = historyService.getHistorys(adminHistorysCondition); return ResponseEntity.ok(historys); } diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java index e738e5b10..13ef938b6 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java @@ -1,13 +1,15 @@ package in.koreatech.koin.admin.history.dto; import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; +import static in.koreatech.koin.global.model.Criteria.*; +import static in.koreatech.koin.global.model.Criteria.Sort.CREATED_AT_DESC; import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; +import static org.springframework.data.domain.Sort.Direction; import java.util.Objects; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import in.koreatech.koin.global.model.Criteria; import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(value = SnakeCaseStrategy.class) @@ -25,14 +27,27 @@ public record AdminHistorysCondition( String domainName, @Schema(description = "특정 엔티티 id", requiredMode = NOT_REQUIRED) - Integer domainId + Integer domainId, + + @Schema(description = "정렬 기준", requiredMode = NOT_REQUIRED) + Sort sort ) { public AdminHistorysCondition { if (Objects.isNull(page)) { - page = Criteria.DEFAULT_PAGE; + page = DEFAULT_PAGE; } if (Objects.isNull(limit)) { - limit = Criteria.DEFAULT_LIMIT; + limit = DEFAULT_LIMIT; + } + if (Objects.isNull(sort)) { + sort = CREATED_AT_DESC; + } + } + + public Direction getSortDir() { + if (sort == Sort.CREATED_AT_ASC) { + return Direction.ASC; } + return Direction.DESC; } } diff --git a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java index 84706bab5..260746580 100644 --- a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java +++ b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; @@ -22,12 +23,14 @@ public AdminHistorysResponse getHistorys(AdminHistorysCondition condition) { Integer total = adminActivityHistoryRepository.countAdminActivityHistory(); Criteria criteria = Criteria.of(condition.page(), condition.limit(), total); - PageRequest pageRequest = PageRequest.of(criteria.getPage(), criteria.getLimit()); - Page adminActivityHistoryRepositoryPage = adminActivityHistoryRepository.findByConditions( - condition, - pageRequest); + PageRequest pageRequest = PageRequest.of( + criteria.getPage(), criteria.getLimit(), + Sort.by(condition.getSortDir(), "createdAt") + ); + Page adminActivityHistoryPage = adminActivityHistoryRepository.findByConditions( + condition, pageRequest); - return AdminHistorysResponse.of(adminActivityHistoryRepositoryPage); + return AdminHistorysResponse.of(adminActivityHistoryPage); } public AdminHistoryResponse getHistory(Integer id) { From 5d869bf68243117faaf861d4313f7eb1c3afb40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 23 Nov 2024 19:47:20 +0900 Subject: [PATCH 03/15] =?UTF-8?q?fix:=20String=20=ED=95=84=EB=93=9C=20Enum?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aop/AdminActivityHistoryAspect.java | 5 +++-- .../admin/history/controller/HistoryApi.java | 6 ++++-- .../history/controller/HistoryController.java | 6 ++++-- .../history/dto/AdminHistoryResponse.java | 4 ++-- .../history/dto/AdminHistorysCondition.java | 6 ++++-- .../history/dto/AdminHistorysResponse.java | 4 ++-- .../history/model/AdminActivityHistory.java | 19 +++++++++++++------ .../AdminActivityHistoryRepository.java | 4 ++-- 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java index 75e4f9289..a1abd3661 100644 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java @@ -12,6 +12,7 @@ import org.springframework.web.util.ContentCachingRequestWrapper; import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.model.AdminActivityHistory; import in.koreatech.koin.admin.history.repository.AdminActivityHistoryRepository; import in.koreatech.koin.admin.user.model.Admin; @@ -57,7 +58,7 @@ private void excludeSpecificMethods() { public Object logAdminActivity(ProceedingJoinPoint joinPoint) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); String requestURI = request.getRequestURI(); - String requestMethod = request.getMethod(); + HttpMethodType requestMethod = HttpMethodType.valueOf(request.getMethod()); ContentCachingRequestWrapper cachingRequest = (ContentCachingRequestWrapper)request; String requestMessage = new String(cachingRequest.getContentAsByteArray()); @@ -71,7 +72,7 @@ public Object logAdminActivity(ProceedingJoinPoint joinPoint) throws Throwable { .domainId(domainInfo.domainId()) .admin(admin) .requestMethod(requestMethod) - .domainName(domainInfo.domainName()) + .domainName(DomainType.valueOf(domainInfo.domainName())) .requestMessage(requestMessage) .build()); diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java index fdff5152e..a6b667b1a 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java @@ -10,6 +10,8 @@ import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; import in.koreatech.koin.admin.history.dto.AdminHistorysResponse; +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.global.auth.Auth; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -34,8 +36,8 @@ public interface HistoryApi { ResponseEntity getHistorys( @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, - @RequestParam(required = false) String requestMethod, - @RequestParam(required = false) String domainName, + @RequestParam(required = false) HttpMethodType requestMethod, + @RequestParam(required = false) DomainType domainName, @RequestParam(required = false) Integer domainId, @RequestParam(required = false) Sort sort, @Auth(permit = {ADMIN}) Integer adminId diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java index 7671e88ac..aa591c117 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java @@ -12,6 +12,8 @@ import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; import in.koreatech.koin.admin.history.dto.AdminHistorysCondition; import in.koreatech.koin.admin.history.dto.AdminHistorysResponse; +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.service.HistoryService; import in.koreatech.koin.global.auth.Auth; import lombok.RequiredArgsConstructor; @@ -26,8 +28,8 @@ public class HistoryController implements HistoryApi { public ResponseEntity getHistorys( @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, - @RequestParam(required = false) String requestMethod, - @RequestParam(required = false) String domainName, + @RequestParam(required = false) HttpMethodType requestMethod, + @RequestParam(required = false) DomainType domainName, @RequestParam(required = false) Integer domainId, @RequestParam(required = false) Sort sort, @Auth(permit = {ADMIN}) Integer adminId diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java index ef7e6ee0c..035fa6e59 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoryResponse.java @@ -49,8 +49,8 @@ public static AdminHistoryResponse from(AdminActivityHistory adminActivityHistor adminActivityHistory.getId(), adminActivityHistory.getDomainId(), adminActivityHistory.getAdmin().getUser().getName(), - DomainType.valueOf(adminActivityHistory.getDomainName()).getDescription(), - HttpMethodType.valueOf(adminActivityHistory.getRequestMethod()).getValue(), + adminActivityHistory.getDomainName().getDescription(), + adminActivityHistory.getRequestMethod().getValue(), adminActivityHistory.getRequestMessage(), adminActivityHistory.getCreatedAt() ); diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java index 13ef938b6..d70ace485 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(value = SnakeCaseStrategy.class) @@ -21,10 +23,10 @@ public record AdminHistorysCondition( Integer limit, @Schema(description = "HTTP 메소드", example = "POST", requiredMode = NOT_REQUIRED) - String requestMethod, + HttpMethodType requestMethod, @Schema(description = "도메인 이름", example = "NOTICE", requiredMode = NOT_REQUIRED) - String domainName, + DomainType domainName, @Schema(description = "특정 엔티티 id", requiredMode = NOT_REQUIRED) Integer domainId, diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java index 7c0e3b325..50c82fbac 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java @@ -70,8 +70,8 @@ public static InnerAdminHistorysResponse from(AdminActivityHistory adminActivity adminActivityHistory.getId(), adminActivityHistory.getDomainId(), adminActivityHistory.getAdmin().getUser().getName(), - DomainType.valueOf(adminActivityHistory.getDomainName()).getDescription(), - HttpMethodType.valueOf(adminActivityHistory.getRequestMethod()).getValue(), + adminActivityHistory.getDomainName().getDescription(), + adminActivityHistory.getRequestMethod().getValue(), adminActivityHistory.getRequestMessage(), adminActivityHistory.getCreatedAt() ); diff --git a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java index 3ab600a04..cef0a3c4c 100644 --- a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java +++ b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java @@ -3,10 +3,14 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.user.model.Admin; import in.koreatech.koin.global.domain.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -32,14 +36,14 @@ public class AdminActivityHistory extends BaseEntity { private Integer domainId; @NotNull - @Size(max = 10) + @Enumerated(value = EnumType.STRING) @Column(name = "request_method", nullable = false, length = 10) - private String requestMethod; + private HttpMethodType requestMethod; @NotNull - @Size(max = 20) + @Enumerated(value = EnumType.STRING) @Column(name = "domain_name", nullable = false, length = 20) - private String domainName; + private DomainType domainName; @Column(name = "request_message", columnDefinition = "TEXT") private String requestMessage; @@ -49,8 +53,11 @@ public class AdminActivityHistory extends BaseEntity { private Admin admin; @Builder - public AdminActivityHistory(Integer domainId, String requestMethod, String domainName, String requestMessage, - Admin admin) { + + public AdminActivityHistory( + Integer domainId, HttpMethodType requestMethod, + DomainType domainName, String requestMessage, Admin admin + ) { this.domainId = domainId; this.requestMethod = requestMethod; this.domainName = domainName; diff --git a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java index eb0a9721f..a1c60b32f 100644 --- a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java +++ b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java @@ -27,8 +27,8 @@ default AdminActivityHistory getById(Integer id) { @Query(""" SELECT a FROM AdminActivityHistory a WHERE - (:#{#condition.requestMethod} IS NULL OR a.requestMethod = :#{#condition.requestMethod}) AND - (:#{#condition.domainName} IS NULL OR a.domainName = :#{#condition.domainName}) AND + (:#{#condition.requestMethod?.name()} IS NULL OR a.requestMethod = :#{#condition.requestMethod}) AND + (:#{#condition.domainName?.name()} IS NULL OR a.domainName = :#{#condition.domainName}) AND (:#{#condition.domainId} IS NULL OR a.domainId = :#{#condition.domainId}) """) Page findByConditions(@Param("condition") AdminHistorysCondition adminsCondition, From 416bffe3f29fc41d1dbb54a98878660048f7809f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 23 Nov 2024 20:03:12 +0900 Subject: [PATCH 04/15] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koreatech/koin/admin/history/model/AdminActivityHistory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java index cef0a3c4c..f8c0e1862 100644 --- a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java +++ b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java @@ -53,7 +53,6 @@ public class AdminActivityHistory extends BaseEntity { private Admin admin; @Builder - public AdminActivityHistory( Integer domainId, HttpMethodType requestMethod, DomainType domainName, String requestMessage, Admin admin From 53090e8e2d4c29b575aeb3c18ef409ca039df994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 23 Nov 2024 20:07:29 +0900 Subject: [PATCH 05/15] =?UTF-8?q?chore:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20im?= =?UTF-8?q?port=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koreatech/koin/admin/history/model/AdminActivityHistory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java index f8c0e1862..d95b6d8b4 100644 --- a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java +++ b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java @@ -17,7 +17,6 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; From c1563ec78aca34503b7d51c77a57bc96d41aff38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Tue, 26 Nov 2024 16:14:54 +0900 Subject: [PATCH 06/15] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koin/admin/history/aop/AdminActivityHistoryAspect.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java index a1abd3661..39fd7d7cc 100644 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java @@ -74,7 +74,8 @@ public Object logAdminActivity(ProceedingJoinPoint joinPoint) throws Throwable { .requestMethod(requestMethod) .domainName(DomainType.valueOf(domainInfo.domainName())) .requestMessage(requestMessage) - .build()); + .build() + ); return result; } From e138734abf604aee6e69ddf895d09a9e8d69b319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 30 Nov 2024 23:23:04 +0900 Subject: [PATCH 07/15] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EB=B8=94?= =?UTF-8?q?=EB=9F=AD=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../history/aop/AdminActivityHistoryAspect.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java index 39fd7d7cc..d94d750c5 100644 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java @@ -45,12 +45,14 @@ private void allAdminControllers() { private void excludeGetMapping() { } - @Pointcut("!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminLogin(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.logout(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && " - + "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..))") + @Pointcut(""" + !execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminLogin(..)) && + !execution(* in.koreatech.koin.admin.user.controller.AdminUserController.logout(..)) && + !execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && + !execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && + !execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && + !execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..)) + """) private void excludeSpecificMethods() { } From 6b2693d6fc1698aebcab69b03aea4ea198cc8b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 30 Nov 2024 23:26:48 +0900 Subject: [PATCH 08/15] =?UTF-8?q?chore:=20historys=20->=20histories?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/history/controller/HistoryApi.java | 6 +++--- .../history/controller/HistoryController.java | 14 +++++++------- ...ition.java => AdminHistoriesCondition.java} | 4 ++-- ...sponse.java => AdminHistoriesResponse.java} | 18 ++++++++---------- .../AdminActivityHistoryRepository.java | 4 ++-- .../admin/history/service/HistoryService.java | 8 ++++---- 6 files changed, 26 insertions(+), 28 deletions(-) rename src/main/java/in/koreatech/koin/admin/history/dto/{AdminHistorysCondition.java => AdminHistoriesCondition.java} (96%) rename src/main/java/in/koreatech/koin/admin/history/dto/{AdminHistorysResponse.java => AdminHistoriesResponse.java} (84%) diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java index a6b667b1a..86c11b428 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam; import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; -import in.koreatech.koin.admin.history.dto.AdminHistorysResponse; +import in.koreatech.koin.admin.history.dto.AdminHistoriesResponse; import in.koreatech.koin.admin.history.enums.DomainType; import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.global.auth.Auth; @@ -32,8 +32,8 @@ public interface HistoryApi { } ) @Operation(summary = "히스토리 리스트 조회") - @GetMapping("/admin/historys") - ResponseEntity getHistorys( + @GetMapping("/admin/histories") + ResponseEntity getHistories( @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, @RequestParam(required = false) HttpMethodType requestMethod, diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java index aa591c117..01aaa834f 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryController.java @@ -10,8 +10,8 @@ import org.springframework.web.bind.annotation.RestController; import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; -import in.koreatech.koin.admin.history.dto.AdminHistorysCondition; -import in.koreatech.koin.admin.history.dto.AdminHistorysResponse; +import in.koreatech.koin.admin.history.dto.AdminHistoriesCondition; +import in.koreatech.koin.admin.history.dto.AdminHistoriesResponse; import in.koreatech.koin.admin.history.enums.DomainType; import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.service.HistoryService; @@ -24,8 +24,8 @@ public class HistoryController implements HistoryApi { private final HistoryService historyService; - @GetMapping("/admin/historys") - public ResponseEntity getHistorys( + @GetMapping("/admin/histories") + public ResponseEntity getHistories( @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, @RequestParam(required = false) HttpMethodType requestMethod, @@ -34,10 +34,10 @@ public ResponseEntity getHistorys( @RequestParam(required = false) Sort sort, @Auth(permit = {ADMIN}) Integer adminId ) { - AdminHistorysCondition adminHistorysCondition = new AdminHistorysCondition(page, limit, requestMethod, + AdminHistoriesCondition adminHistoriesCondition = new AdminHistoriesCondition(page, limit, requestMethod, domainName, domainId, sort); - AdminHistorysResponse historys = historyService.getHistorys(adminHistorysCondition); - return ResponseEntity.ok(historys); + AdminHistoriesResponse histories = historyService.getHistories(adminHistoriesCondition); + return ResponseEntity.ok(histories); } @GetMapping("/admin/history/{id}") diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java similarity index 96% rename from src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java rename to src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java index d70ace485..2932b1777 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysCondition.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java @@ -15,7 +15,7 @@ import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(value = SnakeCaseStrategy.class) -public record AdminHistorysCondition( +public record AdminHistoriesCondition( @Schema(description = "페이지", example = "1", defaultValue = "1", requiredMode = NOT_REQUIRED) Integer page, @@ -34,7 +34,7 @@ public record AdminHistorysCondition( @Schema(description = "정렬 기준", requiredMode = NOT_REQUIRED) Sort sort ) { - public AdminHistorysCondition { + public AdminHistoriesCondition { if (Objects.isNull(page)) { page = DEFAULT_PAGE; } diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java similarity index 84% rename from src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java rename to src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java index 50c82fbac..e17308df2 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistorysResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java @@ -12,13 +12,11 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import in.koreatech.koin.admin.history.enums.DomainType; -import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.model.AdminActivityHistory; import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(value = SnakeCaseStrategy.class) -public record AdminHistorysResponse( +public record AdminHistoriesResponse( @Schema(description = "조건에 해당하는 히스토리 수", example = "10", requiredMode = REQUIRED) Long totalCount, @@ -32,10 +30,10 @@ public record AdminHistorysResponse( Integer currentPage, @Schema(description = "어드민 계정 리스트", requiredMode = REQUIRED) - List historys + List histories ) { @JsonNaming(value = SnakeCaseStrategy.class) - public record InnerAdminHistorysResponse( + public record InnerAdminHistoriesResponse( @Schema(description = "고유 id", example = "1", requiredMode = REQUIRED) Integer id, @@ -65,8 +63,8 @@ public record InnerAdminHistorysResponse( @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdAt ) { - public static InnerAdminHistorysResponse from(AdminActivityHistory adminActivityHistory) { - return new InnerAdminHistorysResponse( + public static InnerAdminHistoriesResponse from(AdminActivityHistory adminActivityHistory) { + return new InnerAdminHistoriesResponse( adminActivityHistory.getId(), adminActivityHistory.getDomainId(), adminActivityHistory.getAdmin().getUser().getName(), @@ -78,14 +76,14 @@ public static InnerAdminHistorysResponse from(AdminActivityHistory adminActivity } } - public static AdminHistorysResponse of(Page adminActivityHistoryPage) { - return new AdminHistorysResponse( + public static AdminHistoriesResponse of(Page adminActivityHistoryPage) { + return new AdminHistoriesResponse( adminActivityHistoryPage.getTotalElements(), adminActivityHistoryPage.getContent().size(), adminActivityHistoryPage.getTotalPages(), adminActivityHistoryPage.getNumber() + 1, adminActivityHistoryPage.getContent().stream() - .map(InnerAdminHistorysResponse::from) + .map(InnerAdminHistoriesResponse::from) .collect(Collectors.toList()) ); } diff --git a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java index a1c60b32f..b25e75940 100644 --- a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java +++ b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java @@ -8,7 +8,7 @@ import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; -import in.koreatech.koin.admin.history.dto.AdminHistorysCondition; +import in.koreatech.koin.admin.history.dto.AdminHistoriesCondition; import in.koreatech.koin.admin.history.exception.AdminActivityHistoryNotFoundException; import in.koreatech.koin.admin.history.model.AdminActivityHistory; @@ -31,6 +31,6 @@ default AdminActivityHistory getById(Integer id) { (:#{#condition.domainName?.name()} IS NULL OR a.domainName = :#{#condition.domainName}) AND (:#{#condition.domainId} IS NULL OR a.domainId = :#{#condition.domainId}) """) - Page findByConditions(@Param("condition") AdminHistorysCondition adminsCondition, + Page findByConditions(@Param("condition") AdminHistoriesCondition adminsCondition, Pageable pageable); } diff --git a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java index 260746580..4251f0b0c 100644 --- a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java +++ b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java @@ -6,8 +6,8 @@ import org.springframework.stereotype.Service; import in.koreatech.koin.admin.history.dto.AdminHistoryResponse; -import in.koreatech.koin.admin.history.dto.AdminHistorysCondition; -import in.koreatech.koin.admin.history.dto.AdminHistorysResponse; +import in.koreatech.koin.admin.history.dto.AdminHistoriesCondition; +import in.koreatech.koin.admin.history.dto.AdminHistoriesResponse; import in.koreatech.koin.admin.history.model.AdminActivityHistory; import in.koreatech.koin.admin.history.repository.AdminActivityHistoryRepository; import in.koreatech.koin.global.model.Criteria; @@ -19,7 +19,7 @@ public class HistoryService { private final AdminActivityHistoryRepository adminActivityHistoryRepository; - public AdminHistorysResponse getHistorys(AdminHistorysCondition condition) { + public AdminHistoriesResponse getHistories(AdminHistoriesCondition condition) { Integer total = adminActivityHistoryRepository.countAdminActivityHistory(); Criteria criteria = Criteria.of(condition.page(), condition.limit(), total); @@ -30,7 +30,7 @@ public AdminHistorysResponse getHistorys(AdminHistorysCondition condition) { Page adminActivityHistoryPage = adminActivityHistoryRepository.findByConditions( condition, pageRequest); - return AdminHistorysResponse.of(adminActivityHistoryPage); + return AdminHistoriesResponse.of(adminActivityHistoryPage); } public AdminHistoryResponse getHistory(Integer id) { From d8cf3855e02fb00e98cd1354b9bf0413ed98f027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 30 Nov 2024 23:31:47 +0900 Subject: [PATCH 09/15] =?UTF-8?q?chore:=20=EC=A0=95=EC=A0=81=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koin/admin/history/dto/AdminHistoriesResponse.java | 2 +- .../in/koreatech/koin/admin/history/service/HistoryService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java index e17308df2..61e1a8722 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesResponse.java @@ -76,7 +76,7 @@ public static InnerAdminHistoriesResponse from(AdminActivityHistory adminActivit } } - public static AdminHistoriesResponse of(Page adminActivityHistoryPage) { + public static AdminHistoriesResponse from(Page adminActivityHistoryPage) { return new AdminHistoriesResponse( adminActivityHistoryPage.getTotalElements(), adminActivityHistoryPage.getContent().size(), diff --git a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java index 4251f0b0c..124973a64 100644 --- a/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java +++ b/src/main/java/in/koreatech/koin/admin/history/service/HistoryService.java @@ -30,7 +30,7 @@ public AdminHistoriesResponse getHistories(AdminHistoriesCondition condition) { Page adminActivityHistoryPage = adminActivityHistoryRepository.findByConditions( condition, pageRequest); - return AdminHistoriesResponse.of(adminActivityHistoryPage); + return AdminHistoriesResponse.from(adminActivityHistoryPage); } public AdminHistoryResponse getHistory(Integer id) { From cdddd1426334fb12fd7d10e7491232ffc046b4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sat, 30 Nov 2024 23:58:30 +0900 Subject: [PATCH 10/15] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koin/admin/history/model/AdminActivityHistory.java | 7 +++++-- .../history/repository/AdminActivityHistoryRepository.java | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java index d95b6d8b4..afb88e2b4 100644 --- a/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java +++ b/src/main/java/in/koreatech/koin/admin/history/model/AdminActivityHistory.java @@ -53,8 +53,11 @@ public class AdminActivityHistory extends BaseEntity { @Builder public AdminActivityHistory( - Integer domainId, HttpMethodType requestMethod, - DomainType domainName, String requestMessage, Admin admin + Integer domainId, + HttpMethodType requestMethod, + DomainType domainName, + String requestMessage, + Admin admin ) { this.domainId = domainId; this.requestMethod = requestMethod; diff --git a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java index b25e75940..01c6cf937 100644 --- a/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java +++ b/src/main/java/in/koreatech/koin/admin/history/repository/AdminActivityHistoryRepository.java @@ -13,6 +13,7 @@ import in.koreatech.koin.admin.history.model.AdminActivityHistory; public interface AdminActivityHistoryRepository extends Repository { + AdminActivityHistory save(AdminActivityHistory adminActivityHistory); Optional findById(Integer id); From 0f756c20b8612df656bcaa8e19e3f1cc340e7a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Sun, 1 Dec 2024 00:07:43 +0900 Subject: [PATCH 11/15] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EA=B0=9C?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/koreatech/koin/admin/history/controller/HistoryApi.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java index 86c11b428..fe0edc9b1 100644 --- a/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java +++ b/src/main/java/in/koreatech/koin/admin/history/controller/HistoryApi.java @@ -22,6 +22,7 @@ @Tag(name = "(Admin) History: 기록", description = "관리자 기록 관련 API") public interface HistoryApi { + @ApiResponses( value = { @ApiResponse(responseCode = "200"), From 7c1ecb22d5fe15b506432089e6019df14ad0ed3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Fri, 6 Dec 2024 11:31:33 +0900 Subject: [PATCH 12/15] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B9=85=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aop/AdminActivityHistoryAspect.java | 113 ++++-------------- .../koin/admin/history/aop/AdminLogging.java | 20 ++++ 2 files changed, 44 insertions(+), 89 deletions(-) create mode 100644 src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java index 720ae012c..3f385ffa2 100644 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java @@ -1,21 +1,20 @@ package in.koreatech.koin.admin.history.aop; -import org.apache.commons.lang3.EnumUtils; +import java.lang.reflect.Method; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.util.ContentCachingRequestWrapper; -import in.koreatech.koin.admin.history.enums.DomainType; import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.model.AdminActivityHistory; import in.koreatech.koin.admin.history.repository.AdminActivityHistoryRepository; -import in.koreatech.koin.admin.user.model.Admin; import in.koreatech.koin.admin.user.repository.AdminRepository; import in.koreatech.koin.global.auth.AuthContext; import jakarta.servlet.http.HttpServletRequest; @@ -26,114 +25,50 @@ @Profile("!test") @RequiredArgsConstructor public class AdminActivityHistoryAspect { + + private static final String SEPARATOR = "/"; private static final String REGEX_NUMERIC = "^[0-9]*$"; - private static final String SEGMENT_SHOPS = "SHOPS"; - private static final String SEGMENT_BENEFIT = "benefit"; - private static final String SEGMENT_CATEGORIES = "CATEGORIES"; - private static final String SEGMENT_CLOSE = "close"; - private static final String SEGMENT_ABTEST = "abtest"; private final AuthContext authContext; private final AdminRepository adminRepository; private final AdminActivityHistoryRepository adminActivityHistoryRepository; - @Pointcut("execution(* in.koreatech.koin.admin..controller.*.*(..))") - private void allAdminControllers() { - } - - @Pointcut("!@annotation(org.springframework.web.bind.annotation.GetMapping)") - private void excludeGetMapping() { - } - - @Pointcut("!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminLogin(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.logout(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && " - + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && " - + "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..)) &&" - + "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.issueAccessHistoryId(..))") - private void excludeSpecificMethods() { - } - - @Around("allAdminControllers() && excludeGetMapping() && excludeSpecificMethods()") + @Around("@annotation(AdminLogging) && (args(..))") public Object logAdminActivity(ProceedingJoinPoint joinPoint) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); - String requestURI = request.getRequestURI(); - HttpMethodType requestMethod = HttpMethodType.valueOf(request.getMethod()); - ContentCachingRequestWrapper cachingRequest = (ContentCachingRequestWrapper)request; - String requestMessage = new String(cachingRequest.getContentAsByteArray()); Object result = joinPoint.proceed(); - - Admin admin = adminRepository.getById(authContext.getUserId()); - DomainInfo domainInfo = getDomainInfo(requestURI); + AdminLogging annotation = getAnnotation(joinPoint); adminActivityHistoryRepository.save(AdminActivityHistory.builder() - .domainId(domainInfo.domainId()) - .admin(admin) - .requestMethod(requestMethod) - .domainName(DomainType.valueOf(domainInfo.domainName())) - .requestMessage(requestMessage) + .domainId(getDomainId(annotation, request.getRequestId())) + .admin(adminRepository.getById(authContext.getUserId())) + .requestMethod(HttpMethodType.valueOf(request.getMethod())) + .domainName(annotation.domainType()) + .requestMessage(new String(cachingRequest.getContentAsByteArray())) .build() ); return result; } - private DomainInfo getDomainInfo(String requestURI) { - String[] segments = requestURI.split("/"); - Integer domainId = null; - String domainName = null; - - for (int i = segments.length - 1; i >= 0; i--) { - String segment = segments[i]; - - if (isDomainType(segment)) { - domainName = getDomainName(segment, segments, i); - domainId = getDomainId(segments, i); - break; - } - - if (isCloseAbtest(segment, segments, i)) { - domainName = segments[i - 1].toUpperCase(); - domainId = Integer.valueOf(segments[i + 1]); - break; - } - } - - return new DomainInfo(domainId, domainName); - } - - private boolean isDomainType(String segment) { - return EnumUtils.isValidEnumIgnoreCase(DomainType.class, segment); + private AdminLogging getAnnotation(ProceedingJoinPoint joinPoint) { + MethodSignature signature = (MethodSignature)joinPoint.getSignature(); + Method method = signature.getMethod(); + return method.getAnnotation(AdminLogging.class); } - private String getDomainName(String segment, String[] segments, int index) { - String domainName = segment.toUpperCase(); - - if (SEGMENT_SHOPS.equals(domainName) && SEGMENT_BENEFIT.equals(segments[index - 2])) { - return segments[index - 2].toUpperCase(); - } - - if (SEGMENT_CATEGORIES.equals(domainName)) { - return (segments[index - 1] + domainName).toUpperCase(); - } + private Integer getDomainId(AdminLogging annotation, String requestURI) { + if (annotation.hasId()) { + String[] segments = requestURI.split(SEPARATOR); - return domainName; - } - - private Integer getDomainId(String[] segments, int index) { - if (index != segments.length - 1 && segments[index + 1].matches(REGEX_NUMERIC)) { - return Integer.valueOf(segments[index + 1]); + for (int index = segments.length - 1; index >= 0; index--) { + if (segments[index].matches(REGEX_NUMERIC)) { + return Integer.parseInt(segments[index]); + } + } } return null; } - - private boolean isCloseAbtest(String segment, String[] segments, int index) { - return SEGMENT_CLOSE.equals(segment) && SEGMENT_ABTEST.equals(segments[index - 1]); - } - - private record DomainInfo(Integer domainId, String domainName) { - } } diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java new file mode 100644 index 000000000..c8b77b6f0 --- /dev/null +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java @@ -0,0 +1,20 @@ +package in.koreatech.koin.admin.history.aop; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.springframework.context.annotation.Profile; + +import in.koreatech.koin.admin.history.enums.DomainType; + +@Retention(RUNTIME) +@Target(METHOD) +@Profile("!test") +public @interface AdminLogging { + DomainType domainType(); + + boolean hasId() default false; +} From 7d1052cf0f1824116f003de2c8d3b5cb25b4affb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Wed, 11 Dec 2024 19:35:04 +0900 Subject: [PATCH 13/15] =?UTF-8?q?Revert=20"fix:=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7c1ecb22d5fe15b506432089e6019df14ad0ed3e. --- .../aop/AdminActivityHistoryAspect.java | 113 ++++++++++++++---- .../koin/admin/history/aop/AdminLogging.java | 20 ---- 2 files changed, 89 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java index 3f385ffa2..720ae012c 100644 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java +++ b/src/main/java/in/koreatech/koin/admin/history/aop/AdminActivityHistoryAspect.java @@ -1,20 +1,21 @@ package in.koreatech.koin.admin.history.aop; -import java.lang.reflect.Method; - +import org.apache.commons.lang3.EnumUtils; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.reflect.MethodSignature; +import org.aspectj.lang.annotation.Pointcut; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.util.ContentCachingRequestWrapper; +import in.koreatech.koin.admin.history.enums.DomainType; import in.koreatech.koin.admin.history.enums.HttpMethodType; import in.koreatech.koin.admin.history.model.AdminActivityHistory; import in.koreatech.koin.admin.history.repository.AdminActivityHistoryRepository; +import in.koreatech.koin.admin.user.model.Admin; import in.koreatech.koin.admin.user.repository.AdminRepository; import in.koreatech.koin.global.auth.AuthContext; import jakarta.servlet.http.HttpServletRequest; @@ -25,50 +26,114 @@ @Profile("!test") @RequiredArgsConstructor public class AdminActivityHistoryAspect { - - private static final String SEPARATOR = "/"; private static final String REGEX_NUMERIC = "^[0-9]*$"; + private static final String SEGMENT_SHOPS = "SHOPS"; + private static final String SEGMENT_BENEFIT = "benefit"; + private static final String SEGMENT_CATEGORIES = "CATEGORIES"; + private static final String SEGMENT_CLOSE = "close"; + private static final String SEGMENT_ABTEST = "abtest"; private final AuthContext authContext; private final AdminRepository adminRepository; private final AdminActivityHistoryRepository adminActivityHistoryRepository; - @Around("@annotation(AdminLogging) && (args(..))") + @Pointcut("execution(* in.koreatech.koin.admin..controller.*.*(..))") + private void allAdminControllers() { + } + + @Pointcut("!@annotation(org.springframework.web.bind.annotation.GetMapping)") + private void excludeGetMapping() { + } + + @Pointcut("!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminLogin(..)) && " + + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.logout(..)) && " + + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && " + + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && " + + "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && " + + "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..)) &&" + + "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.issueAccessHistoryId(..))") + private void excludeSpecificMethods() { + } + + @Around("allAdminControllers() && excludeGetMapping() && excludeSpecificMethods()") public Object logAdminActivity(ProceedingJoinPoint joinPoint) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); + String requestURI = request.getRequestURI(); + HttpMethodType requestMethod = HttpMethodType.valueOf(request.getMethod()); + ContentCachingRequestWrapper cachingRequest = (ContentCachingRequestWrapper)request; + String requestMessage = new String(cachingRequest.getContentAsByteArray()); Object result = joinPoint.proceed(); - AdminLogging annotation = getAnnotation(joinPoint); + + Admin admin = adminRepository.getById(authContext.getUserId()); + DomainInfo domainInfo = getDomainInfo(requestURI); adminActivityHistoryRepository.save(AdminActivityHistory.builder() - .domainId(getDomainId(annotation, request.getRequestId())) - .admin(adminRepository.getById(authContext.getUserId())) - .requestMethod(HttpMethodType.valueOf(request.getMethod())) - .domainName(annotation.domainType()) - .requestMessage(new String(cachingRequest.getContentAsByteArray())) + .domainId(domainInfo.domainId()) + .admin(admin) + .requestMethod(requestMethod) + .domainName(DomainType.valueOf(domainInfo.domainName())) + .requestMessage(requestMessage) .build() ); return result; } - private AdminLogging getAnnotation(ProceedingJoinPoint joinPoint) { - MethodSignature signature = (MethodSignature)joinPoint.getSignature(); - Method method = signature.getMethod(); - return method.getAnnotation(AdminLogging.class); - } + private DomainInfo getDomainInfo(String requestURI) { + String[] segments = requestURI.split("/"); + Integer domainId = null; + String domainName = null; - private Integer getDomainId(AdminLogging annotation, String requestURI) { - if (annotation.hasId()) { - String[] segments = requestURI.split(SEPARATOR); + for (int i = segments.length - 1; i >= 0; i--) { + String segment = segments[i]; - for (int index = segments.length - 1; index >= 0; index--) { - if (segments[index].matches(REGEX_NUMERIC)) { - return Integer.parseInt(segments[index]); - } + if (isDomainType(segment)) { + domainName = getDomainName(segment, segments, i); + domainId = getDomainId(segments, i); + break; } + + if (isCloseAbtest(segment, segments, i)) { + domainName = segments[i - 1].toUpperCase(); + domainId = Integer.valueOf(segments[i + 1]); + break; + } + } + + return new DomainInfo(domainId, domainName); + } + + private boolean isDomainType(String segment) { + return EnumUtils.isValidEnumIgnoreCase(DomainType.class, segment); + } + + private String getDomainName(String segment, String[] segments, int index) { + String domainName = segment.toUpperCase(); + + if (SEGMENT_SHOPS.equals(domainName) && SEGMENT_BENEFIT.equals(segments[index - 2])) { + return segments[index - 2].toUpperCase(); + } + + if (SEGMENT_CATEGORIES.equals(domainName)) { + return (segments[index - 1] + domainName).toUpperCase(); + } + + return domainName; + } + + private Integer getDomainId(String[] segments, int index) { + if (index != segments.length - 1 && segments[index + 1].matches(REGEX_NUMERIC)) { + return Integer.valueOf(segments[index + 1]); } return null; } + + private boolean isCloseAbtest(String segment, String[] segments, int index) { + return SEGMENT_CLOSE.equals(segment) && SEGMENT_ABTEST.equals(segments[index - 1]); + } + + private record DomainInfo(Integer domainId, String domainName) { + } } diff --git a/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java b/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java deleted file mode 100644 index c8b77b6f0..000000000 --- a/src/main/java/in/koreatech/koin/admin/history/aop/AdminLogging.java +++ /dev/null @@ -1,20 +0,0 @@ -package in.koreatech.koin.admin.history.aop; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.springframework.context.annotation.Profile; - -import in.koreatech.koin.admin.history.enums.DomainType; - -@Retention(RUNTIME) -@Target(METHOD) -@Profile("!test") -public @interface AdminLogging { - DomainType domainType(); - - boolean hasId() default false; -} From c5958dfc6b6dca4e79e60ee14bdfd8f2825312b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Fri, 13 Dec 2024 12:22:05 +0900 Subject: [PATCH 14/15] =?UTF-8?q?chore:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../history/dto/AdminHistoriesCondition.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java index 2932b1777..aec40405b 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java @@ -1,19 +1,19 @@ package in.koreatech.koin.admin.history.dto; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.Objects; + import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import static in.koreatech.koin.global.model.Criteria.*; +import static in.koreatech.koin.global.model.Criteria.Sort.CREATED_AT_ASC; import static in.koreatech.koin.global.model.Criteria.Sort.CREATED_AT_DESC; import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; import static org.springframework.data.domain.Sort.Direction; -import java.util.Objects; - -import com.fasterxml.jackson.databind.annotation.JsonNaming; - -import in.koreatech.koin.admin.history.enums.DomainType; -import in.koreatech.koin.admin.history.enums.HttpMethodType; -import io.swagger.v3.oas.annotations.media.Schema; - @JsonNaming(value = SnakeCaseStrategy.class) public record AdminHistoriesCondition( @Schema(description = "페이지", example = "1", defaultValue = "1", requiredMode = NOT_REQUIRED) @@ -47,7 +47,7 @@ public record AdminHistoriesCondition( } public Direction getSortDir() { - if (sort == Sort.CREATED_AT_ASC) { + if (sort == CREATED_AT_ASC) { return Direction.ASC; } return Direction.DESC; From 0a93a546d10109519be773912735bb665797d866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EA=B4=80=EA=B7=9C?= Date: Fri, 13 Dec 2024 12:25:46 +0900 Subject: [PATCH 15/15] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../history/dto/AdminHistoriesCondition.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java index aec40405b..e7e775554 100644 --- a/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java +++ b/src/main/java/in/koreatech/koin/admin/history/dto/AdminHistoriesCondition.java @@ -1,12 +1,5 @@ package in.koreatech.koin.admin.history.dto; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import in.koreatech.koin.admin.history.enums.DomainType; -import in.koreatech.koin.admin.history.enums.HttpMethodType; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.Objects; - import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import static in.koreatech.koin.global.model.Criteria.*; import static in.koreatech.koin.global.model.Criteria.Sort.CREATED_AT_ASC; @@ -14,6 +7,14 @@ import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; import static org.springframework.data.domain.Sort.Direction; +import java.util.Objects; + +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import in.koreatech.koin.admin.history.enums.DomainType; +import in.koreatech.koin.admin.history.enums.HttpMethodType; +import io.swagger.v3.oas.annotations.media.Schema; + @JsonNaming(value = SnakeCaseStrategy.class) public record AdminHistoriesCondition( @Schema(description = "페이지", example = "1", defaultValue = "1", requiredMode = NOT_REQUIRED)