Advertisement
Guest User

Untitled

a guest
May 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. @PostMapping(value = "/room-types", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  2. public RoomType saveRoom(@RequestPart("image") MultipartFile image, @Valid @RequestPart("roomType") RoomType roomType) throws IOException {
  3.  
  4.  
  5. String imageName = "";
  6. Integer roomTypeId = roomType.getId();
  7.  
  8. if(roomTypeId != null){
  9. imageName = roomTypeService.findImagePathById(roomTypeId);
  10. if(imageService.doesImageExist(imageName)) {
  11. imageService.deleteImage(imageName);
  12. }
  13. }
  14.  
  15. String fileName = imageService.saveImage(image.getInputStream(), image.getOriginalFilename());
  16. if (fileName != null) {
  17. roomType.setImage(fileName);
  18. return roomTypeService.saveRoomType(roomType);
  19. }
  20. return new RoomType();
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement