for customer findAll()->findCustomerByOptionalPrefix(...)
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -111,11 +111,18 @@ declare
|
||||
objectUuid uuid;
|
||||
begin
|
||||
if TG_OP = 'INSERT' then
|
||||
insert
|
||||
into RbacObject (objectTable)
|
||||
values (TG_TABLE_NAME)
|
||||
returning uuid into objectUuid;
|
||||
NEW.uuid = objectUuid;
|
||||
if NEW.uuid is null then
|
||||
insert
|
||||
into RbacObject (objectTable)
|
||||
values (TG_TABLE_NAME)
|
||||
returning uuid into objectUuid;
|
||||
NEW.uuid = objectUuid;
|
||||
else
|
||||
insert
|
||||
into RbacObject (uuid, objectTable)
|
||||
values (NEW.uuid, TG_TABLE_NAME)
|
||||
returning uuid into objectUuid;
|
||||
end if;
|
||||
return NEW;
|
||||
else
|
||||
raise exception 'invalid usage of TRIGGER AFTER INSERT';
|
||||
@ -138,7 +145,8 @@ create table RbacRole
|
||||
(
|
||||
uuid uuid primary key references RbacReference (uuid) on delete cascade,
|
||||
objectUuid uuid references RbacObject (uuid) not null,
|
||||
roleType RbacRoleType not null
|
||||
roleType RbacRoleType not null,
|
||||
unique (objectUuid, roleType)
|
||||
);
|
||||
|
||||
create type RbacRoleDescriptor as
|
||||
@ -753,7 +761,7 @@ grant all privileges on all tables in schema public to restricted;
|
||||
*/
|
||||
drop view if exists rbacrole_rv;
|
||||
create or replace view rbacrole_rv as
|
||||
select r.*, o.objectTable,
|
||||
select DISTINCT r.*, o.objectTable,
|
||||
findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName
|
||||
from rbacrole as r
|
||||
join rbacobject as o on o.uuid=r.objectuuid
|
||||
|
Reference in New Issue
Block a user