#480 Code Review of a Cached Photo Service
Perform a review and identify the problems:
@RequiredArgsConstructor
@RestController("/resize/v1")
public class Controller {
private final CachedPhotosService cachedPhotosService;
@GetMapping("/resized-photo/{photo-id}")
public PhootoDTO getResizedPhoto(@PathVariable("photo-id") String photoId) {
return cachedPhotosService.iconifiedPhoto(photoId);
}
}
@Component
@RequiredArgsConstructor
public class CachedPhotosService {
private static final String RESIZED_PHOTO_CACHE_NAME = "RESIZED_PHOTO_CACHE_NAME";
private final PhotoRepository photoRepository;
private final PhotoValidationService photoValidationService;
private final PhotoOperations photoOperations;
@Cacheable(cacheNames = RESIZED_PHOTO_CACHE_NAME)
public PhotoDTO resizedPhoto(String photoId, int width, int height) {
photoValidationService.validateSize(width, height);
Photo photo = photoRepository.findById(photoId);
PhotoDTO photoDto = ConversionUtils.convert(photo);
var resizedPhoto = photoOperations.resize(photoDto, width, height);
return resizedPhoto;
}
public PhotoDTO iconifiedPhoto(String photoId) {
return resizedPhoto(photoId, 100, 100);
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor