-
Notifications
You must be signed in to change notification settings - Fork 0
[#3] Zero #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: review/kotlin
Are you sure you want to change the base?
[#3] Zero #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 배운 걸 잘 응용하셨네요 굿
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 참고로 서버개발할 때는 RESTful하게 많이 짜는데요(물론 완벽히 구현이 불가함) RESTful하게 짤떄 동사는 사용하지 않습니다!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와우 감사합니다...저는 함수명처럼 사용하고 있었군요
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 보내주신 포스트 참고하여 수정 커밋 올리도록 하겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. boardList보다는 board그대로 가거나 boards가 어울릴것 같다는 생각이 드네요, 자바에서도 보통
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kkw01234 @DongHyukki 제가 REST API를 구현하는 스타일인데 참고하시면 좋을 것 같습니다. // 추가하는 경우
@PostMapping("board")
...
// 전체 조회인 경우
@GetMapping("/board")
....
// 단건 조회인 경우
@GetMapping("board/{id}")
....
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 @minkukjo (해리) 처럼 많이 사용하는 편이에요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
| 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 | ||
| ) |
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코틀린에서 이렇게도 사용할 수 있군요..처음 알았습니다 근데 필요없어보이는 코드 같아보이네요...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋㅋㅋㅋ급하게 막 짜느라곸ㅋㅋㅋㅋ죄송합니다..우선은 동작만 하게 만들어뒀어요 ㅠㅅㅠ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also 배워갑니다
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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문을 제외시킬 수 있을 것 같네요 :) |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
|
|
||
| server.port = 5050 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안드로이드는 이거 필요해요..??? 궁금궁금
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헤카앱 안드로이드같은 경우는 기본 sdk 로 자바 8을 쓰고있어서 해당 경로가 기입된것 같습니다 ㅇㅅㅇ...