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(path = "geo-services", collectionResourceRel = "geo-services", itemResourceRel = "geo-service")
21  public interface GeoServiceRepository extends JpaRepository<GeoService, String> {
22    @Override
23    @NonNull @PreAuthorize("permitAll()")
24    Optional<GeoService> findById(@NonNull String id);
25  
26    /**
27     * Find multiple geo-services. Example URL:
28     * /api/admin/geo-services/search/findByIds?ids=openbasiskaart&amp;ids=at-basemap
29     *
30     * @param ids The ids to search for
31     * @return The geo services matching the ids
32     */
33    @NonNull @PreAuthorize("permitAll()")
34    @Query("from GeoService s where id in :ids")
35    List<GeoService> findByIds(@Param("ids") List<String> ids);
36  
37    /**
38     * Find multiple geo-services except some. Example URL:
39     * /api/admin/geo-services/search/getAllExcludingIds?ids=openbasiskaart&amp;ids=at-basemap
40     *
41     * <p>No geo services are returned if ids is an empty list.
42     *
43     * @param ids The ids not to include
44     * @return All geo services except those matching the ids
45     */
46    @NonNull @PreAuthorize("permitAll()")
47    @Query("from GeoService s where id not in :ids")
48    List<GeoService> getAllExcludingIds(@Param("ids") List<String> ids);
49  }