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