Add audit log search feature

Problem Context

The security team needs to search audit logs by date range and user for compliance reporting. The audit_logs table has millions of records.

Advanced
200 points

File Changes (2)

src/main/java/com/example/entity/AuditLog.java MODIFIED
@@ -1 +1 @@
1 1 @Entity
2 2 @Table(name = "audit_logs")
3 3 public class AuditLog {
4 4 @Id
5 5 @GeneratedValue(strategy = GenerationType.IDENTITY)
6 6 private Long id;
7 7
8 8 private Long userId;
9 9 private String action;
10 10 private String details;
11 11 private LocalDateTime createdAt;
12 12 }
src/main/java/com/example/repository/AuditLogRepository.java MODIFIED
@@ -1 +1 @@
1 1 public interface AuditLogRepository extends JpaRepository<AuditLog, Long> {
2 +
3 + @Query("SELECT a FROM AuditLog a WHERE a.createdAt BETWEEN :start AND :end")
4 + List<AuditLog> findByDateRange(@Param("start") LocalDateTime start,
5 + @Param("end") LocalDateTime end);
6 +
7 + @Query("SELECT a FROM AuditLog a WHERE a.userId = :userId AND a.createdAt BETWEEN :start AND :end")
8 + List<AuditLog> findByUserAndDateRange(@Param("userId") Long userId,
9 + @Param("start") LocalDateTime start,
10 + @Param("end") LocalDateTime end);
2 11 }
Login Required: You must be registered to submit reviews and receive AI feedback. Register or login to start reviewing!

Your Review

Tip: Be thorough! Consider security, performance, code quality, and best practices.
Review Tips
  • Look for security vulnerabilities (SQL injection, XSS, etc.)
  • Check for null pointer exceptions and error handling
  • Consider performance implications
  • Evaluate code maintainability and readability
  • Check for proper resource management
  • Look for logic errors or edge cases
Analyzing Your Review
Our AI is carefully evaluating your code review against best practices