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.history.RevisionRepository;
13  import org.springframework.data.repository.query.Param;
14  import org.springframework.data.rest.core.annotation.RepositoryRestResource;
15  import org.springframework.lang.NonNull;
16  import org.springframework.security.access.prepost.PreAuthorize;
17  import org.tailormap.api.persistence.GeoService;
18  import org.tailormap.api.security.annotation.PreAuthorizeAdmin;
19  
20  @PreAuthorizeAdmin
21  @RepositoryRestResource(path = "geo-services", collectionResourceRel = "geo-services", itemResourceRel = "geo-service")
22  public interface GeoServiceRepository
23      extends JpaRepository<GeoService, String>, RevisionRepository<GeoService, String, Long> {
24    @Override
25    @NonNull @PreAuthorize("permitAll()")
26    Optional<GeoService> findById(@NonNull String id);
27  
28    /**
29     * Find multiple geo-services. Example URL:
30     * /api/admin/geo-services/search/findByIds?ids=openbasiskaart&amp;ids=at-basemap
31     *
32     * @param ids The ids to search for
33     * @return The geo services matching the ids
34     */
35    @NonNull @PreAuthorize("permitAll()")
36    @Query("from GeoService s where id in :ids")
37    List<GeoService> findByIds(@Param("ids") List<String> ids);
38  
39    /**
40     * Find multiple geo-services except some. Example URL:
41     * /api/admin/geo-services/search/getAllExcludingIds?ids=openbasiskaart&amp;ids=at-basemap
42     *
43     * <p>No geo services are returned if ids is an empty list.
44     *
45     * @param ids The ids not to include
46     * @return All geo services except those matching the ids
47     */
48    @NonNull @PreAuthorize("permitAll()")
49    @Query("from GeoService s where id not in :ids")
50    List<GeoService> getAllExcludingIds(@Param("ids") List<String> ids);
51  }