@RestController
@RequiredArgsConstructor
@DataRouteByExample(Product.class) // We are in the catalog service, so we need to use the Catalog route
public class MyEntityEndpoint implements ProjectionReferencedApi<Projection<MyCompanyEntity>> {
private final RsqlCrudEntityService<Projection<MyCompanyEntity>> service;
@GetMapping("/my-entity")
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public Page<Projection<MyCompanyEntity>> readAll(HttpServletRequest request,
@ContextOperation ContextInfo context,
@PageableDefault(size = 50) Pageable page,
Node filters) {
return service.readAll(filters, page, context);
}
@PostMapping(value = "/my-entity", consumes = MediaType.APPLICATION_JSON_VALUE)
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public Projection<MyCompanyEntity> create(HttpServletRequest request,
@ContextOperation(OperationType.CREATE) ContextInfo context,
@RequestBody Projection<MyCompanyEntity> req) {
return service.create(req, context);
}
@GetMapping("/my-entity/{id}")
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public Projection<MyCompanyEntity> readById(HttpServletRequest request,
@ContextOperation ContextInfo context,
@PathVariable("id") String id) {
return service.readByContextId(id, context);
}
@PatchMapping(value = "/my-entity/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public Projection<MyCompanyEntity> update(HttpServletRequest request,
@ContextOperation(OperationType.UPDATE) ContextInfo context,
@PathVariable("id") String id,
@JsonView(RequestView.class) @RequestBody Projection<MyCompanyEntity> req) {
return service.update(id, req, context);
}
@PutMapping(value = "/my-entity/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public Projection<MyCompanyEntity> replace(HttpServletRequest request,
@ContextOperation(OperationType.UPDATE) ContextInfo context,
@PathVariable("id") String id,
@RequestBody Projection<MyCompanyEntity> req) {
return service.replace(id, req, context);
}
@DeleteMapping("/my-entity/{id}")
@Policy(permissionRoots = {"MY_ENTITY"})
@Override
public void delete(HttpServletRequest request,
@ContextOperation(OperationType.DELETE) ContextInfo context,
@PathVariable("id") String id) {
service.delete(id, context);
}
}