/** GET /platforms/:id -> get the "id" platform. */ @RequestMapping( value = "/platforms/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<PlatformDTO> get(@PathVariable String id) { log.debug("REST request to get Platform : {}", id); return Optional.ofNullable(platformRepository.findOne(id)) .map(platformMapper::platformToPlatformDTO) .map(platformDTO -> new ResponseEntity<>(platformDTO, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
/** DELETE /platforms/:id -> delete the "id" platform. */ @RequestMapping( value = "/platforms/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<PlatformDTO> delete(@PathVariable String id) { log.debug("REST request to delete Platform : {}", id); return Optional.ofNullable(platformRepository.findOne(id)) .map( p -> { platformRepository.delete(id); return p; }) .map(platformMapper::platformToPlatformDTO) .map( dto -> ResponseEntity.ok() .headers(HeaderUtil.createEntityDeletionAlert("platform", id.toString())) .body(dto)) .orElse(new ResponseEntity<PlatformDTO>(HttpStatus.NOT_FOUND)); }
/** POST /platforms -> Create a new platform. */ @RequestMapping( value = "/platforms", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<PlatformDTO> create(@Valid @RequestBody PlatformDTO platformDTO) throws URISyntaxException { log.debug("REST request to save Platform : {}", platformDTO); Platform platform = platformMapper.platformDTOToPlatform(platformDTO); Platform result = platformRepository.save(platform); return ResponseEntity.created(new URI("/api/platforms/" + result.getName())) .headers(HeaderUtil.createEntityCreationAlert("platform", result.getName().toString())) .body(platformMapper.platformToPlatformDTO(result)); }
/** PUT /platforms -> Updates an existing platform. */ @RequestMapping( value = "/platforms", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<PlatformDTO> update(@Valid @RequestBody PlatformDTO platformDTO) throws URISyntaxException { log.debug("REST request to update Platform : {}", platformDTO); if (platformDTO.getName() == null) { return create(platformDTO); } Platform platform = platformMapper.platformDTOToPlatform(platformDTO); Platform result = platformRepository.save(platform); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert("platform", platformDTO.getName().toString())) .body(platformMapper.platformToPlatformDTO(result)); }
/** GET /platforms -> get all the platforms. */ @RequestMapping( value = "/platforms", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed @Transactional(readOnly = true) public ResponseEntity<List<PlatformDTO>> getAll( @RequestParam(value = "page", required = false) Integer offset, @RequestParam(value = "per_page", required = false) Integer limit) throws URISyntaxException { Page<Platform> page = platformRepository.findAll(PaginationUtil.generatePageRequest(offset, limit)); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/platforms", offset, limit); return new ResponseEntity<>( page.getContent() .stream() .map(platformMapper::platformToPlatformDTO) .collect(Collectors.toCollection(LinkedList::new)), headers, HttpStatus.OK); }