RepositoryGalleryController.java
/*
* Copyright 2025 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.server.api.v2.impl.admin;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.server.api.ApiBaseController;
import org.genesys.server.api.v2.facade.ImageGalleryApiService;
import org.genesys.server.api.v2.model.impl.ImageGalleryDTO;
import org.genesys.server.mvc.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController("adminRepositoryGalleryControllerV2")
@RequestMapping(RepositoryGalleryController.CONTROLLER_URL)
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class RepositoryGalleryController extends BaseController {
/** The Constant CONTROLLER_URL. */
public static final String CONTROLLER_URL = ApiBaseController.APIv2_BASE + "/admin/r/g";
public static final Logger LOG = LoggerFactory.getLogger(RepositoryGalleryController.class);
@Autowired
private ImageGalleryApiService imageGalleryService;
@GetMapping(value = "/{page:\\d+}")
public Page<ImageGalleryDTO> listAllFiles(@PathVariable("page") int page) {
return imageGalleryService.listImageGalleries(PageRequest.of(page - 1, 50, Sort.by("path")));
}
@PutMapping(value = "")
public void updateMetadata(@RequestParam String galleryPath, @RequestBody ImageGalleryDTO imageGallery) throws Exception {
imageGalleryService.updateMetadata(galleryPath, imageGallery);
}
@DeleteMapping(value = "")
public void deleteFile(@RequestParam String galleryPath) throws InvalidRepositoryPathException {
imageGalleryService.deleteFile(galleryPath);
}
}