image/farmimage controller efix
This commit is contained in:
@@ -55,17 +55,17 @@ public class FarmImageController {
|
||||
@RequestMapping(path = FARM_IMAGE_BASE, method = RequestMethod.POST, produces = "application/json")
|
||||
public ResponseEntity<Boolean> add(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_UUID) UUID articleUuid,
|
||||
@RequestParam(value = PARAM_IMAGE) MultipartFile file,
|
||||
@RequestParam(value = PARAM_STANDARD) boolean standard) {
|
||||
@RequestParam(value = PARAM_STANDARD) boolean standard,
|
||||
@RequestBody String base64) {
|
||||
logRequest(request);
|
||||
|
||||
if (articleUuid == null || articleService.findByUUID(articleUuid) == null
|
||||
|| file == null || file.isEmpty()) {
|
||||
|| base64 == null || base64.isEmpty()) {
|
||||
log.warn("[{}] failed Validation, sending bad request", request.getRequestURI());
|
||||
return ResponseEntity.badRequest().body(false);
|
||||
}
|
||||
|
||||
FarmImage a = farmImageService.save(articleUuid, file, standard);
|
||||
FarmImage a = farmImageService.save(articleUuid, base64, standard);
|
||||
return ResponseEntity.ok(a != null);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ImageController {
|
||||
@RequestMapping(path = IMAGE_BASE, method = RequestMethod.POST, produces = "application/json")
|
||||
public ResponseEntity<Boolean> add(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_UUID) UUID articleUuid,
|
||||
@RequestParam(value = PARAM_IMAGE) String base64) {
|
||||
@RequestBody String base64) {
|
||||
logRequest(request);
|
||||
|
||||
if (articleUuid == null || articleService.findByUUID(articleUuid) == null
|
||||
@@ -72,26 +72,6 @@ public class ImageController {
|
||||
return ResponseEntity.ok(imageService.save(articleUuid, base64) != null);
|
||||
}
|
||||
|
||||
@RequestMapping(path = IMAGE_ALL, method = RequestMethod.POST, produces = "application/json")
|
||||
public ResponseEntity<Integer> addAll(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_UUID) UUID articleUuid,
|
||||
@RequestParam(value = PARAM_IMAGE) List<String> base64list) {
|
||||
logRequest(request);
|
||||
|
||||
if (articleUuid == null || articleService.findByUUID(articleUuid) == null
|
||||
|| base64list == null || base64list.isEmpty()) {
|
||||
log.warn("[{}] failed Validation, sending bad request", request.getRequestURI());
|
||||
return ResponseEntity.badRequest().body(0);
|
||||
}
|
||||
int[] successful = {0};
|
||||
base64list.forEach(b64 -> {
|
||||
if (imageService.save(articleUuid, b64) != null) {
|
||||
successful[0]++;
|
||||
}
|
||||
});
|
||||
return ResponseEntity.ok(successful[0]);
|
||||
}
|
||||
|
||||
@RequestMapping(path = IMAGE_BASE, method = RequestMethod.PUT, produces = "application/json")
|
||||
public ResponseEntity<Boolean> update(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_ID) Long imageId,
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface FarmImageService {
|
||||
|
||||
FarmImage save(FarmImageModel model);
|
||||
|
||||
FarmImage save(UUID uuid, MultipartFile file, boolean standard);
|
||||
FarmImage save(UUID uuid, String base64, boolean standard);
|
||||
|
||||
void deleteById(Long imageId);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class FarmImageServiceImpl implements FarmImageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FarmImage save(UUID uuid, MultipartFile file, boolean standard) {
|
||||
public FarmImage save(UUID uuid, String base64, boolean standard) {
|
||||
if (uuid == null) {
|
||||
log.warn("Got no UUID, aborting");
|
||||
return null;
|
||||
@@ -65,22 +65,12 @@ public class FarmImageServiceImpl implements FarmImageService {
|
||||
log.warn("Could not find article with id {}", uuid);
|
||||
return null;
|
||||
}
|
||||
if (file == null) {
|
||||
if (base64 == null || base64.isEmpty()) {
|
||||
log.warn("Got no file for {}", uuid);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
String based64 = Base64.getEncoder().encodeToString(file.getBytes());
|
||||
if (based64 == null || based64.isEmpty()) {
|
||||
log.warn("Could not save image with id {} and file size {}", uuid, file.getSize());
|
||||
return null;
|
||||
}
|
||||
return farmImageRepository.save(new FarmImage(null, article, based64, standard));
|
||||
} catch (Exception e) {
|
||||
log.warn("Error saving image {} for article {}", file, uuid, e);
|
||||
}
|
||||
return null;
|
||||
return farmImageRepository.save(new FarmImage(null, article, base64, standard));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user