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/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) } 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..f1097a1 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/controller/BoardController.kt @@ -0,0 +1,21 @@ +package com.example.kotlinweb.controller + +import com.example.kotlinweb.model.Board +import com.example.kotlinweb.service.BoardService +import org.springframework.web.bind.annotation.* + +@RestController +class BoardController(private val boardService: BoardService) { + + @PostMapping("/board") + fun postBoard(@RequestBody body: Board): Boolean = boardService.create(body) + + @GetMapping("/getBoardList") + fun getBoardList(): List = boardService.getBoard() + + @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/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..38082f3 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/service/BoardService.kt @@ -0,0 +1,26 @@ +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).also { println("create Board:$board") } + return true + } + + fun getBoard(): List = boardList.also { println("get Board : $boardList") } + + 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 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() {