From 609414fd4f44a5ece52cba4c8fc747fe9cdb0dc4 Mon Sep 17 00:00:00 2001 From: gabi_def Date: Mon, 24 Aug 2020 10:21:50 +0900 Subject: [PATCH] =?UTF-8?q?(#2)CRUD=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlinweb/controller/PostingController.kt | 39 +++++++++++++++++++ .../kotlin/com/example/kotlinweb/db/BlogDB.kt | 9 +++++ .../com/example/kotlinweb/db/Content.kt | 10 +++++ .../com/example/kotlinweb/service/Service.kt | 23 +++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/main/kotlin/com/example/kotlinweb/controller/PostingController.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/db/BlogDB.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/db/Content.kt create mode 100644 src/main/kotlin/com/example/kotlinweb/service/Service.kt diff --git a/src/main/kotlin/com/example/kotlinweb/controller/PostingController.kt b/src/main/kotlin/com/example/kotlinweb/controller/PostingController.kt new file mode 100644 index 0000000..c97437c --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/controller/PostingController.kt @@ -0,0 +1,39 @@ +package com.example.kotlinweb.controller + +import com.example.kotlinweb.db.Content +import com.example.kotlinweb.service.Service +import org.springframework.web.bind.annotation.* + + +@RestController +@RequestMapping("/v1") +class PostingController( + val service: Service +) { + @PostMapping("/post") + fun addPostToBlog( + @RequestBody content: Content + ) { + service.addContent(content) + } + + @GetMapping("/get") + fun getPostedBlogList(): List { + return service.blogDB.blogList + } + + @PutMapping("/update") + fun updateBlogList( + @RequestBody content: Content + ) { + service.updateContent(content) + } + + @DeleteMapping("/delete") + fun deletePostedBlogList( + @RequestBody id: Int + ) { + service.deleteContent(id) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/db/BlogDB.kt b/src/main/kotlin/com/example/kotlinweb/db/BlogDB.kt new file mode 100644 index 0000000..df6e10e --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/db/BlogDB.kt @@ -0,0 +1,9 @@ +package com.example.kotlinweb.db + +import org.springframework.stereotype.Component + +@Component +class BlogDB { + val blogList : MutableList = mutableListOf() + +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/db/Content.kt b/src/main/kotlin/com/example/kotlinweb/db/Content.kt new file mode 100644 index 0000000..6ec7484 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/db/Content.kt @@ -0,0 +1,10 @@ +package com.example.kotlinweb.db + +class Content ( + val id :Int, + val title : String, + val content : String, + val date : String +){ + +} \ No newline at end of file diff --git a/src/main/kotlin/com/example/kotlinweb/service/Service.kt b/src/main/kotlin/com/example/kotlinweb/service/Service.kt new file mode 100644 index 0000000..7018219 --- /dev/null +++ b/src/main/kotlin/com/example/kotlinweb/service/Service.kt @@ -0,0 +1,23 @@ +package com.example.kotlinweb.service + +import com.example.kotlinweb.db.BlogDB +import com.example.kotlinweb.db.Content +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +class Service @Autowired constructor( + val blogDB: BlogDB +) { + fun addContent(content: Content) { + blogDB.blogList.add(content) + } + fun updateContent(content: Content){ + val updateItem = blogDB.blogList.filter { it.id == content.id } +// updateItem = content + } + fun deleteContent(id : Int){ + val deleteItem = blogDB.blogList.filter { it.id == id } + blogDB.blogList.remove(deleteItem) + } +} \ No newline at end of file