migrate hs-api to test-api
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package net.hostsharing.hsadminng.test.cust;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.api.CustomersApi;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.CustomerResource;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.api.TestCustomersApi;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.TestCustomerResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -17,7 +17,7 @@ import static net.hostsharing.hsadminng.Mapper.mapList;
|
||||
|
||||
@RestController
|
||||
|
||||
public class TestCustomerController implements CustomersApi {
|
||||
public class TestCustomerController implements TestCustomersApi {
|
||||
|
||||
@Autowired
|
||||
private Context context;
|
||||
@@ -27,7 +27,7 @@ public class TestCustomerController implements CustomersApi {
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<CustomerResource>> listCustomers(
|
||||
public ResponseEntity<List<TestCustomerResource>> listCustomers(
|
||||
String currentUser,
|
||||
String assumedRoles,
|
||||
String prefix
|
||||
@@ -36,15 +36,15 @@ public class TestCustomerController implements CustomersApi {
|
||||
|
||||
final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix);
|
||||
|
||||
return ResponseEntity.ok(mapList(result, CustomerResource.class));
|
||||
return ResponseEntity.ok(mapList(result, TestCustomerResource.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<CustomerResource> addCustomer(
|
||||
public ResponseEntity<TestCustomerResource> addCustomer(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final CustomerResource customer) {
|
||||
final TestCustomerResource customer) {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
@@ -56,10 +56,10 @@ public class TestCustomerController implements CustomersApi {
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/customers/{id}")
|
||||
.path("/api/test-customers/{id}")
|
||||
.buildAndExpand(customer.getUuid())
|
||||
.toUri();
|
||||
return ResponseEntity.created(uri).body(map(saved, CustomerResource.class));
|
||||
return ResponseEntity.created(uri).body(map(saved, TestCustomerResource.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,17 +0,0 @@
|
||||
package net.hostsharing.hsadminng.test.pac;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PackageRepository extends Repository<PackageEntity, UUID> {
|
||||
|
||||
@Query("SELECT p FROM PackageEntity p WHERE :name is null or p.name like concat(:name, '%')")
|
||||
List<PackageEntity> findAllByOptionalNameLike(final String name);
|
||||
|
||||
PackageEntity findByUuid(UUID packageUuid);
|
||||
|
||||
PackageEntity save(PackageEntity current);
|
||||
}
|
@@ -2,9 +2,9 @@ package net.hostsharing.hsadminng.test.pac;
|
||||
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.api.PackagesApi;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.PackageResource;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.PackageUpdateResource;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.api.TestPackagesApi;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.TestPackageResource;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.TestPackageUpdateResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -17,41 +17,41 @@ import static net.hostsharing.hsadminng.Mapper.map;
|
||||
import static net.hostsharing.hsadminng.Mapper.mapList;
|
||||
|
||||
@RestController
|
||||
public class PackageController implements PackagesApi {
|
||||
public class TestPackageController implements TestPackagesApi {
|
||||
|
||||
@Autowired
|
||||
private Context context;
|
||||
|
||||
@Autowired
|
||||
private PackageRepository packageRepository;
|
||||
private TestPackageRepository testPackageRepository;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<PackageResource>> listPackages(
|
||||
public ResponseEntity<List<TestPackageResource>> listPackages(
|
||||
String currentUser,
|
||||
String assumedRoles,
|
||||
String name
|
||||
) {
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var result = packageRepository.findAllByOptionalNameLike(name);
|
||||
return ResponseEntity.ok(mapList(result, PackageResource.class));
|
||||
final var result = testPackageRepository.findAllByOptionalNameLike(name);
|
||||
return ResponseEntity.ok(mapList(result, TestPackageResource.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<PackageResource> updatePackage(
|
||||
public ResponseEntity<TestPackageResource> updatePackage(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID packageUuid,
|
||||
final PackageUpdateResource body) {
|
||||
final TestPackageUpdateResource body) {
|
||||
|
||||
context.define(currentUser, assumedRoles);
|
||||
|
||||
final var current = packageRepository.findByUuid(packageUuid);
|
||||
final var current = testPackageRepository.findByUuid(packageUuid);
|
||||
OptionalFromJson.of(body.getDescription()).ifPresent(current::setDescription);
|
||||
final var saved = packageRepository.save(current);
|
||||
final var mapped = map(saved, PackageResource.class);
|
||||
final var saved = testPackageRepository.save(current);
|
||||
final var mapped = map(saved, TestPackageResource.class);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PackageEntity {
|
||||
public class TestPackageEntity {
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
@@ -0,0 +1,17 @@
|
||||
package net.hostsharing.hsadminng.test.pac;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TestPackageRepository extends Repository<TestPackageEntity, UUID> {
|
||||
|
||||
@Query("SELECT p FROM TestPackageEntity p WHERE :name is null or p.name like concat(:name, '%')")
|
||||
List<TestPackageEntity> findAllByOptionalNameLike(final String name);
|
||||
|
||||
TestPackageEntity findByUuid(UUID packageUuid);
|
||||
|
||||
TestPackageEntity save(TestPackageEntity current);
|
||||
}
|
@@ -30,14 +30,14 @@ paths:
|
||||
|
||||
# HS
|
||||
|
||||
/api/customers:
|
||||
$ref: "./api-definition/hs-customers.yaml"
|
||||
/api/test-customers:
|
||||
$ref: "./api-definition/test-customers.yaml"
|
||||
|
||||
/api/packages:
|
||||
$ref: "./api-definition/hs-packages.yaml"
|
||||
/api/test-packages:
|
||||
$ref: "./api-definition/test-packages.yaml"
|
||||
|
||||
/api/packages/{packageUUID}:
|
||||
$ref: "./api-definition/hs-packages-uuid.yaml"
|
||||
/api/test-packages/{packageUUID}:
|
||||
$ref: "./api-definition/test-packages-uuid.yaml"
|
||||
|
||||
# Other
|
||||
|
||||
|
@@ -3,7 +3,7 @@ components:
|
||||
|
||||
schemas:
|
||||
|
||||
Customer:
|
||||
TestCustomer:
|
||||
type: object
|
||||
properties:
|
||||
uuid:
|
@@ -2,7 +2,7 @@ get:
|
||||
summary: Returns a list of (optionally filtered) customers.
|
||||
description: Returns the list of (optionally filtered) customers which are visible to the current user or any of it's assumed roles.
|
||||
tags:
|
||||
- customers
|
||||
- testCustomers
|
||||
operationId: listCustomers
|
||||
parameters:
|
||||
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
|
||||
@@ -21,7 +21,7 @@ get:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer'
|
||||
$ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
|
||||
"401":
|
||||
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
@@ -30,7 +30,7 @@ get:
|
||||
post:
|
||||
summary: Adds a new customer.
|
||||
tags:
|
||||
- customers
|
||||
- testCustomers
|
||||
operationId: addCustomer
|
||||
parameters:
|
||||
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
|
||||
@@ -39,7 +39,7 @@ post:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './api-definition/api-definition/hs-customer-schemas.yaml#/components/schemas/Customer'
|
||||
$ref: './api-definition/api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
|
||||
required: true
|
||||
responses:
|
||||
"201":
|
||||
@@ -47,7 +47,7 @@ post:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer'
|
||||
$ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
|
||||
"401":
|
||||
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
@@ -3,20 +3,20 @@ components:
|
||||
|
||||
schemas:
|
||||
|
||||
Package:
|
||||
TestPackage:
|
||||
type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
customer:
|
||||
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer'
|
||||
$ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
maxLength: 80
|
||||
PackageUpdate:
|
||||
TestPackageUpdate:
|
||||
type: object
|
||||
properties:
|
||||
description:
|
@@ -1,6 +1,6 @@
|
||||
patch:
|
||||
tags:
|
||||
- packages
|
||||
- testPackages
|
||||
operationId: updatePackage
|
||||
parameters:
|
||||
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
|
||||
@@ -15,14 +15,14 @@ patch:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/PackageUpdate'
|
||||
$ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackageUpdate'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/Package'
|
||||
$ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackage'
|
||||
"401":
|
||||
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
@@ -1,6 +1,6 @@
|
||||
get:
|
||||
tags:
|
||||
- packages
|
||||
- testPackages
|
||||
operationId: listPackages
|
||||
parameters:
|
||||
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
|
||||
@@ -18,7 +18,7 @@ get:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/Package'
|
||||
$ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackage'
|
||||
"401":
|
||||
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
@@ -7,11 +7,10 @@ options:
|
||||
map:
|
||||
result: org.springframework.http.ResponseEntity
|
||||
|
||||
|
||||
types:
|
||||
- type: array => java.util.List
|
||||
- type: string:uuid => java.util.UUID
|
||||
|
||||
paths:
|
||||
/api/packages/{packageUUID}:
|
||||
/api/test-packages/{packageUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
|
Reference in New Issue
Block a user