Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @PostMapping(value = "/room-types", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
- public RoomType saveRoom(@RequestPart("image") MultipartFile image, @Valid @RequestPart("roomType") RoomType roomType) throws IOException {
- String imageName = "";
- Integer roomTypeId = roomType.getId();
- if(roomTypeId != null){
- imageName = roomTypeService.findImagePathById(roomTypeId);
- if(imageService.doesImageExist(imageName)) {
- imageService.deleteImage(imageName);
- }
- }
- String fileName = imageService.saveImage(image.getInputStream(), image.getOriginalFilename());
- if (fileName != null) {
- roomType.setImage(fileName);
- return roomTypeService.saveRoomType(roomType);
- }
- return new RoomType();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement