POST to /api/customers response 200 -> 201

This commit is contained in:
Michael Hoennig 2022-08-13 14:58:19 +02:00
parent 8529ec9949
commit c03697ccd9
3 changed files with 18 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.generated.api.v1.model.CustomerResource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.List; import java.util.List;
@ -47,6 +48,7 @@ public class CustomerController implements CustomersApi {
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final CustomerResource customer) { final CustomerResource customer) {
context.setCurrentUser(currentUser); context.setCurrentUser(currentUser);
if (assumedRoles != null && !assumedRoles.isBlank()) { if (assumedRoles != null && !assumedRoles.isBlank()) {
context.assumeRoles(assumedRoles); context.assumeRoles(assumedRoles);
@ -54,10 +56,15 @@ public class CustomerController implements CustomersApi {
if (customer.getUuid() == null) { if (customer.getUuid() == null) {
customer.setUuid(UUID.randomUUID()); customer.setUuid(UUID.randomUUID());
} }
return ResponseEntity.ok(
map( final var saved = customerRepository.save(map(customer, CustomerEntity.class));
customerRepository.save(map(customer, CustomerEntity.class)),
CustomerResource.class)); final var uri =
MvcUriComponentsBuilder.fromController(getClass())
.path("/api/rbac-users/{id}")
.buildAndExpand(customer.getUuid())
.toUri();
return ResponseEntity.created(uri).body(map(saved, CustomerResource.class));
} }
} }

View File

@ -19,6 +19,9 @@ paths:
/api/rbac-roles: /api/rbac-roles:
$ref: "./api-definition/rbac-roles.yaml" $ref: "./api-definition/rbac-roles.yaml"
/api/rbac-grants:
$ref: "./api-definition/rbac-grants.yaml"
# HS # HS
/api/customers: /api/customers:

View File

@ -42,8 +42,8 @@ post:
$ref: './api-definition/api-definition/hs-customer-schemas.yaml#/components/schemas/Customer' $ref: './api-definition/api-definition/hs-customer-schemas.yaml#/components/schemas/Customer'
required: true required: true
responses: responses:
"200": "201":
description: OK description: Created
content: content:
'application/json': 'application/json':
schema: schema:
@ -52,3 +52,5 @@ post:
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized' $ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
"403": "403":
$ref: './api-definition/error-responses.yaml#/components/responses/Forbidden' $ref: './api-definition/error-responses.yaml#/components/responses/Forbidden'
"409":
$ref: './api-definition/error-responses.yaml#/components/responses/Conflict'