Last active
November 19, 2021 12:03
-
-
Save diegolirio/bd6f18d98aaeb641c85d7544027d4170 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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