align create methods and improve and align acceptance tests
This commit is contained in:
@ -28,26 +28,26 @@ public class CustomerController implements CustomersApi {
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<CustomerResource>> listCustomers(
|
||||
String userName,
|
||||
String assumedRoles,
|
||||
String prefix
|
||||
String userName,
|
||||
String assumedRoles,
|
||||
String prefix
|
||||
) {
|
||||
context.setCurrentUser(userName);
|
||||
if (assumedRoles != null && !assumedRoles.isBlank()) {
|
||||
context.assumeRoles(assumedRoles);
|
||||
}
|
||||
return ResponseEntity.ok(
|
||||
mapList(
|
||||
customerRepository.findCustomerByOptionalPrefixLike(prefix),
|
||||
CustomerResource.class));
|
||||
|
||||
final var result = customerRepository.findCustomerByOptionalPrefixLike(prefix);
|
||||
|
||||
return ResponseEntity.ok(mapList(result, CustomerResource.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<CustomerResource> addCustomer(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final CustomerResource customer) {
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final CustomerResource customer) {
|
||||
|
||||
context.setCurrentTask("create new customer: #" + customer.getReference() + " / " + customer.getPrefix());
|
||||
context.setCurrentUser(currentUser);
|
||||
@ -61,10 +61,10 @@ public class CustomerController implements CustomersApi {
|
||||
final var saved = customerRepository.save(map(customer, CustomerEntity.class));
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/rbac-users/{id}")
|
||||
.buildAndExpand(customer.getUuid())
|
||||
.toUri();
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/rbac-users/{id}")
|
||||
.buildAndExpand(customer.getUuid())
|
||||
.toUri();
|
||||
return ResponseEntity.created(uri).body(map(saved, CustomerResource.class));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -25,6 +26,9 @@ public class RbacGrantController implements RbacgrantsApi {
|
||||
@Autowired
|
||||
private RbacGrantRepository rbacGrantRepository;
|
||||
|
||||
@Autowired
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<RbacGrantResource> getGrantById(
|
||||
@ -61,7 +65,7 @@ public class RbacGrantController implements RbacgrantsApi {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<Void> grantRoleToUser(
|
||||
public ResponseEntity<RbacGrantResource> grantRoleToUser(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final RbacGrantResource body) {
|
||||
@ -72,14 +76,16 @@ public class RbacGrantController implements RbacgrantsApi {
|
||||
context.assumeRoles(assumedRoles);
|
||||
}
|
||||
|
||||
rbacGrantRepository.save(map(body, RbacGrantEntity.class));
|
||||
final var granted = rbacGrantRepository.save(map(body, RbacGrantEntity.class));
|
||||
em.flush();
|
||||
em.refresh(granted);
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/rbac-grants/{roleUuid}")
|
||||
.buildAndExpand(body.getGrantedRoleUuid())
|
||||
.toUri();
|
||||
return ResponseEntity.created(uri).build();
|
||||
return ResponseEntity.created(uri).body(map(granted, RbacGrantResource.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,5 +106,4 @@ public class RbacGrantController implements RbacgrantsApi {
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public interface RbacGrantRepository extends Repository<RbacGrantEntity, RbacGra
|
||||
|
||||
List<RbacGrantEntity> findAll();
|
||||
|
||||
void save(final RbacGrantEntity grant);
|
||||
RbacGrantEntity save(final RbacGrantEntity grant);
|
||||
|
||||
@Modifying
|
||||
@Query(value = """
|
||||
|
@ -32,6 +32,9 @@ post:
|
||||
"201":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './api-definition/rbac-grant-schemas.yaml#/components/schemas/RbacGrant'
|
||||
"401":
|
||||
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
|
Reference in New Issue
Block a user