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
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
Expand All @@ -32,6 +32,6 @@ tasks.withType<Test> {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
jvmTarget = "1.8"
}
}
8 changes: 8 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Aug 20 19:53:31 KST 2020
sdk.dir=/Users/zero/Library/Android/sdk
Copy link
Member

Choose a reason for hiding this comment

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

안드로이드는 이거 필요해요..??? 궁금궁금

Copy link
Author

Choose a reason for hiding this comment

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

헤카앱 안드로이드같은 경우는 기본 sdk 로 자바 8을 쓰고있어서 해당 경로가 기입된것 같습니다 ㅇㅅㅇ...

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class KotlinwebApplication
class KotlinWebApplication

fun main(args: Array<String>) {
runApplication<KotlinwebApplication>(*args)
runApplication<KotlinWebApplication>(*args)
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/config/BoardConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.kotlinweb.config

import com.example.kotlinweb.model.Board
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class BoardConfig {
Copy link
Member

Choose a reason for hiding this comment

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

배운 걸 잘 응용하셨네요 굿

Copy link
Author

Choose a reason for hiding this comment

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

꾸오오옹 아직은 잘 모르겠습니다 해리 감사해요 👍


@Bean
fun boardList(): MutableList<Board> {
return mutableListOf()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.kotlinweb.controller

import com.example.kotlinweb.model.Board
import com.example.kotlinweb.service.BoardService
import org.springframework.web.bind.annotation.*

@RestController
class BoardController(private val boardService: BoardService) {

@PostMapping("/board")
fun postBoard(@RequestBody body: Board): Boolean = boardService.create(body)

@GetMapping("/getBoardList")
Copy link
Member

Choose a reason for hiding this comment

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

참고로 서버개발할 때는 RESTful하게 많이 짜는데요(물론 완벽히 구현이 불가함) RESTful하게 짤떄 동사는 사용하지 않습니다!
한번 이 글을 참고해주시면 좋을 것 같아요 https://gmlwjd9405.github.io/2018/09/21/rest-and-restful.html

Copy link
Author

Choose a reason for hiding this comment

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

와우 감사합니다...저는 함수명처럼 사용하고 있었군요
실제로 저도 요청할 때, 저런 url을 보진 못했지만 이런 이유가 있었군요
그렇다면 getBoardList 보다는 boardList 가 맞는 형태겠군요

자원의 표현: 그 자원을 표현하기 위한 이름
-> Ex) DB의 학생 정보가 자원일 때, ‘students’를 자원의 표현으로 정한다.

Copy link
Author

Choose a reason for hiding this comment

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

보내주신 포스트 참고하여 수정 커밋 올리도록 하겠습니다.

Choose a reason for hiding this comment

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

boardList보다는 board그대로 가거나 boards가 어울릴것 같다는 생각이 드네요, 자바에서도 보통
변수명에 데이터타입을 넣지 않는 것 처럼 물론 데이터가 리스트 일 수는 있겠지만 너무 해당 데이터가 종속 되어버리는 것 같아요.
REST라 함은 board라는 자원을 가지고 행위를 표현한다고 보면 board와 boardList는 다른 자원의 관점으로 보게 될 수 있지 않을까 싶네요! 다른분들 의견은 어떤가요??

Copy link
Member

Choose a reason for hiding this comment

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

@kkw01234 @DongHyukki
저도 마크 의견에 동의합니다.
변수 이름에 컬렉션 이름 포함 안시키는게 좀 더 클린한 코드라고 생각합니다.
저같은 경우 단수는 board, 복수인 경우 boards를 쓰고 있습니다.
미처 못봤는데 REST에 관한 리뷰는 다니엘이 잘 주셨네요 👍

제가 REST API를 구현하는 스타일인데 참고하시면 좋을 것 같습니다.

// 추가하는 경우
@PostMapping("board")
...

// 전체 조회인 경우
@GetMapping("/board")
....

// 단건 조회인 경우
@GetMapping("board/{id}")
....

Copy link
Member

@kkw01234 kkw01234 Aug 25, 2020

Choose a reason for hiding this comment

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

저도 @minkukjo (해리) 처럼 많이 사용하는 편이에요!

Copy link
Author

Choose a reason for hiding this comment

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

으악 체고! 👍

fun getBoardList(): List<Board> = boardService.getBoard()

@DeleteMapping("/boardClear")
fun deleteBoardList() = boardService.delete()

@PutMapping("/boardUpdate")
fun updateBoard(@RequestBody body: Board) = boardService.updateItem(body)
}

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/model/Board.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.kotlinweb.model

data class Board(
val id: Int,
val title: String,
val name: String,
val content: String
)
26 changes: 26 additions & 0 deletions src/main/kotlin/com/example/kotlinweb/service/BoardService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.kotlinweb.service

import com.example.kotlinweb.model.Board
import org.springframework.stereotype.Service

@Service
class BoardService(
private val boardList: MutableList<Board>
) {
fun create(board: Board): Boolean {
boardList.add(board).also { println("create Board:$board") }
return true
}

fun getBoard(): List<Board> = boardList.also { println("get Board : $boardList") }

fun delete() = boardList.clear().also { println("clear Board : $boardList") }

fun updateItem(board: Board) = boardList.forEach {
if (it.id == board.id) {
boardList.remove(it)
boardList.add(board)
return@forEach
Copy link
Member

Choose a reason for hiding this comment

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

코틀린에서 이렇게도 사용할 수 있군요..처음 알았습니다

근데 필요없어보이는 코드 같아보이네요...

Copy link
Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋ급하게 막 짜느라곸ㅋㅋㅋㅋ죄송합니다..우선은 동작만 하게 만들어뒀어요 ㅠㅅㅠ...
데이터베이스 적용되면 대대적인 변화를 주도록 하겠습니다.

Choose a reason for hiding this comment

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

also 배워갑니다

Copy link
Member

@minkukjo minkukjo Aug 25, 2020

Choose a reason for hiding this comment

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

fun updateItem(board: Board) = boardList.find { it.id == board.id }.run { 
            boardList.remove(it)
            boardList.add(board)
}

boardList안에서 boardList를 부르는 모습도 썩 아름답지는 않지만 이렇게 리팩토링하면 return문을 제외시킬 수 있을 것 같네요 :)

}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@

server.port = 5050
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class KotlinwebApplicationTests {
class KotlinWebApplicationTests {

@Test
fun contextLoads() {
Expand Down