CRUDController
Base implementation of a controller for API layer providing CRUD operations
For some Foo data that have Long ids, a FooController defined as
@RestController
@RequestMapping("/foo")
class FooController(
service: FooService,
dtoMapper: FooDTOMapper
) : CRUDController<
Long,
FooDTO,
Foo,
FooEntity,
CreateFoo,
UpdateFoo,
CreateFooDTO,
UpdateFooDTO,
FooMapper,
FooDTOMapper,
FooService>("Foo", service, dtoMapper)
automatically implements
@PostMapping("/")
fun create(createDTO: CreateFooDTO): FooDTO
@GetMapping("/")
fun getAll(page: Int, perPage: Int): Paged<FooDTO>
@GetMapping("/{id}")
fun get(id: Long): FooDTO
@PutMapping("/{id}")
fun update(id: Long, updateDTO: UpdateFooDTO): FooDTO
@DeleteMapping("/{id}")
fun delete(id: Long)
This is meant to be extended from a @RestController class, ideally also with a @RequestMapping with some path prefix for the endpoints.
Parameters
Id type of the data
Entity type of the data which is a CRUDEntity
Model type of the data which is a CRUDModel
DTO type of the data which is a CRUDDTO
Create model type of the data which is a CRUDCreateModel
Update model type of the data which is a CRUDUpdateModel
Create DTO type of the data which is a CRUDCreateDTO
Update DTO type of the data which is a CRUDUpdateDTO
Mapper type of the data which is a CRUDMapper
DTO mapper type of the data which is a CRUDDTOMapper
Service type of the data which is a CRUDService