-
Notifications
You must be signed in to change notification settings - Fork 1
4-Backend-seungchan #24
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: Backend
Are you sure you want to change the base?
Conversation
| public class BoardResponseDto { | ||
| private String title; | ||
| private String content; | ||
| private LocalDateTime createdAt; |
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.
์์ฑ๋ ์๊ฐ๊ณผ ์์ ๋ ์๊ฐ์ ๋ฐํํ๋ Board entity์๋ ์ด๋ฐ ํ๋๊ฐ ์์ด์ ๋ฌด์จ ์๊ฐ์ ๋ฐํํ์๋๊ฑด๊ฐ์?
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.
์๊ฐ์ ๊ดํ ํ๋๋ฅผ ์์ฑํ๋ ค๊ณ ํ์๋๋ฐ ์ญ์ ๋ฅผ ์ํ๋๊ฒ ๊ฐ์ต๋๋ค.
050af7d
|
|
||
| private final BoardService boardService; | ||
|
|
||
| @Autowired |
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.
@Autowired๋ฅผ ์ฌ์ฉํ ์์ฑ์ ์ฃผ์
๋ณด๋ค @RequiredArgsConstructor๋ฅผ ์ฌ์ฉํ ์์ฑ์ ์ฃผ์
๋ฐฉ๋ฒ๋ฅผ ์ฌ์ฉํ๋๊ฒ ์ข์ ๊ฒ๊ฐ์์
@Autowird์ ํ์ฉํ ์์ ์ ์ฃผ์ ์ ํ๋ ์ฃผ์ ์ด๋ผ๊ณ ํฉ๋๋ค
ํ๋ ์ฃผ์ ๋ฐฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํด์ ํธ๋ฆฌํ์ง๋ง ์ด๋ฌํ ๋ฐฉ๋ฒ๋ง๊ณ ๋ ์ฅ์ ์ด ์์ด ์คํ๋ง 4.3๋ถํฐ๋ ์ฌ์ฉํ์ง ์๋ ๊ฒ์ ๊ถ์ฅํ๊ณ ์์ต๋๋ค
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.
ae66a75
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
| this.boardService = boardService; | ||
| } | ||
| //๊ธ ๋ฑ๋ก | ||
| @PostMapping("/boards") |
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.
๊ณตํต์ ์ธ url์ @RequestMapping ํตํด ํ๋ฒ๋ง ์ ๊ณ ๋ ์ฌ์ฉํ ์ ์์ด์
@RequestMapping์ ํด๋์ค์ ๋ฉ์๋์ ์ฌ์ฉํ ์ ์์ง๋ง ์์น์ ๋ฐ๋ผ ์๋ฏธ๊ฐ ๋ค๋ฅด๋ ์ฐพ์๋ณด๊ณ ์์ ํด์ฃผ์ธ์
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.
007626e
ํผ๋๋ฐฑ ๋ฐ์ ์๋ฃํ์ต๋๋ค
| @@ -0,0 +1,6 @@ | |||
|
|
|||
| spring.datasource.url=jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true | |||
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.
๋ง์ ํ๋ก์ ํธ์์ application.properties ํ์ผ๋ณด๋ค application.ymlํ์ผ์ด ๊ฐ๋
์ฑ์ด ๋ ์ข๊ณ ์ฌ์ฉ์ ์นํ์ ์ด์ด์ yml ํ์ผ ๋ ๋ง์ด ์ฌ์ฉํด์
๊ทธ๋์ yml ํ์ผ ์ฌ์ฉํด๋ณด๋๊ฒ๋ ์ข์๊ฑฐ ๊ฐ์์
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.
8abe05e
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
| @@ -0,0 +1,6 @@ | |||
|
|
|||
| spring.datasource.url=jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true | |||
| spring.datasource.username=root | |||
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.
username์ด๋ password ๊ฐ์ ๋ฏผ๊ฐํ ์ ๋ณด๋ ์ธ๋ถ์ ๋
ธ์ถ๋๋ฉด ์๋๊ธฐ ๋๋ฌธ์ ์ปค๋ฐ์ ํ ๋ ํ๊ฒฝ๋ณ์ ์ฒ๋ฆฌํด์ ์ฌ๋ ค์ฃผ์ธ์
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.
ecca6f6
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
| } | ||
| //๋ชจ๋ ๊ธ ๊ฐ์ ธ์ค๊ธฐ | ||
| public List<BoardListResponseDto> findAllBoard(){ | ||
| try{ |
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.
try-catch ๋ฌธ์ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์๋์??
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.
try-catch ๊ตฌ๋ฌธ์ ์ฌ์ฉํด์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํ๋ ๊ฒ๋ณด๋ค Optional๋ฅผ ์ฌ์ฉํด์ ์์ธ์ฒ๋ฆฌํ๋๊ฒ ๋ ์ข์ ๊ฒ ๊ฐ์์
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.
cd2e132
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
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.
์์ธ์ฒ๋ฆฌ Optionl ์ฌ์ฉํด์ ์ ํด์ค๊ฑฐ ๊ฐ์๋ฐ ์ ์ฒด ๊ธ์ ๋ถ๋ฌ์ค๋ ์ํฉ์์ ์์ธ์ฒ๋ฆฌ๊ฐ ํ์ํด๋ณด์ด์ง ์์์ ๊ตณ์ด ์์ ํ ํ์๋ ์์ง๋ง ๋ค์์ ๊ฐ๋ฐํ ๋ ์ฐธ๊ณ ํด์ฃผ์ธ์!
| //์ ์ฒด ๋ชฉ๋ก ์กฐํ | ||
| @GetMapping("/boards") | ||
| public List<BoardListResponseDto> getAllBoards(){ | ||
| return boardService.findAllBoard(); |
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.
์ปจํธ๋กค๋ฌ์์ ๋ฐํํ ๋ ResponseEntity ์ฌ์ฉํด์ ๋ฐํ๊ฐ๊ณผ ์ํ ์ฝ๋๋ฅผ ํจ๊ป ๋ฐํํ๋ฉด ์ข์๊ฑฐ ๊ฐ์์
ResponseEntity๋ ์ ์ ํ ์ํ ์ฝ๋์ ์๋ต ํค๋ ๋ฐ ์๋ต ๋ณธ๋ฌธ์ ์์ฑํ์ฌ ํด๋ผ์ด์ธํธ์ ์ ๋ฌํ๊ธฐ ์ํด ์ฌ์ฉํฉ๋๋ค
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.
c3af8d1
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค
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.
ResponseEntity๋ฅผ ์ฌ์ฉํด์ return ํ ๋๋ ์์ฑ์๋ณด๋ค Builer ํจํด์ ์ฌ์ฉํด์
์์ฑ์๋ณด๋ค Builder ํจํด์ ์ฌ์ฉํ๋๊ฒ์ด ์ ์ง๋ณด์์ ์ข๊ณ ์๋ฏธ๊ฐ ์ง๊ด์ ์
| private LocalDateTime createdAt; | ||
| private LocalDateTime modifiedAt; | ||
| //Entity -> dto | ||
| public BoardListResponseDto(Board board){ |
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.
entity์์ dto ๋ณํํ๋ ๋ฉ์๋๊ฐ ๋๊ฐ ์๋๋ฐ ๋ ๋ฉ์๋๊ฐ title๋ฅผ ๊ฐ์ ธ์ค๋ ๋ด์ฉ์ผ๋ก ๊ฐ์ ๊ธฐ๋ฅ์ ํ๋ ๋ฉ์๋๊ฐ์๋ฐ ๋๊ฐ๋ฅผ ๋ง๋์ ์ด์ ๊ฐ ์๋์??
์ฌ์ฉ๋์ง ์๋ ๋ฉ์๋๋ ์ง์ฐ๋๊ฒ ์ข์๊ฒ๊ฐ์์
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.
177f1fb
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
ta2ye0n
left a comment
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.
๊ธ ์์ฑ๊ณผ ๊ธ ์์ ํ ๋ ๊ฐ์ dto๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ๋ถ๋ฆฌํด์ฃผ์ธ์
ex) ๊ธ์์ฑ -> BoardWriteRequestDto ๊ธ์์ -> BoardUpdateRequestDto (์ด๊ฑด ์์์ ๋๋ค ์ฐธ๊ณ ํด์ ์์ ํด์ฃผ์ธ์)
| import lombok.*; | ||
|
|
||
| @NoArgsConstructor | ||
| @Entity(name = "users") |
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.
board์ ๊ด๋ จ๋ entity์ธ๋ฐ users๋ก ์ ์ฅ ํ๋๊ฑด ๋ง์ง ์๋ ๊ฒ ๊ฐ์ ๋ณด์ฌ์
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.
6536bf5
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
| @AllArgsConstructor | ||
| public class BoardService { | ||
|
|
||
| private final BoardRepository boardRepository; |
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.
@AllArgsConstructor๋ฅผ ์ฌ์ฉํด๋ ๋ฌธ์ ๋ ์์ผ๋ ํ๋์ final์ด ๋ถ์ด์ @AllArgsConstructor๋์ ์ @RequiredArgsConstructor๋ฅผ ์ฌ์ฉํ๋๊ฒ์ด ๋ ์ ์ ํฉ๋๋ค
์์ฑ์ ์ด๋
ธํ
์ด์
์ ๋ํด ์์๋ณด์๋ฉด ๋์์ด ๋ ๊ฑฐ ๊ฐ์ต๋๋ค
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.
ํผ๋๋ฐฑ ๋ฐ์ ํ์ต๋๋ค.
c8be7a6
src/main/resources/application.yml
Outdated
| @@ -1,8 +1,8 @@ | |||
| spring: | |||
| datasource: | |||
| url: jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true | |||
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.
url ๋ถ๋ถ๋ ํ๊ฒฝ ๋ณ์ ์ฒ๋ฆฌ ํด์ฃผ์ธ์
ํ๊ฒฝ๋ณ์ ์ฒ๋ฆฌ๋ {$USERNAME} ์ด๋ฐ์์ผ๋ก ํ๋ฉด ๋ฉ๋๋ค
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.
์ค๋ฅ ์์ ํ์ต๋๋ค.
247e5c8
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.
url ๋ถ๋ถ์ด ํ๊ฒฝ๋ณ์ ์ฒ๋ฆฌ๊ฐ ๋์ง ์์์ด์ ๋ค์ ํ์ธํ๊ณ ํ๊ฒฝ๋ณ์ ์ฒ๋ฆฌํด์ฃผ์ธ์
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.
๋ค์ ํ์ธํ์ต๋๋ค. ์ฃ์กํฉ๋๋ค.
ffba8af
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.
ํผ๋๋ฐฑ ๋ฐ์ํ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค!
0dacb5e
820fb3a |
๐ก ๊ฐ์
๐ ์์ ๋ด์ฉ
๐ ๋ณ๊ฒฝ์ฌํญ
๐โโ๏ธ ์ง๋ฌธ์ฌํญ
๐ ์ด๋ ค์ ๋ ์