Conversation
| val id: Long, val title: String, val writer: String, val text: String | ||
| ) { | ||
| val createDate: LocalDateTime = LocalDateTime.now() | ||
| var updateDate: LocalDateTime = LocalDateTime.now() |
There was a problem hiding this comment.
createDate, updateDate도 생성자에 넣는거 가능합니다!
코틀린에서는 default값 주입 가능해요
class Post(
val id: Long,
val title: String,
val writer: String,
val text: String,
val createDate: LocalDateTime = LocalDateTime.now()
var updateDate: LocalDateTime = LocalDateTime.now()
)
|
|
||
| ) { | ||
| companion object { | ||
| var posts: MutableList<Any> = mutableListOf() |
There was a problem hiding this comment.
posts를 바꿀 경우가 있나요? var로 선언이 되어있길래..
그리고 Any를 쓴 이유가 있을까요?
There was a problem hiding this comment.
val로 바꾸는게 맞는것 같네요.
모든 타입 다 가능하게끔 하려고 Any선언 했는데. 나름의 추상화...
해당 클래스 파일도 제네릭으로 하는게 맞았던거 같네요
| AbstractDatabase.create(post); | ||
| } | ||
|
|
||
| override fun find(): MutableList<Any> { |
| override fun updatePost(post: Post) { | ||
| var foundPost: Post = postRepository.findById(post.id) as Post | ||
| foundPost?.let { | ||
| postRepository.delete(post) |
| } | ||
|
|
||
| @DeleteMapping(value = ["/board"]) | ||
| fun deletePost(@RequestBody post: Post): ResponseEntity<Any> { |
There was a problem hiding this comment.
근데 delete는 body지원 안하지 않나요? (잘 모름..)
| override fun deletePost(post: Post) { | ||
| var foundPost: Post = postRepository.findById(post.id) as Post | ||
| foundPost?.let { | ||
| postRepository.delete(post) |
There was a problem hiding this comment.
let을 null check만 하는 것은 좋지 않은걸로 알고있는데 제가 잘 알고있는지는... (https://tourspace.tistory.com/208)
There was a problem hiding this comment.
foundPost가 nullable 타입이 아니라서 safety call을 할 필요는 없을 것 같습니다.
mark가 의도하신 바가 JPA query method를 사용해서 못찾은 경우에 null check를 하려는 의도셨다면 Post -> Post? 타입으로 바꾸는게 좋을 것 같아요.
다니엘이 올려주신 예제가 아주 좋네요. 저도 널체크는 명시적으로 if( A == null )로 하는게 좀 더 직관적인 것 같습니다. 이건 개인차 인것 같아요~
There was a problem hiding this comment.
if로 하는게 맞을 것 같아요! 저도 급하게 하다보니 ?를.. 생략해버렸네요
| @@ -0,0 +1,26 @@ | |||
| package com.example.kotlinweb.board.model | |||
|
|
|||
| class AbstractDatabase( | |||
There was a problem hiding this comment.
JPA를 안쓰기 위해 별도의 싱글톤을 사용하신거군요 멋진 아이디어네요
| import org.springframework.boot.test.context.SpringBootTest | ||
| import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
|
||
| @ExtendWith(SpringExtension::class) |
There was a problem hiding this comment.
SpringBootTest에 포함되어있어서 JUnit 5에서는 생략해도됩니다~
|
Depoy가 몹니까 지금.. 커밋이 장난입니까? 엌 |
|
@mingimin |

코틀린 잘 못해여.. 리팩토링 가이드 부탁드려요 :)