From 480a07da3352db0c1d653f9403e34f72a1ceafbb Mon Sep 17 00:00:00 2001 From: saebomnewspring Date: Sat, 31 May 2025 15:03:32 +0900 Subject: [PATCH] =?UTF-8?q?Update=20:=20api-key=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=20=EC=82=AC=EC=9A=A9=20=EC=8B=9C=EA=B0=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fisa/pg/dto/response/ApiKeyResponseDto.java | 2 ++ .../java/com/fisa/pg/entity/auth/ApiKey.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fisa/pg/dto/response/ApiKeyResponseDto.java b/src/main/java/com/fisa/pg/dto/response/ApiKeyResponseDto.java index bdd3ac0..799bcfa 100644 --- a/src/main/java/com/fisa/pg/dto/response/ApiKeyResponseDto.java +++ b/src/main/java/com/fisa/pg/dto/response/ApiKeyResponseDto.java @@ -59,6 +59,7 @@ public class ApiKeyResponseDto { */ private LocalDateTime lastUsed; + public static ApiKeyResponseDto from(ApiKey apiKey) { return ApiKeyResponseDto.builder() .id(apiKey.getId()) @@ -69,6 +70,7 @@ public static ApiKeyResponseDto from(ApiKey apiKey) { .isActive(apiKey.isActive()) .issuedAt(apiKey.getIssuedAt()) .expiresAt(apiKey.getExpiresAt()) + .lastUsed(apiKey.getLastUsed()) .build(); } diff --git a/src/main/java/com/fisa/pg/entity/auth/ApiKey.java b/src/main/java/com/fisa/pg/entity/auth/ApiKey.java index 18d8566..9b3e959 100644 --- a/src/main/java/com/fisa/pg/entity/auth/ApiKey.java +++ b/src/main/java/com/fisa/pg/entity/auth/ApiKey.java @@ -71,12 +71,24 @@ public class ApiKey { @Column(name = "is_active", nullable = false) private boolean isActive; + /** + * 마지막 사용 시각 + */ + @Column(name = "last_used", nullable = true) + private LocalDateTime lastUsed; + /** * API 키 비활성화 메서드 */ + public void deactivate() { this.isActive = false; } - -} + /** + * API 키 사용 시각 업데이트 메서드 + */ + public void updateLastUsed() { + this.lastUsed = LocalDateTime.now(); + } +} \ No newline at end of file