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