Skip to content

Instantly share code, notes, and snippets.

@diegolirio
Last active November 19, 2021 12:03
Show Gist options
  • Select an option

  • Save diegolirio/bd6f18d98aaeb641c85d7544027d4170 to your computer and use it in GitHub Desktop.

Select an option

Save diegolirio/bd6f18d98aaeb641c85d7544027d4170 to your computer and use it in GitHub Desktop.
@Transactional
@Path("/customers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class CustomerEntrypoint {
@Inject
private lateinit var customerSpringDataRepository: CustomerSpringDataRepository
@POST
fun created(customer: CustomerEntity): CustomerEntity {
customer.persist()
return customer
}
@GET
@Path("/{id}")
fun get(@PathParam("id") id: Long): CustomerEntity? {
return CustomerEntity.findById(id)
}
@GET
fun getList(): List<CustomerEntity> {
return CustomerEntity.findAll().list()
}
@DELETE
@Path("/{id}")
fun delete(@PathParam("id") id: Long) {
CustomerEntity.deleteById(id)
}
@PUT
@Path("/{id}")
fun update(@PathParam("id") id: Long, customer: CustomerEntity) {
CustomerEntity.findById(id)?.let {
it.copy(firstname = customer.firstname, lastname = customer.lastname)
}?.persist()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment