Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
add patch for demonstration purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
andibraeu committed Apr 18, 2019
1 parent 36af50f commit 55d925a
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions replace-controllers-by-spring-data-rest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Index: src/main/kotlin/de/andi95/crudservicespringdata/ConferenceController.kt
===================================================================
--- src/main/kotlin/de/andi95/crudservicespringdata/ConferenceController.kt (revision 36af50fb7863291098fd45cbd950a80778b8e672)
+++ src/main/kotlin/de/andi95/crudservicespringdata/ConferenceController.kt (revision 36af50fb7863291098fd45cbd950a80778b8e672)
@@ -1,66 +0,0 @@
-package de.andi95.crudservicespringdata
-
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.http.HttpStatus
-import org.springframework.http.ResponseEntity
-import org.springframework.http.ResponseEntity.created
-import org.springframework.http.ResponseEntity.noContent
-import org.springframework.http.ResponseEntity.notFound
-import org.springframework.http.ResponseEntity.ok
-import org.springframework.web.bind.annotation.DeleteMapping
-import org.springframework.web.bind.annotation.GetMapping
-import org.springframework.web.bind.annotation.PathVariable
-import org.springframework.web.bind.annotation.PostMapping
-import org.springframework.web.bind.annotation.PutMapping
-import org.springframework.web.bind.annotation.RequestBody
-import org.springframework.web.bind.annotation.RequestMapping
-import org.springframework.web.bind.annotation.RestController
-import org.springframework.web.servlet.support.ServletUriComponentsBuilder
-
-@RestController
-@RequestMapping("/conferences")
-class ConferenceController(@Autowired val conferenceRepository: ConferenceRepository) {
-
- @PostMapping
- fun `create new element`(@RequestBody conference: Conference) :ResponseEntity<Conference> {
- val savedConference = conferenceRepository.save(conference)
- val uri = ServletUriComponentsBuilder.fromCurrentRequest()
- .path("/{id}")
- .buildAndExpand(savedConference.id)
- .toUri()
- return created(uri).body(savedConference)
- }
-
- @GetMapping("/{id}")
- fun `read single element`(@PathVariable id: String) :ResponseEntity<Conference> {
- val conference = conferenceRepository.findById(id)
- return if (conference.isPresent) {
- ok(conference.get())
- } else notFound().build()
- }
-
- @PutMapping("/{id}")
- fun `update single element`(@PathVariable id: String, @RequestBody conference: Conference) :ResponseEntity<Conference> {
- val oldConference = conferenceRepository.findById(id)
- val savedConference = conferenceRepository.save(conference)
- return if (oldConference.isPresent) {
- ok(savedConference)
- } else {
- val uri = ServletUriComponentsBuilder.fromCurrentRequest()
- .path("/{id}")
- .buildAndExpand(savedConference.id)
- .toUri()
- created(uri).body(savedConference)
- }
- }
-
- @DeleteMapping("/{id}")
- fun `delete single element`(@PathVariable id: String) :ResponseEntity<HttpStatus> {
- val conference = conferenceRepository.findById(id)
- return if (conference.isPresent) {
- noContent().build()
- } else notFound().build()
-
- }
-
-}
\ No newline at end of file
Index: src/main/kotlin/de/andi95/crudservicespringdata/Controller.kt
===================================================================
--- src/main/kotlin/de/andi95/crudservicespringdata/Controller.kt (revision 36af50fb7863291098fd45cbd950a80778b8e672)
+++ src/main/kotlin/de/andi95/crudservicespringdata/Controller.kt (revision 36af50fb7863291098fd45cbd950a80778b8e672)
@@ -1,14 +0,0 @@
-package de.andi95.crudservicespringdata
-
-import org.springframework.http.ResponseEntity
-import org.springframework.web.bind.annotation.GetMapping
-import org.springframework.web.bind.annotation.RestController
-
-@RestController
-class Controller {
-
- @GetMapping("/")
- fun `return hello world`(): ResponseEntity<String> {
- return ResponseEntity.ok("Hello World!")
- }
-}
\ No newline at end of file
Index: pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pom.xml (revision 36af50fb7863291098fd45cbd950a80778b8e672)
+++ pom.xml (date 1555583271000)
@@ -22,7 +22,11 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
+ <artifactId>spring-boot-starter-data-rest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>

0 comments on commit 55d925a

Please sign in to comment.