| /* |
| ******************************************************************************* |
| * Copyright (c) 2019 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ******************************************************************************* |
| */ |
| package org.eclipse.openk.contactbasedata.controller; |
| |
| import io.swagger.annotations.ApiOperation; |
| import io.swagger.annotations.ApiResponse; |
| import io.swagger.annotations.ApiResponses; |
| import lombok.extern.log4j.Log4j2; |
| import org.eclipse.openk.contactbasedata.model.VwDetailedContact; |
| import org.eclipse.openk.contactbasedata.service.ContactService; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.data.domain.Page; |
| import org.springframework.data.domain.Pageable; |
| import org.springframework.data.web.PageableDefault; |
| import org.springframework.http.HttpStatus; |
| import org.springframework.security.access.annotation.Secured; |
| import org.springframework.web.bind.annotation.*; |
| |
| import java.util.Optional; |
| import java.util.UUID; |
| |
| import static org.springframework.data.domain.Sort.Direction.ASC; |
| |
| @Log4j2 |
| @RestController |
| @RequestMapping("/contacts") |
| public class ContactController { |
| @Autowired |
| private ContactService contactService; |
| |
| @ApiOperation(value = "Anzeigen aller gespeicherter Kontakte") |
| @ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")}) |
| @ResponseStatus(HttpStatus.OK) |
| @Secured({"ROLE_KON-READER", "ROLE_KON-WRITER", "ROLE_KON-ADMIN"}) |
| @GetMapping |
| public Page<VwDetailedContact> findContacts( |
| @RequestParam( "contactType") Optional<String> contactType, |
| @RequestParam( "personTypeId" ) Optional<UUID> personTypeUuid, |
| @RequestParam( "searchText" ) Optional<String> searchText, |
| @RequestParam( "moduleName") Optional<String> moduleName, |
| @RequestParam( "withoutAssignedModule") Optional<Boolean> withoutAssignedModule, |
| @PageableDefault( sort = {"name"}, size = 20, direction = ASC) Pageable pageable ) { |
| return contactService.findDetailedContacts( |
| contactType.orElse(null), |
| personTypeUuid.orElse(null), |
| searchText.orElse( null), |
| moduleName.orElse(null), |
| withoutAssignedModule.orElse(Boolean.FALSE), |
| pageable); |
| } |
| |
| |
| @ApiOperation(value = "Anzeigen aller gespeicherten Kontakte") |
| @ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")}) |
| @ResponseStatus(HttpStatus.OK) |
| @Secured({"ROLE_KON-READER", "ROLE_KON-WRITER", "ROLE_KON-ADMIN"}) |
| @GetMapping(value = "/searchByModulName") |
| public Page<VwDetailedContact> findContacts( |
| @RequestParam( "modulName") Optional<String> modulName, |
| @RequestParam( "searchText" ) Optional<String> searchText, |
| @PageableDefault( sort = {"id"}, size = 20, direction = ASC) Pageable pageable ) { |
| return contactService.findDetailedContactsByModulName( |
| modulName.orElse(null), |
| searchText.orElse(null), |
| pageable); |
| } |
| |
| |
| } |