Skip to content

Conversation

@DongHyukki
Copy link

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

val id: Long, val title: String, val writer: String, val text: String
) {
val createDate: LocalDateTime = LocalDateTime.now()
var updateDate: LocalDateTime = LocalDateTime.now()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Member

@kkw01234 kkw01234 Aug 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posts를 바꿀 경우가 있나요? var로 선언이 되어있길래..
그리고 Any를 쓴 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val로 바꾸는게 맞는것 같네요.
모든 타입 다 가능하게끔 하려고 Any선언 했는데. 나름의 추상화...
해당 클래스 파일도 제네릭으로 하는게 맞았던거 같네요

AbstractDatabase.create(post);
}

override fun find(): MutableList<Any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 Any가 있네요..

override fun updatePost(post: Post) {
var foundPost: Post = postRepository.findById(post.id) as Post
foundPost?.let {
postRepository.delete(post)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete(it)이 더 올바른 표현처럼 보여요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

급하게 하고, 올리다보니 실수..

}

@DeleteMapping(value = ["/board"])
fun deletePost(@RequestBody post: Post): ResponseEntity<Any> {
Copy link
Member

@kkw01234 kkw01234 Aug 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 delete는 body지원 안하지 않나요? (잘 모름..)

override fun deletePost(post: Post) {
var foundPost: Post = postRepository.findById(post.id) as Post
foundPost?.let {
postRepository.delete(post)
Copy link
Member

@kkw01234 kkw01234 Aug 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let을 null check만 하는 것은 좋지 않은걸로 알고있는데 제가 잘 알고있는지는... (https://tourspace.tistory.com/208)

Copy link
Member

@minkukjo minkukjo Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foundPost가 nullable 타입이 아니라서 safety call을 할 필요는 없을 것 같습니다.
mark가 의도하신 바가 JPA query method를 사용해서 못찾은 경우에 null check를 하려는 의도셨다면 Post -> Post? 타입으로 바꾸는게 좋을 것 같아요.
다니엘이 올려주신 예제가 아주 좋네요. 저도 널체크는 명시적으로 if( A == null )로 하는게 좀 더 직관적인 것 같습니다. 이건 개인차 인것 같아요~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if로 하는게 맞을 것 같아요! 저도 급하게 하다보니 ?를.. 생략해버렸네요

@@ -0,0 +1,26 @@
package com.example.kotlinweb.board.model

class AbstractDatabase(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JPA를 안쓰기 위해 별도의 싱글톤을 사용하신거군요 멋진 아이디어네요

import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpringBootTest에 포함되어있어서 JUnit 5에서는 생략해도됩니다~

@mingimin
Copy link

Depoy가 몹니까 지금.. 커밋이 장난입니까? 엌

@minkukjo
Copy link
Member

@mingimin
다운로드
꼰머 앨런...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants