1
0

for customer findAll()->findCustomerByOptionalPrefix(...)

This commit is contained in:
Michael Hoennig
2022-08-04 09:09:06 +02:00
parent 8fb92f9978
commit 57cf316c00
6 changed files with 104 additions and 37 deletions

View File

@ -22,13 +22,14 @@ public class CustomerController {
@Transactional
public List<CustomerEntity> listCustomers(
@RequestHeader(value = "current-user") String userName,
@RequestHeader(value = "assumed-roles", required = false) String assumedRoles
@RequestHeader(value = "assumed-roles", required = false) String assumedRoles,
@RequestParam(required = false) String prefix
) {
context.setCurrentUser(userName);
if (assumedRoles != null && !assumedRoles.isBlank()) {
context.assumeRoles(assumedRoles);
}
return customerRepository.findAll();
return customerRepository.findCustomerByOptionalPrefix(prefix);
}
@PostMapping(value = "/api/customers")
@ -48,5 +49,4 @@ public class CustomerController {
}
return customerRepository.save(customer);
}
}

View File

@ -1,11 +1,21 @@
package net.hostsharing.hsadminng.hs.hscustomer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface CustomerRepository extends JpaRepository<CustomerEntity, UUID> {
public interface CustomerRepository extends Repository<CustomerEntity, UUID> {
Optional<CustomerEntity> findByUuid(UUID id);
@Query("SELECT c FROM CustomerEntity c WHERE :prefix is null or c.prefix like concat(:prefix, '%')")
List<CustomerEntity> findCustomerByOptionalPrefix(@Param("prefix") String prefix);
CustomerEntity save(final CustomerEntity entity);
List<CustomerEntity> findByPrefixLike(final String prefix);
}