View Javadoc
1   /*
2    * Copyright (C) 2023 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
5    */
6   package org.tailormap.api.repository;
7   
8   import java.util.List;
9   import java.util.Optional;
10  import org.springframework.data.jpa.repository.JpaRepository;
11  import org.springframework.data.jpa.repository.Query;
12  import org.springframework.data.repository.query.Param;
13  import org.springframework.data.rest.core.annotation.RepositoryRestResource;
14  import org.springframework.lang.NonNull;
15  import org.springframework.security.access.prepost.PreAuthorize;
16  import org.tailormap.api.persistence.GeoService;
17  import org.tailormap.api.security.annotation.PreAuthorizeAdmin;
18  
19  @PreAuthorizeAdmin
20  @RepositoryRestResource(
21      path = "geo-services",
22      collectionResourceRel = "geo-services",
23      itemResourceRel = "geo-service")
24  public interface GeoServiceRepository extends JpaRepository<GeoService, String> {
25    @Override
26    @NonNull
27    @PreAuthorize("permitAll()")
28    Optional<GeoService> findById(@NonNull String id);
29  
30    /**
31     * Find multiple geo-services. Example URL:
32     * /api/admin/geo-services/search/findByIds?ids=openbasiskaart&amp;ids=at-basemap
33     *
34     * @param ids The ids to search for
35     * @return The geo services matching the ids
36     */
37    @NonNull
38    @PreAuthorize("permitAll()")
39    @Query("from GeoService s where id in :ids")
40    List<GeoService> findByIds(@Param("ids") List<String> ids);
41  
42    /**
43     * Find multiple geo-services except some. Example URL:
44     * /api/admin/geo-services/search/getAllExcludingIds?ids=openbasiskaart&amp;ids=at-basemap
45     *
46     * <p>No geo services are returned if ids is an empty list.
47     *
48     * @param ids The ids not to include
49     * @return All geo services except those matching the ids
50     */
51    @NonNull
52    @PreAuthorize("permitAll()")
53    @Query("from GeoService s where id not in :ids")
54    List<GeoService> getAllExcludingIds(@Param("ids") List<String> ids);
55  }