Skip to content

Commit

Permalink
feat: update operator rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jan 5, 2024
1 parent d5f9da3 commit ea101c2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class OperatorRestController implements PermissionOperatorApi {
public Response createOrUpdatePermission(String appId, PermissionRequestDTOV1 permissionRequestDTOV1) {

var data = mapper.map(permissionRequestDTOV1, appId);
if (data.isEmpty()) {
return Response.ok().build();
}
var permissions = dao.loadByAppId(appId);
var map = permissions.stream().collect(Collectors.toMap(x -> x.getObject() + x.getAction(), x -> x));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default List<Permission> map(PermissionRequestDTOV1 dto, String appId) {

default List<Permission> map(List<PermissionDTOV1> list, String appId) {
if (list == null) {
return null;
return List.of();
}
List<Permission> data = new ArrayList<>();
for (PermissionDTOV1 dto : list) {
Expand Down
1 change: 0 additions & 1 deletion src/main/openapi/onecx-permission-operator-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ components:
properties:
permissions:
type: array
minItems: 1
items:
$ref: '#/components/schemas/Permission'
Permission:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@QuarkusTest
@TestHTTPEndpoint(OperatorRestController.class)
@WithDBData(value = "data/test-operator-v1.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
public class OperatorRestControllerTest extends AbstractTest {
class OperatorRestControllerTest extends AbstractTest {

@Test
void requestNoBodyTest() {
Expand All @@ -46,21 +46,14 @@ void requestEmptyListTest() {
var request = new PermissionRequestDTOV1();
request.setPermissions(List.of());

var exception = given()
given()
.contentType(APPLICATION_JSON)
.body(request)
.pathParam("appId", "app1")
.put()
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.contentType(APPLICATION_JSON)
.extract()
.as(ProblemDetailResponseDTOV1.class);
.statusCode(OK.getStatusCode());

assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(ExceptionMapper.ErrorKeys.CONSTRAINT_VIOLATIONS.name());
assertThat(exception.getDetail()).isEqualTo(
"createOrUpdatePermission.permissionRequestDTOV1.permissions: size must be between 1 and 2147483647");
}

@Test
Expand Down

0 comments on commit ea101c2

Please sign in to comment.