Skip to content

Commit

Permalink
Return images on addImage()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Oct 30, 2023
1 parent 1087e49 commit 7af0cde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/nonononoki/alovoa/rest/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.nonononoki.alovoa.Tools;
import com.nonononoki.alovoa.entity.user.UserImage;
import com.nonononoki.alovoa.entity.user.UserMiscInfo;
import com.nonononoki.alovoa.model.AlovoaException;
import com.nonononoki.alovoa.model.ProfileOnboardingDto;
Expand Down Expand Up @@ -191,11 +192,11 @@ public void updateUnits(@PathVariable int units) throws AlovoaException {
}

@PostMapping(value = "/image/add", consumes = "text/plain")
public void addImage(@RequestBody String imageB64) throws AlovoaException, IOException {
public List<UserImage> addImage(@RequestBody String imageB64) throws AlovoaException, IOException {
if (Tools.getBase64Size(imageB64) > mediaMaxSize) {
throw new AlovoaException(AlovoaException.MAX_MEDIA_SIZE_EXCEEDED);
}
userService.addImage(imageB64);
return userService.addImage(imageB64);
}

@PostMapping("/image/delete/{imageId}")
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/nonononoki/alovoa/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void updateUnits(int units) throws AlovoaException {
userRepo.saveAndFlush(user);
}

public void addImage(String imgB64) throws AlovoaException, IOException {
public List<UserImage> addImage(String imgB64) throws AlovoaException, IOException {
User user = authService.getCurrentUser(true);
if (user.getImages() != null && user.getImages().size() < imageMax) {

Expand All @@ -588,7 +588,8 @@ public void addImage(String imgB64) throws AlovoaException, IOException {
img.setDate(new Date());
img.setUser(user);
user.getImages().add(img);
userRepo.saveAndFlush(user);
user = userRepo.saveAndFlush(user);
return user.getImages();
} else {
throw new AlovoaException("max_image_amount_exceeded");
}
Expand Down

0 comments on commit 7af0cde

Please sign in to comment.