Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
kotlin("plugin.jpa") version "1.3.72"
}

group = "com.example"
Expand All @@ -20,6 +21,11 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("junit:junit:4.12")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.+")
runtimeOnly("mysql:mysql-connector-java")
testImplementation("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.kong.dashboard.model

class CreateUserDto {
var name: String = "";
var age: Int = 0;
}
24 changes: 24 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/config/jpaConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.kotlinweb.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.domain.AuditorAware

import org.springframework.data.jpa.repository.config.EnableJpaAuditing
import java.util.*


@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
internal class JpaConfig {
@Bean
fun auditorAware(): AuditorAware<String> {
return AuditorAwareImpl()
}
}

internal class AuditorAwareImpl : AuditorAware<String> {
override fun getCurrentAuditor(): Optional<String> {
return Optional.of("Kong.jino")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ 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<String>
get() = ResponseEntity("Health", HttpStatus.OK)
class HealthCheckController{

@GetMapping(value = ["/health_check.html"])
fun getStatus():ResponseEntity<String>{
return ResponseEntity("Health", HttpStatus.OK)
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/controller/board.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.kotlinweb.controller

import com.example.kotlinweb.entity.Board
import com.example.kotlinweb.model.CreateBoardRequest
import com.example.kotlinweb.model.UpdateBoardRequest
import com.example.kotlinweb.service.BoardService
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*

@Controller
class BoardController(private val boardService: BoardService){
@GetMapping("/board")
fun findAll(): ResponseEntity<List<Board>> {
return ResponseEntity.ok(boardService.findAll())
}
@GetMapping("/board/{id}")
fun findOne(@PathVariable id:Long):ResponseEntity<Board>{
return ResponseEntity.ok(boardService.getBoardById(id))
}
@PostMapping("/board")
fun create(@RequestBody requestBody: CreateBoardRequest):ResponseEntity<Board>{
return ResponseEntity.ok(boardService.save(requestBody))
}

@PatchMapping("/board/{id}")
fun update(@PathVariable id:Long, @RequestBody requestBody: UpdateBoardRequest):ResponseEntity<Board>{
return ResponseEntity.ok(boardService.update(id,requestBody))
}

}
31 changes: 31 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/controller/comment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.kotlinweb.controller

import com.example.kotlinweb.entity.Comment
import com.example.kotlinweb.model.CreateCommentRequest
import com.example.kotlinweb.model.UpdateCommentRequest
import com.example.kotlinweb.service.CommentService
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*

@Controller
class CommentController(private val commentService: CommentService){
@GetMapping("/comment")
fun findAll(): ResponseEntity<List<Comment>> {
return ResponseEntity.ok(commentService.findAll())
}
@GetMapping("/comment/{id}")
fun findOne(@PathVariable id:Long):ResponseEntity<Comment>{
return ResponseEntity.ok(commentService.getCommentById(id))
}
@PostMapping("/comment")
fun create(@RequestBody requestBody: CreateCommentRequest):ResponseEntity<Comment>{
return ResponseEntity.ok(commentService.save(requestBody))
}

@PatchMapping("/comment/{id}")
fun update(@PathVariable id:Long, @RequestBody requestBody: UpdateCommentRequest):ResponseEntity<Comment>{
return ResponseEntity.ok(commentService.update(id,requestBody))
}

}
31 changes: 31 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/controller/post.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.kotlinweb.controller

import com.example.kotlinweb.entity.Post
import com.example.kotlinweb.model.CreatePostRequest
import com.example.kotlinweb.model.UpdatePostRequest
import com.example.kotlinweb.service.PostService
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*

@Controller
class PostController(private val postService: PostService){
@GetMapping("/post")
fun findAll(): ResponseEntity<List<Post>> {
return ResponseEntity.ok(postService.findAll())
}
@GetMapping("/post/{id}")
fun findOne(@PathVariable id:Long):ResponseEntity<Post>{
return ResponseEntity.ok(postService.getPostById(id))
}
@PostMapping("/post")
fun create(@RequestBody requestBody: CreatePostRequest):ResponseEntity<Post>{
return ResponseEntity.ok(postService.save(requestBody))
}

@PatchMapping("/post/{id}")
fun update(@PathVariable id:Long, @RequestBody requestBody: UpdatePostRequest):ResponseEntity<Post>{
return ResponseEntity.ok(postService.update(id,requestBody))
}

}
31 changes: 31 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/controller/user.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.kotlinweb.controller

import com.example.kotlinweb.entity.User
import com.example.kotlinweb.model.CreateUserRequest
import com.example.kotlinweb.model.UpdateUserRequest
import com.example.kotlinweb.service.UserService
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*

@Controller
class UserController(private val userService: UserService){
@GetMapping("/user")
fun findAll(): ResponseEntity<List<User>> {
return ResponseEntity.ok(userService.findAll())
}
@GetMapping("/user/{id}")
fun findOne(@PathVariable id:Long):ResponseEntity<User>{
return ResponseEntity.ok(userService.getUserById(id))
}
@PostMapping("/user")
fun create(@RequestBody requestBody: CreateUserRequest):ResponseEntity<User>{
return ResponseEntity.ok(userService.save(requestBody))
}

@PatchMapping("/user/{id}")
fun update(@PathVariable id:Long, @RequestBody requestBody: UpdateUserRequest):ResponseEntity<User>{
return ResponseEntity.ok(userService.update(id,requestBody))
}

}
32 changes: 32 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/entity/baseEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.kotlinweb.entity


import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer
import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import javax.persistence.EntityListeners
import javax.persistence.MappedSuperclass


@EntityListeners(value = [AuditingEntityListener::class])
@MappedSuperclass
abstract class Auditable<U>{
@CreatedBy
var createdBy: U? = null

@JsonDeserialize(using = LocalDateTimeDeserializer::class)
@CreatedDate
var createdAt: LocalDateTime? = null

@LastModifiedBy
var updateBy: U? = null

@JsonDeserialize(using = LocalDateTimeDeserializer::class)
@LastModifiedDate
var updatedAt: LocalDateTime? = null
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/entity/board.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.kotlinweb.entity
import com.fasterxml.jackson.annotation.JsonIgnore
import javax.persistence.*

@Entity
@Table
data class Board (
@Column
var title:String
): Auditable<String>() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id:Long? = null
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/entity/comment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.kotlinweb.entity

import javax.persistence.*

@Entity
@Table
data class Comment (
@Column
var title:String
): Auditable<String>() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id:Long? = null
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/entity/post.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.kotlinweb.entity

import javax.persistence.*

@Entity
@Table
data class Post (
@Column
var title:String
): Auditable<String>() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id:Long? = null
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/entity/user.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.kotlinweb.entity

import javax.persistence.*


@Entity
@Table
data class User (
@Column
var name: String
): Auditable<String>() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class CreateBoardRequest(
val title:String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class CreateCommentRequest(
val title:String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class CreatePostRequest(
val title:String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class CreateUserRequest(
val name:String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class UpdateBoardRequest(
val title:String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class UpdateCommentRequest(
val title:String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class UpdatePostRequest(
val title:String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.kotlinweb.model

data class UpdateUserRequest(
val name:String?
)
10 changes: 10 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/repository/board.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.kotlinweb.repository

import com.example.kotlinweb.entity.Board
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface BoardRepository: JpaRepository<Board, Long> {

}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/repository/comment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.kotlinweb.repository

import com.example.kotlinweb.entity.Comment
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface CommentRepository: JpaRepository<Comment, Long> {

}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/repository/post.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.kotlinweb.repository

import com.example.kotlinweb.entity.Post
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface PostRepository: JpaRepository<Post, Long> {

}
Loading