This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
replace-controllers-by-spring-data-rest.patch
112 lines (112 loc) · 4.73 KB
/
replace-controllers-by-spring-data-rest.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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>