add updatePackage (description) using JsonNullableModule and HTTP-to-DB test with RestAssured
This commit is contained in:
@ -9,5 +9,4 @@ public class HsadminNgApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HsadminNgApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
@Configuration
|
||||
public class JsonObjectMapperConfiguration {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public Jackson2ObjectMapperBuilder customObjectMapper() {
|
||||
return new Jackson2ObjectMapperBuilder()
|
||||
.modules(new JsonNullableModule());
|
||||
}
|
||||
}
|
@ -3,13 +3,16 @@ package net.hostsharing.hsadminng.hs.hspackage;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.Mapper.map;
|
||||
import static net.hostsharing.hsadminng.Mapper.mapList;
|
||||
|
||||
@RestController
|
||||
@ -36,4 +39,27 @@ public class PackageController implements PackagesApi {
|
||||
return ResponseEntity.ok(mapList(result, PackageResource.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<PackageResource> updatePackage(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID packageUuid,
|
||||
final PackageUpdateResource body) {
|
||||
|
||||
context.setCurrentUser(currentUser);
|
||||
if (assumedRoles != null && !assumedRoles.isBlank()) {
|
||||
context.assumeRoles(assumedRoles);
|
||||
}
|
||||
final var current = packageRepository.findByUuid(packageUuid);
|
||||
if (body.getDescription() != null) {
|
||||
body.getDescription().ifPresent(current::setDescription);
|
||||
} else {
|
||||
body.toString();
|
||||
}
|
||||
final var saved = packageRepository.save(current);
|
||||
final var mapped = map(saved, PackageResource.class);
|
||||
return ResponseEntity.ok(mapped);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.hspackage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
@ -11,15 +12,18 @@ import java.util.UUID;
|
||||
@Entity
|
||||
@Table(name = "package_rv")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PackageEntity {
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "customeruuid")
|
||||
private CustomerEntity customer;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
}
|
||||
|
@ -10,4 +10,8 @@ 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);
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
package net.hostsharing.hsadminng.rbac.rbacuser;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.api.RbacusersApi;
|
||||
import net.hostsharing.hsadminng.generated.api.v1.model.RbacUserPermissionResource;
|
||||
|
@ -182,6 +182,40 @@ paths:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Package'
|
||||
"401":
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: '#/components/responses/Forbidden'
|
||||
/api/packages/{packageUUID}:
|
||||
patch:
|
||||
tags:
|
||||
- packages
|
||||
operationId: updatePackage
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/currentUser'
|
||||
- $ref: '#/components/parameters/assumedRoles'
|
||||
- name: packageUUID
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
requestBody:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/PackageUpdate'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: '#/components/schemas/Package'
|
||||
"401":
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: '#/components/responses/Forbidden'
|
||||
|
||||
components:
|
||||
|
||||
@ -290,10 +324,20 @@ components:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
name:
|
||||
type: string
|
||||
customer:
|
||||
$ref: '#/components/schemas/Customer'
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
maxLength: 80
|
||||
PackageUpdate:
|
||||
type: object
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
maxLength: 80
|
||||
nullable: true
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
|
@ -12,3 +12,6 @@ map:
|
||||
- type: array => java.util.List
|
||||
- type: string:uuid => java.util.UUID
|
||||
|
||||
paths:
|
||||
/api/packages/{packageUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
||||
|
@ -188,6 +188,7 @@ drop view if exists package_rv;
|
||||
create or replace view package_rv as
|
||||
select target.*
|
||||
from package as target
|
||||
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'package', currentSubjectIds()));
|
||||
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'package', currentSubjectIds()))
|
||||
order by target.name;
|
||||
grant all privileges on package_rv to restricted;
|
||||
--//
|
||||
|
@ -37,8 +37,8 @@ create or replace procedure createPackageTestData(
|
||||
set local hsadminng.currentTask to currentTask;
|
||||
|
||||
insert
|
||||
into package (name, customerUuid)
|
||||
values (pacName, cust.uuid)
|
||||
into package (customerUuid, name, description)
|
||||
values (cust.uuid, pacName, 'Here can add your own description of package ' || pacName || '.')
|
||||
returning * into pac;
|
||||
|
||||
call grantRoleToUser(
|
||||
|
@ -7,7 +7,8 @@
|
||||
create table if not exists package
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid),
|
||||
name character varying(5),
|
||||
customerUuid uuid references customer (uuid)
|
||||
customerUuid uuid references customer (uuid),
|
||||
name varchar(5),
|
||||
description varchar(80)
|
||||
);
|
||||
--//
|
||||
|
Reference in New Issue
Block a user