Commit 74137cdb authored by Holger Rudolph's avatar Holger Rudolph
Browse files

[SI-382] new get service for stations by id and name


Signed-off-by: Holger Rudolph's avatarHolger Rudolph <holger.rudolph@pta.de>
parent 8e95fe15
......@@ -19,15 +19,11 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.AddressService;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Log4j2
@RestController
......
/*
*******************************************************************************
* 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.gridfailureinformation.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.gridfailureinformation.service.StationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.StationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Log4j2
@RestController
@RequestMapping("/stations")
public class StationController {
@Autowired
private StationService stationService;
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige Stationen nach Stationsnummer und Stationsname")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping
public List<StationDto> findStations(
@RequestParam ("stationid") String stationid,
@RequestParam ("stationname") String stationname
) {
return stationService.getStationsByIdAndName(stationid, stationname);
}
}
......@@ -17,6 +17,8 @@ package org.eclipse.openk.gridfailureinformation.repository;
import org.eclipse.openk.gridfailureinformation.model.TblStation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -30,5 +32,7 @@ public interface StationRepository extends JpaRepository<TblStation, Long > {
Optional<TblStation> findByUuid(UUID uuid);
@Query("select s from TblStation s where s.stationId = :stationid and s.stationName = :stationname")
List<TblStation> findStationsByIdAndName(@Param("stationid") String stationid, @Param("stationname") String stationname);
}
......@@ -11,7 +11,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
*/
package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.mapper.StationMapper;
......@@ -34,10 +34,15 @@ public class StationService {
public List<StationDto> getStations() {
return stationRepository.findAll().stream()
.map( stationMapper::toStationDto )
.map(stationMapper::toStationDto)
.collect(Collectors.toList());
}
public List<StationDto> getStationsByIdAndName(String stationId, String stationName) {
return stationRepository.findStationsByIdAndName(stationId, stationName).stream()
.map(stationMapper::toStationDto)
.collect(Collectors.toList());
}
}
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