-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/auditlogs #55
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
Changes from all commits
1c93b63
7f6a559
e51fc7f
c258810
523b8d1
df24570
03db623
df9f9fc
acdaaaa
e4e7929
b668503
3963deb
33314c8
8428460
5eedb44
a984519
c7cb136
80bcd77
e5fc895
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
|
|
||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
|
|
||
| @Configuration | ||
| @EnableAspectJAutoProxy | ||
| public class AspectConfig { | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface AuditAction { | ||
| String action(); | ||
| String entity(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
| import org.aspectj.lang.JoinPoint; | ||
| import org.aspectj.lang.annotation.AfterReturning; | ||
| import org.aspectj.lang.annotation.AfterThrowing; | ||
| import org.aspectj.lang.annotation.Aspect; | ||
| import org.aspectj.lang.annotation.Pointcut; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.context.request.RequestContextHolder; | ||
| import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
|
||
| @Aspect | ||
| @Component | ||
| public class AuditAspect { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(AuditAspect.class); | ||
|
|
||
| private final AuditService auditService; | ||
|
|
||
| public AuditAspect(AuditService auditService) { | ||
| this.auditService = auditService; | ||
| } | ||
|
|
||
| @Pointcut("within(backendlab.team4you..*)") | ||
| public void controllerMethods() {} | ||
|
|
||
| @AfterReturning(pointcut = "@annotation(auditAction)", returning = "result") | ||
| public void logAuditSuccess(JoinPoint joinPoint, AuditAction auditAction, Object result) { | ||
| record(joinPoint, auditAction, "SUCCESS"); | ||
| } | ||
|
|
||
| @AfterThrowing(pointcut = "@annotation(auditAction)", throwing = "ex") | ||
| public void logAuditFailure(JoinPoint joinPoint, AuditAction auditAction, Throwable ex) { | ||
| record(joinPoint, auditAction, "FAILURE"); | ||
| } | ||
|
|
||
| private void record(JoinPoint joinPoint, AuditAction auditAction, String status) { | ||
| try { | ||
| Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| String username = (auth != null) ? auth.getName() : "anonymous"; | ||
|
|
||
| ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | ||
| String ip = "unknown"; | ||
| String endpoint = "unknown"; | ||
| String httpMethod = "UNKNOWN"; | ||
|
|
||
| if (attrs != null) { | ||
| ip = attrs.getRequest().getRemoteAddr(); | ||
| endpoint = attrs.getRequest().getRequestURI(); | ||
| httpMethod = attrs.getRequest().getMethod(); | ||
| } | ||
|
|
||
|
|
||
| String methodName = joinPoint.getSignature().toShortString(); | ||
| String details = "Executed method: " + methodName; | ||
| Long entityId = null; | ||
|
|
||
| Object[] args = joinPoint.getArgs(); | ||
| for (Object arg : args) { | ||
| if (arg instanceof Long) { | ||
| entityId = (Long) arg; | ||
| } else if (arg instanceof String && !((String) arg).contains("/")) { | ||
| details = "File/Key: " + arg; | ||
| } | ||
| } | ||
|
|
||
| auditService.saveLog( | ||
| username, | ||
| null, | ||
| auditAction.action(), | ||
| endpoint, | ||
| httpMethod, | ||
| ip, | ||
| status, | ||
| details, | ||
| auditAction.entity(), | ||
| Math.toIntExact(entityId) | ||
|
|
||
| ); | ||
|
|
||
| } catch (Exception e) { | ||
| log.warn("Failed to persist audit log for {}: {}", | ||
| joinPoint.getSignature().toShortString(), e.getMessage(), e); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
| import java.time.ZonedDateTime; | ||
|
|
||
| @Entity | ||
| @Table(name = "audit") | ||
| public class AuditLog { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
|
|
||
| private String username; | ||
| private String email; | ||
|
|
||
| String details; | ||
|
|
||
| private String action; | ||
|
|
||
| private String httpMethod; | ||
|
|
||
| private String endpoint; | ||
|
|
||
| private String entityType; | ||
|
|
||
| private Long entityId; | ||
|
|
||
| @Column(name = "ip_address") | ||
| private String ipAddress; | ||
|
|
||
|
|
||
| private ZonedDateTime timestamp; | ||
|
|
||
| private String status; | ||
|
|
||
|
|
||
| public AuditLog() { | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
| public String getUsername() { | ||
| return username; | ||
| } | ||
| public void setUsername(String username) { | ||
| this.username = username; | ||
| } | ||
| public String getEmail() { | ||
| return email; | ||
| } | ||
| public void setEmail(String email) { | ||
| this.email = email; | ||
| } | ||
| public String getAction() { | ||
| return action; | ||
| } | ||
| public void setAction(String action) { | ||
| this.action = action; | ||
| } | ||
| public String getEndpoint() { | ||
| return endpoint; | ||
| } | ||
| public void setEndpoint(String endpoint) { | ||
| this.endpoint = endpoint; | ||
| } | ||
| public String getEntityType() { | ||
| return entityType; | ||
| } | ||
| public void setEntityType(String entityType) { | ||
| this.entityType = entityType; | ||
| } | ||
| public Long getEntityId() { | ||
| return entityId; | ||
| } | ||
| public void setEntityId(Long entityId) { | ||
| this.entityId = entityId; | ||
| } | ||
|
|
||
| public String getIpAddress() { | ||
| return ipAddress; | ||
| } | ||
| public void setIpAddress(String ipAddress) { | ||
| this.ipAddress = ipAddress; | ||
| } | ||
| public ZonedDateTime getTimestamp() { | ||
| return timestamp; | ||
| } | ||
| public void setTimestamp(ZonedDateTime timestamp) { | ||
| this.timestamp = timestamp; | ||
| } | ||
| public String getStatus() { | ||
| return status; | ||
| } | ||
| public void setStatus(String status) { | ||
| this.status = status; | ||
| } | ||
| public String getDetails() { | ||
| return details; | ||
| } | ||
| public void setDetails(String details) { | ||
| this.details = details; | ||
| } | ||
| public String getHttpMethod() { | ||
| return httpMethod; | ||
| } | ||
| public void setHttpMethod(String httpMethod) { | ||
| this.httpMethod = httpMethod; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface AuditLogRepository extends JpaRepository<AuditLog, Long> { | ||
|
|
||
|
|
||
| List<AuditLog> findAllByOrderByTimestampDesc(); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package backendlab.team4you.audit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.ZonedDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class AuditService { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final Logger log = LoggerFactory.getLogger(AuditService.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AuditLogRepository auditLogRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public AuditService(AuditLogRepository auditRepository) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.auditLogRepository = auditRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void saveLog( String username, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String email, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String action, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String endpoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String httpMethod, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String ipAddress, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String details, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String entityType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int entityId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AuditLog log = new AuditLog(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setUsername(username); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setEmail(email); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setAction(action); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setEndpoint(endpoint); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setIpAddress(ipAddress); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setTimestamp(ZonedDateTime.now()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setDetails(details); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setStatus(status); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setHttpMethod(httpMethod); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setEntityType(entityType); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.setEntityId((long) entityId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLogRepository.save(log); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void log(String username, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String action, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String entityType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Long entityId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String details, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AuditLog auditLog = new AuditLog(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setUsername(username); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setAction(action); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setEntityType(entityType); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setEntityId((long) Math.toIntExact(entityId)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setDetails(details); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setStatus(status); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLog.setTimestamp(ZonedDateTime.now()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auditLogRepository.save(auditLog); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.info("Audit log saved: action={}, entity={}:{}", action, entityType, entityId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| System.out.println("Failed to save audit log " + e.getMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace A few concerns in
🛡️ Proposed fix-import org.springframework.stereotype.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
...
public class AuditService {
+ private static final Logger log = LoggerFactory.getLogger(AuditService.class);
...
public void log(String username,
String action,
String entityType,
Long entityId,
String details,
String status) {
-
- {
- try {
- AuditLog auditLog = new AuditLog();
-
- auditLog.setUsername(username);
- auditLog.setAction(action);
- auditLog.setEntityType(entityType);
- auditLog.setEntityId(Math.toIntExact(entityId));
- auditLog.setDetails(details);
- auditLog.setStatus(status);
- auditLog.setTimestamp(ZonedDateTime.now());
-
- auditLogRepository.save(auditLog);
-
- System.out.println(" Audit log saved " + action);
-
- } catch (Exception e) {
- System.out.println("Failed to save audit log " + e.getMessage());
- }
- }
-
+ try {
+ AuditLog auditLog = new AuditLog();
+ auditLog.setUsername(username);
+ auditLog.setAction(action);
+ auditLog.setEntityType(entityType);
+ auditLog.setEntityId(entityId); // change field type to Long, see AuditLog.java
+ auditLog.setDetails(details);
+ auditLog.setStatus(status);
+ auditLog.setTimestamp(ZonedDateTime.now());
+ auditLogRepository.save(auditLog);
+ log.info("Audit log saved: action={}, entity={}:{}", action, entityType, entityId);
+ } catch (Exception e) {
+ log.error("Failed to save audit log for action={}, entity={}:{}", action, entityType, entityId, e);
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package backendlab.team4you.audit; | ||
|
|
||
| public enum AuditStatus { | ||
| SUCCESS, | ||
| FAILURE, | ||
| PENDING | ||
|
|
||
| } | ||
|
Comment on lines
+3
to
+8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm AuditStatus is unused anywhere
rg -nP '\bAuditStatus\b' --type=javaRepository: ithsjava25/project-backend-team4you Length of output: 164 🏁 Script executed: # First, let's see the full AuditStatus.java file to check the blank line issue
cat -n src/main/java/backendlab/team4you/audit/AuditStatus.javaRepository: ithsjava25/project-backend-team4you Length of output: 238 🏁 Script executed: # Find and inspect AuditLog class to see how status field is typed
find . -name "AuditLog.java" -type fRepository: ithsjava25/project-backend-team4you Length of output: 135 🏁 Script executed: # Find and inspect AuditService class to see method signatures
find . -name "AuditService.java" -type fRepository: ithsjava25/project-backend-team4you Length of output: 139 🏁 Script executed: # Read AuditLog.java
cat -n src/main/java/backendlab/team4you/audit/AuditLog.javaRepository: ithsjava25/project-backend-team4you Length of output: 3078 🏁 Script executed: # Read AuditService.java
cat -n src/main/java/backendlab/team4you/audit/AuditService.javaRepository: ithsjava25/project-backend-team4you Length of output: 2688 Enum is defined but appears unused — type Based on Remove the blank line at line 7 inside the enum body. 🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.