From 556ca43fe7a8def6231da05a90ba218bbaac4318 Mon Sep 17 00:00:00 2001 From: zero-dev Date: Sat, 15 Aug 2020 18:13:55 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[Refactoring]=20Application=20Class=20?= =?UTF-8?q?=EC=B9=B4=EB=A9=9C=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{KotlinwebApplication.kt => KotlinWebApplication.kt} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/kotlin/com/example/kotlinweb/{KotlinwebApplication.kt => KotlinWebApplication.kt} (73%) diff --git a/src/main/kotlin/com/example/kotlinweb/KotlinwebApplication.kt b/src/main/kotlin/com/example/kotlinweb/KotlinWebApplication.kt similarity index 73% rename from src/main/kotlin/com/example/kotlinweb/KotlinwebApplication.kt rename to src/main/kotlin/com/example/kotlinweb/KotlinWebApplication.kt index 326f1e6..5b5e15e 100644 --- a/src/main/kotlin/com/example/kotlinweb/KotlinwebApplication.kt +++ b/src/main/kotlin/com/example/kotlinweb/KotlinWebApplication.kt @@ -4,8 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @SpringBootApplication -class KotlinwebApplication +class KotlinWebApplication fun main(args: Array) { - runApplication(*args) + runApplication(*args) } From e9594981f3b76fb959668eea0fef557424319f8b Mon Sep 17 00:00:00 2001 From: zero-dev Date: Sat, 22 Aug 2020 18:40:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[#3]=20Create=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 4 ++-- local.properties | 8 ++++++++ .../com/example/kotlinweb/config/BoardConfig.kt | 14 ++++++++++++++ .../kotlinweb/controller/BoardController.kt | 16 ++++++++++++++++ .../kotlinweb/controller/HealthController.kt | 17 ----------------- .../kotlin/com/example/kotlinweb/model/Board.kt | 8 ++++++++ .../example/kotlinweb/service/BoardService.kt | 15 +++++++++++++++ src/main/resources/application.properties | 2 +- .../kotlinweb/KotlinwebApplicationTests.kt | 2 +- 9 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 local.properties create mode 100644 src/main/kotlin/com/example/kotlinweb/config/BoardConfig.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt delete mode 100644 src/main/kotlin/com/example/kotlinweb/controller/HealthController.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/model/Board.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/service/BoardService.kt diff --git a/build.gradle.kts b/build.gradle.kts index 9a7cabb..500066f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { group = "com.example" version = "0.0.1-SNAPSHOT" -java.sourceCompatibility = JavaVersion.VERSION_11 +java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { mavenCentral() @@ -32,6 +32,6 @@ tasks.withType { tasks.withType { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") - jvmTarget = "11" + jvmTarget = "1.8" } } diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..9331e0e --- /dev/null +++ b/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Thu Aug 20 19:53:31 KST 2020 +sdk.dir=/Users/zero/Library/Android/sdk diff --git a/src/main/kotlin/com/example/kotlinweb/config/BoardConfig.kt b/src/main/kotlin/com/example/kotlinweb/config/BoardConfig.kt new file mode 100644 index 0000000..5c62cd3 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/config/BoardConfig.kt @@ -0,0 +1,14 @@ +package com.example.kotlinweb.config + +import com.example.kotlinweb.model.Board +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class BoardConfig { + + @Bean + fun boardList(): MutableList { + return mutableListOf() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt new file mode 100644 index 0000000..64fc676 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt @@ -0,0 +1,16 @@ +package com.example.kotlinweb.controller + +import com.example.kotlinweb.model.Board +import com.example.kotlinweb.service.BoardService +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController + +@RestController +class BoardController(private val boardService: BoardService) { + + @PostMapping("/board") + fun postBoard(@RequestBody body: Board): Boolean { + return boardService.create(body) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/controller/HealthController.kt b/src/main/kotlin/com/example/kotlinweb/controller/HealthController.kt deleted file mode 100644 index fed3266..0000000 --- a/src/main/kotlin/com/example/kotlinweb/controller/HealthController.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.example.kotlinweb.controller - -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.stereotype.Controller -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.ResponseBody - -@Controller -class HealthController{ - - @get:ResponseBody - @get:GetMapping(value = ["/health_check.html"]) - val ratingStatus: ResponseEntity - get() = ResponseEntity("Health", HttpStatus.OK) - -} diff --git a/src/main/kotlin/com/example/kotlinweb/model/Board.kt b/src/main/kotlin/com/example/kotlinweb/model/Board.kt new file mode 100644 index 0000000..822f5c8 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/model/Board.kt @@ -0,0 +1,8 @@ +package com.example.kotlinweb.model + +data class Board( + val id: Int, + val title: String, + val name: String, + val content: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt new file mode 100644 index 0000000..0077e80 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt @@ -0,0 +1,15 @@ +package com.example.kotlinweb.service + +import com.example.kotlinweb.model.Board +import org.springframework.stereotype.Service + +@Service +class BoardService( + private val boardList: MutableList +) { + fun create(board: Board): Boolean { + boardList.add(board) + println("Board 생성 :$board") + return true + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..99b4e0f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +server.port = 5050 diff --git a/src/test/kotlin/com/example/kotlinweb/KotlinwebApplicationTests.kt b/src/test/kotlin/com/example/kotlinweb/KotlinwebApplicationTests.kt index 02d9c00..b31c54a 100644 --- a/src/test/kotlin/com/example/kotlinweb/KotlinwebApplicationTests.kt +++ b/src/test/kotlin/com/example/kotlinweb/KotlinwebApplicationTests.kt @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest @SpringBootTest -class KotlinwebApplicationTests { +class KotlinWebApplicationTests { @Test fun contextLoads() { From f96cac5d46d11190200b8dc7a26595abd0ccee73 Mon Sep 17 00:00:00 2001 From: zero-dev Date: Sat, 22 Aug 2020 18:45:58 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[#3]=20Get=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/kotlinweb/controller/BoardController.kt | 9 ++++++--- .../kotlin/com/example/kotlinweb/service/BoardService.kt | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt index 64fc676..a284bab 100644 --- a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt +++ b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt @@ -2,6 +2,7 @@ package com.example.kotlinweb.controller import com.example.kotlinweb.model.Board import com.example.kotlinweb.service.BoardService +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @@ -10,7 +11,9 @@ import org.springframework.web.bind.annotation.RestController class BoardController(private val boardService: BoardService) { @PostMapping("/board") - fun postBoard(@RequestBody body: Board): Boolean { - return boardService.create(body) - } + fun postBoard(@RequestBody body: Board): Boolean = boardService.create(body) + + @GetMapping("/getBoardList") + fun getBoardList(): List = boardService.getBoard() + } \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt index 0077e80..406f53e 100644 --- a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt +++ b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt @@ -12,4 +12,7 @@ class BoardService( println("Board 생성 :$board") return true } + + fun getBoard(): List = boardList + } \ No newline at end of file From e31291d556850974018673eefc69318a39af3351 Mon Sep 17 00:00:00 2001 From: zero-dev Date: Sat, 22 Aug 2020 19:05:39 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[#3]=20Delete=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/kotlinweb/controller/BoardController.kt | 9 +++++---- .../kotlin/com/example/kotlinweb/service/BoardService.kt | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt index a284bab..0f6782f 100644 --- a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt +++ b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt @@ -2,10 +2,7 @@ package com.example.kotlinweb.controller import com.example.kotlinweb.model.Board import com.example.kotlinweb.service.BoardService -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RestController class BoardController(private val boardService: BoardService) { @@ -16,4 +13,8 @@ class BoardController(private val boardService: BoardService) { @GetMapping("/getBoardList") fun getBoardList(): List = boardService.getBoard() + @DeleteMapping("/boardClear") + fun deleteBoardList() = boardService.delete() + + } \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt index 406f53e..294ec3b 100644 --- a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt +++ b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt @@ -8,11 +8,13 @@ class BoardService( private val boardList: MutableList ) { fun create(board: Board): Boolean { - boardList.add(board) - println("Board 생성 :$board") + boardList.add(board).also { println("create Board:$board") } return true } - fun getBoard(): List = boardList + fun getBoard(): List = boardList.also { println("get Board : $boardList") } + + fun delete() = boardList.clear().also { println("clear Board : $boardList") } + } \ No newline at end of file From 361d0cbdef0606ba9d806b01df0f1c34a87df37a Mon Sep 17 00:00:00 2001 From: zero-dev Date: Tue, 25 Aug 2020 15:52:10 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[#3]=20Update=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/kotlinweb/controller/BoardController.kt | 3 ++- .../kotlin/com/example/kotlinweb/service/BoardService.kt | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt index 0f6782f..f1097a1 100644 --- a/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt +++ b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt @@ -16,5 +16,6 @@ class BoardController(private val boardService: BoardService) { @DeleteMapping("/boardClear") fun deleteBoardList() = boardService.delete() - + @PutMapping("/boardUpdate") + fun updateBoard(@RequestBody body: Board) = boardService.updateItem(body) } \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt index 294ec3b..38082f3 100644 --- a/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt +++ b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt @@ -16,5 +16,11 @@ class BoardService( fun delete() = boardList.clear().also { println("clear Board : $boardList") } - + fun updateItem(board: Board) = boardList.forEach { + if (it.id == board.id) { + boardList.remove(it) + boardList.add(board) + return@forEach + } + } } \ No newline at end of file