CRUDController

@Validated
abstract class CRUDController<I : Serializable, E : CRUDEntity<I>, M : CRUDModel<I>, out D : CRUDDTO<I>, CM : CRUDCreateModel, UM : CRUDUpdateModel, in CD : CRUDCreateDTO, in UD : CRUDUpdateDTO, out Mapper : CRUDMapper<I, E, M, CM, UM>, out DTOMapper : CRUDDTOMapper<I, M, D, CM, UM, CD, UD>, out R : CRUDRepository<I, E>, out S : CRUDService<I, E, M, CM, UM, R, Mapper>>(typeName: String, service: S, mapper: DTOMapper)(source)

Base implementation of a controller for API layer providing CRUD operations

This is meant to be extended from a @RestController class, ideally also with a @RequestMapping with some path prefix for the endpoints.

Parameters

I

Id type of the data

E

Entity type of the data which is a CRUDEntity

M

Model type of the data which is a CRUDModel

D

DTO type of the data which is a CRUDDTO

CM

Create model type of the data which is a CRUDCreateModel

UM

Update model type of the data which is a CRUDUpdateModel

CD

Create DTO type of the data which is a CRUDCreateDTO

UD

Update DTO type of the data which is a CRUDUpdateDTO

Mapper

Mapper type of the data which is a CRUDMapper

DTOMapper

DTO mapper type of the data which is a CRUDDTOMapper

R

Repository type of the data which is a CRUDRepository

S

Service type of the data which is a CRUDService

Constructors

Link copied to clipboard
fun <out DTOMapper : CRUDDTOMapper<I, M, D, CM, UM, CD, UD>, out S : CRUDService<I, E, M, CM, UM, R, Mapper>> CRUDController(typeName: String, service: S, mapper: DTOMapper)

Functions

Link copied to clipboard
@PostMapping(consumes = ["application/json"], produces = ["application/json"])
@ResponseStatus(code = HttpStatus.CREATED)
fun create(@RequestBody createDTO: CD): D

Default implementation for creating a new entity from given create DTO

Link copied to clipboard
@DeleteMapping(value = ["/{id}"])
@ResponseStatus(value = HttpStatus.NO_CONTENT)
fun delete(@PathVariable(value = "id") id: I)

Default implementation for deleting an entity with given id

Link copied to clipboard
@GetMapping(path = ["/{id}"], produces = ["application/json"])
fun get(@PathVariable(value = "id") id: I): D

Default implementation for getting an entity with given id

Link copied to clipboard
@GetMapping(produces = ["application/json"])
fun getAll(@RequestParam(name = "page", required = false, defaultValue = "0") page: Int, @RequestParam(name = "perPage", required = false, defaultValue = "20") perPage: Int): Paged<D>

Default implementation for listing entities with given pagination

Link copied to clipboard
@PutMapping(path = ["/{id}"], consumes = ["application/json"], produces = ["application/json"])
fun update(@PathVariable(value = "id") id: I, @RequestBody updateDTO: UD): D

Default implementation for updating an entity with given id with given update DTO data

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard