Commit eea1212b authored by Matija Obreza's avatar Matija Obreza

Repository API v1

- Files
- Folders
- Image galleries
parent dd3172b3
......@@ -60,7 +60,6 @@ import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
* @author Matija Obreza
......@@ -224,6 +223,22 @@ public class RepositoryController {
return folderDetails(folder.getFolderPath());
}
/**
* Create or load folder at specified path
*
* @param request the request
* @return the repository folder
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@PutMapping("/folder/**")
@ApiOperation(nickname = "ensureFolder", value = "Create or load folder at specified path")
@JsonView(JsonViews.Protected.class)
public RepositoryFolder ensureFolder(final HttpServletRequest request) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
RepositoryFolder folder = repositoryService.ensureFolder(Paths.get(folderPath));
return folder;
}
/**
* Gets folder details at specified path.
*
......@@ -234,7 +249,7 @@ public class RepositoryController {
@GetMapping("/folder/**")
@ApiOperation(nickname = "getFolder", value = "Get folder details by folder path")
@JsonView(JsonViews.Protected.class)
public FolderDetails getFolder(@ApiParam(name = "path", type = "java.lang.String") final HttpServletRequest request) throws InvalidRepositoryPathException {
public FolderDetails getFolder(final HttpServletRequest request) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return folderDetails(Paths.get(folderPath));
}
......@@ -250,8 +265,7 @@ public class RepositoryController {
@DeleteMapping("/folder/**")
@ApiOperation(nickname = "deleteFolder", value = "Delete folder")
@JsonView(JsonViews.Protected.class)
public RepositoryFolder deleteFolder(@ApiParam(name = "path", type = "java.lang.String") final HttpServletRequest request) throws InvalidRepositoryPathException,
FolderNotEmptyException {
public RepositoryFolder deleteFolder(final HttpServletRequest request) throws InvalidRepositoryPathException, FolderNotEmptyException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
RepositoryFolder folder = repositoryService.getFolder(Paths.get(folderPath));
repositoryService.deleteFolder(Paths.get(folderPath));
......@@ -288,7 +302,9 @@ public class RepositoryController {
@JsonView(JsonViews.Root.class)
public ImageGallery getGallery(final HttpServletRequest request) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/gallery").length());
return imagegalleryService.loadImageGallery(Paths.get(folderPath));
ImageGallery imageGallery = imagegalleryService.loadImageGallery(Paths.get(folderPath));
imagegalleryService.ensureThumbnails(imageGallery, 200, 200);
return imageGallery;
}
/**
......@@ -301,9 +317,11 @@ public class RepositoryController {
*/
@PostMapping("/gallery/**")
@JsonView(JsonViews.Root.class)
public ImageGallery createGallery(final HttpServletRequest request, @RequestBody ImageGallery imageGallery) throws InvalidRepositoryPathException {
public ImageGallery createGallery(final HttpServletRequest request, @RequestBody ImageGallery metadata) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/gallery").length());
return imagegalleryService.createImageGallery(Paths.get(folderPath), imageGallery.getTitle(), imageGallery.getDescription());
ImageGallery imageGallery = imagegalleryService.createImageGallery(Paths.get(folderPath), metadata.getTitle(), metadata.getDescription());
imagegalleryService.ensureThumbnails(imageGallery, 200, 200);
return imageGallery;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment