Skip to content
Snippets Groups Projects
Commit ca696517 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#510 - added new route to retrieve image by icon ID

parent 083b62b0
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,12 @@ package de.deadlocker8.budgetmaster.images;
import com.google.gson.JsonObject;
import de.deadlocker8.budgetmaster.controller.BaseController;
import de.deadlocker8.budgetmaster.icon.Icon;
import de.deadlocker8.budgetmaster.icon.IconService;
import de.deadlocker8.budgetmaster.utils.Mappings;
import de.deadlocker8.budgetmaster.utils.ResourceNotFoundException;
import de.thecodelabs.utils.util.Localization;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -17,11 +21,13 @@ import java.util.Optional;
@RequestMapping(Mappings.MEDIA)
public class MediaController extends BaseController
{
private final IconService iconService;
private final ImageService imageService;
@Autowired
public MediaController(ImageService imageService)
public MediaController(IconService iconService, ImageService imageService)
{
this.iconService = iconService;
this.imageService = imageService;
}
......@@ -98,4 +104,17 @@ public class MediaController extends BaseController
return data.toString();
}
@GetMapping("/getImage/{ID}")
@ResponseBody
public byte[] getImage(@PathVariable("ID") Integer iconID)
{
Optional<Icon> iconOptional = iconService.getRepository().findById(iconID);
if(iconOptional.isEmpty())
{
throw new ResourceNotFoundException();
}
return ArrayUtils.toPrimitive(iconOptional.get().getImage().getImage());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment