class CargoTrackingRestService {
    private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    private final CargoRepository cargoRepository;
    private final HandlingEventRepository handlingEventRepository;
    private final MessageSource messageSource;

    public CargoTrackingRestService(CargoRepository cargoRepository, HandlingEventRepository handlingEventRepository, MessageSource messageSource) {
        this.cargoRepository = cargoRepository;
        this.handlingEventRepository = handlingEventRepository;
        this.messageSource = messageSource;
    }

    @GetMapping(value = "/api/track/{trackingId}", produces = APPLICATION_JSON_VALUE)
    public ResponseEntity<CargoTrackingDTO> trackCargo(final HttpServletRequest request,
                                                       @PathVariable("trackingId") String trackingId) {<FILL_FUNCTION_BODY>}
}

        try {
            Locale locale = RequestContextUtils.getLocale(request);
            TrackingId trkId = new TrackingId(trackingId);
            Cargo cargo = cargoRepository.find(trkId);
            if (cargo == null) {
                throw new NotFoundException("No cargo found for trackingId");
            }
            final List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(trkId)
                    .distinctEventsByCompletionTime();
            return ResponseEntity.ok(CargoTrackingDTOConverter.convert(cargo, handlingEvents, messageSource, locale));
        } catch (NotFoundException e) {
            URI uri = new UriTemplate(request.getContextPath() + "/api/track/{trackingId}").expand(trackingId);
            return ResponseEntity.notFound().location(uri).build();
        } catch (Exception e) {
            log.error("Unexpected error in trackCargo endpoint", e);
            return ResponseEntity.status(500).build();
        }
    
<no_super_class>