Repository navigation
Enhance Java packages for DTO and WebAuthn and tests - #62
Conversation
✅ Deploy Preview for employee-management-fullstack-system canceled.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Code Review
This pull request restructures the backend application, introducing Data Transfer Objects (DTOs) for validation, a global exception handler, and WebAuthn/Passkey authentication. Key feedback highlights critical improvements: in EmployeeService, calling entityManager.clear() should be avoided to prevent detaching managed entities; in DepartmentService, getDepartmentById should use standard lazy loading instead of eagerly fetching all employees to avoid performance bottlenecks; in GlobalExceptionHandler, unexpected exceptions should be logged rather than swallowed; and in JwtRequestFilter, redundant filter chain calls in the exception catch block should be simplified.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| public Employee saveEmployee(Employee employee) { | ||
| return employeeRepository.save(employee); | ||
| Employee saved = employeeRepository.save(employee); | ||
| entityManager.flush(); | ||
| entityManager.clear(); | ||
| return employeeRepository.findByIdWithDepartment(saved.getId()).orElse(saved); | ||
| } |
There was a problem hiding this comment.
Calling entityManager.clear() inside a service method is highly discouraged in Spring/JPA applications. It detaches all currently managed entities from the persistence context. If this method is called within a larger transaction, any other entities loaded in that transaction will be detached, which can lead to unexpected LazyInitializationExceptions or prevent automatic dirty checking/updates. Since Employee has an EAGER fetch type for department, employeeRepository.save(employee) already returns the fully populated entity, making the flush, clear, and reload redundant.
public Employee saveEmployee(Employee employee) {
return employeeRepository.save(employee);
}| public Optional<Department> getDepartmentById(Long id) { | ||
| return departmentRepository.findById(id); | ||
| return departmentRepository.findByIdWithEmployees(id); | ||
| } |
There was a problem hiding this comment.
Using findByIdWithEmployees(id) inside getDepartmentById eagerly loads all employees of the department. This method is used in EmployeeController to resolve the department reference when creating or updating an employee. If a department has a large number of employees, this will cause a significant performance bottleneck by loading all of them into memory unnecessarily. Instead, use the standard findById(id) method which loads the department lazily, and only fetch employees when explicitly required.
| public Optional<Department> getDepartmentById(Long id) { | |
| return departmentRepository.findById(id); | |
| return departmentRepository.findByIdWithEmployees(id); | |
| } | |
| public Optional<Department> getDepartmentById(Long id) { | |
| return departmentRepository.findById(id); | |
| } |
| @ExceptionHandler(Exception.class) | ||
| public ResponseEntity<Map<String, String>> handleGenericException(Exception ex) { | ||
|
|
||
| Map<String, String> error = new HashMap<>(); | ||
| error.put("message", "An unexpected error occurred"); | ||
|
|
||
| return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR); | ||
| } |
There was a problem hiding this comment.
The catch-all exception handler swallows the unexpected exception without logging it. This makes debugging production issues extremely difficult because the stack trace is completely lost. You should log the exception at the ERROR level before returning the generic error response to the client.
@ExceptionHandler(Exception.class)
public ResponseEntity<Map<String, String>> handleGenericException(Exception ex) {
org.slf4j.LoggerFactory.getLogger(GlobalExceptionHandler.class).error(\"Unexpected error occurred\", ex);
Map<String, String> error = new HashMap<>();
error.put(\"message\", \"An unexpected error occurred\");
return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}| try { | ||
| username = jwtTokenUtil.extractUsername(jwt); | ||
| } catch (Exception e) { | ||
| // Invalid/expired/malformed token — continue unauthenticated | ||
| chain.doFilter(request, response); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Calling chain.doFilter(request, response) and returning inside the catch block is redundant. If an exception is thrown, username remains null, the subsequent authentication block is skipped, and the execution naturally falls through to the end of the doFilterInternal method where chain.doFilter(request, response) is called. You can simplify this by catching the exception and doing nothing (or logging it at a debug level), letting the filter chain proceed naturally.
try {
username = jwtTokenUtil.extractUsername(jwt);
} catch (Exception e) {
// Invalid/expired/malformed token — continue unauthenticated
}
This pull request removes several IDE-specific data source configuration and metadata files from the
.ideadirectory. These files are typically generated by JetBrains IDEs (like IntelliJ IDEA) to store local database connection settings and schema metadata, and are not necessary to keep in version control.Removed IDE data source configuration and metadata files:
Data source configuration:
.idea/dataSources.local.xml, which contained local database connection definitions and credentials.Database metadata (for various data sources):
.idea/dataSources/*/storage_v2/_src_/schema/and.idea/dataSources/*/storage_v2/_src_/database/. These files stored local introspection data for schemas likeinformation_schema,pg_catalog,public,mysql,performance_schema, andsys. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]This cleanup helps keep the repository free from unnecessary local or environment-specific files.