Add status check endpoint

Problem Context

We need a simple endpoint that returns whether a user account is active or not.

Intermediate
100 points

File Changes (1)

src/main/java/com/example/service/UserStatusService.java ADDED
@@ -0 +1 @@
1 +package com.example.service;
2 +
3 +@Service
4 +public class UserStatusService {
5 + private final UserRepository userRepository;
6 + private final StatusResponseFactory responseFactory;
7 + private final StatusCheckStrategySelector strategySelector;
8 +
9 + public StatusResponse checkUserStatus(Long userId) {
10 + User user = userRepository.findById(userId)
11 + .orElseThrow(() -> new UserNotFoundException(userId));
12 +
13 + StatusCheckStrategy strategy = strategySelector.selectStrategy(user);
14 + StatusCheckResult result = strategy.checkStatus(user);
15 +
16 + return responseFactory.createResponse(
17 + StatusResponseBuilder.builder()
18 + .withUserId(userId)
19 + .withStatus(result.getStatus())
20 + .withTimestamp(Instant.now())
21 + .withMetadata(result.getMetadata())
22 + .build()
23 + );
24 + }
25 +}
26 +
27 +// Could have been simply:
28 +// public boolean isUserActive(Long userId) {
29 +// return userRepository.findById(userId)
30 +// .map(User::isActive)
31 +// .orElse(false);
32 +// }
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