Class AbstractCrudController<T,U,R,F,Q extends SearchRequest<T>,ID>
java.lang.Object
nl.datasteel.crudcraft.runtime.controller.AbstractCrudController<T,U,R,F,Q,ID>
- Type Parameters:
T
- the JPA entity typeU
- the upsert/patch request DTO typeR
- the full response DTO typeF
- the reference DTO typeQ
- the search request type extendingSearchRequest<T>
ID
- the identifier type
Generic abstract REST controller exposing a full suite of CRUD endpoints.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Maximum number of rows for CSV export.protected int
Maximum number of rows for JSON export.protected int
Maximum page size for pagination.protected int
Maximum number of rows for XLSX export.The service that handles CRUD operations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractCrudController
(AbstractCrudService<T, U, R, F, ID> service) Constructor to initialize the controller with the service. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.data.domain.Pageable
clampPageable
(org.springframework.data.domain.Pageable pageable) Clamps the pageable parameters to ensure they do not exceed the maximum page size.count()
Count total.org.springframework.http.ResponseEntity
<R> Create new.Bulk create.org.springframework.http.ResponseEntity
<Void> Delete.org.springframework.http.ResponseEntity
<Void> deleteAllByIds
(Collection<ID> ids) Bulk delete.org.springframework.http.ResponseEntity
<Void> Exists check.org.springframework.http.ResponseEntity
<org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody> Export search results as CSV, JSON or XLSX.findByIds
(Collection<ID> ids) Find by multiple IDs.org.springframework.http.ResponseEntity
<PaginatedResponse<R>> Paginated list (optional search).org.springframework.http.ResponseEntity
<PaginatedResponse<F>> Paginated list of reference DTOs.org.springframework.http.ResponseEntity
<R> Find by ID.org.springframework.http.ResponseEntity
<R> Partial update.patchAll
(@Valid List<Identified<ID, U>> requests) Bulk patch.Dedicated search endpoint.org.springframework.http.ResponseEntity
<R> Full update.updateAll
(@Valid List<Identified<ID, U>> requests) Bulk update.upsertAll
(Collection<U> requests) Bulk upsert.org.springframework.http.ResponseEntity
<Void> Validate an upsert request body without persisting.
-
Field Details
-
service
The service that handles CRUD operations. -
maxPageSize
@Value("${crudcraft.api.max-page-size:100}") protected int maxPageSizeMaximum page size for pagination. Default is 100, can be overridden in application properties. -
maxCsvRows
@Value("${crudcraft.export.max-csv-rows:100000}") protected int maxCsvRowsMaximum number of rows for CSV export. Default is 100,000, can be overridden in application properties. -
maxJsonRows
@Value("${crudcraft.export.max-json-rows:50000}") protected int maxJsonRowsMaximum number of rows for JSON export. Default is 50,000, can be overridden in application properties. -
maxXlsxRows
@Value("${crudcraft.export.max-xlsx-rows:25000}") protected int maxXlsxRowsMaximum number of rows for XLSX export. Default is 25,000, can be overridden in application properties.
-
-
Constructor Details
-
AbstractCrudController
Constructor to initialize the controller with the service.- Parameters:
service
- the service that handles CRUD operations
-
-
Method Details
-
clampPageable
protected org.springframework.data.domain.Pageable clampPageable(org.springframework.data.domain.Pageable pageable) Clamps the pageable parameters to ensure they do not exceed the maximum page size. If pageable is null, defaults to the first page with the maximum page size.- Parameters:
pageable
- the original pageable request- Returns:
- a clamped pageable object
-
getAll
@GetMapping public org.springframework.http.ResponseEntity<PaginatedResponse<R>> getAll(org.springframework.data.domain.Pageable pageable, @ModelAttribute Q searchRequest) Paginated list (optional search).GET /?page=...&size=...&q=...
-
getAllRef
@GetMapping("/ref") public org.springframework.http.ResponseEntity<PaginatedResponse<F>> getAllRef(org.springframework.data.domain.Pageable pageable, @ModelAttribute Q searchRequest) Paginated list of reference DTOs.GET /ref?page=...&size=...&q=...
-
getById
@GetMapping("/{id}") public org.springframework.http.ResponseEntity<R> getById(@PathVariable("id") ID id) Find by ID.GET /{id}
-
create
@PostMapping public org.springframework.http.ResponseEntity<R> create(@Valid @RequestBody U request) Create new.POST /
-
update
@PutMapping("/{id}") public org.springframework.http.ResponseEntity<R> update(@PathVariable("id") ID id, @Valid @RequestBody U request) Full update.PUT /{id}
-
patch
@PatchMapping("/{id}") public org.springframework.http.ResponseEntity<R> patch(@PathVariable("id") ID id, @RequestBody U request) Partial update.PATCH /{id}
-
delete
@DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> delete(@PathVariable("id") ID id) Delete.DELETE /{id}
-
createAll
@PostMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> createAll(@Valid @RequestBody @Valid List<U> requests) Bulk create.POST /batch
-
updateAll
@PutMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> updateAll(@Valid @RequestBody @Valid List<Identified<ID, U>> requests) Bulk update.PUT /batch
-
patchAll
@PatchMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> patchAll(@Valid @RequestBody @Valid List<Identified<ID, U>> requests) Bulk patch.PATCH /batch
-
upsertAll
@PostMapping("/batch/upsert") public org.springframework.http.ResponseEntity<List<R>> upsertAll(@RequestBody Collection<U> requests) Bulk upsert.POST /batch/upsert
-
deleteAllByIds
@DeleteMapping("/batch/delete") public org.springframework.http.ResponseEntity<Void> deleteAllByIds(@RequestBody Collection<ID> ids) Bulk delete.DELETE /batch/delete
-
exists
@RequestMapping(value="/exists/{id}", method={HEAD,GET}) public org.springframework.http.ResponseEntity<Void> exists(@PathVariable("id") ID id) Exists check.HEAD /{id}
orGET /exists/{id}
-
count
Count total.GET /count
-
findByIds
@PostMapping("/batch/ids") public org.springframework.http.ResponseEntity<List<R>> findByIds(@RequestBody Collection<ID> ids) Find by multiple IDs.POST /batch/ids
-
search
@GetMapping("/search") public org.springframework.http.ResponseEntity<List<R>> search(@ModelAttribute Q searchRequest, @RequestParam(value="limit",required=true) Integer limit) Dedicated search endpoint.GET /search?limit=...
-
validate
@PostMapping("/validate") public org.springframework.http.ResponseEntity<Void> validate(@Valid @RequestBody U request) Validate an upsert request body without persisting.POST /validate
-
export
@GetMapping("/export") public org.springframework.http.ResponseEntity<org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody> export(@ModelAttribute Q searchRequest, @RequestParam(value="limit",required=false) Integer limit, @RequestParam(value="format",required=true) String format) Export search results as CSV, JSON or XLSX.GET /export
-