Skip to content

Commit 4173fc1

Browse files
author
kimyonghwa
committed
add api
- create board
1 parent a51dce7 commit 4173fc1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎src/main/java/com/rest/api/controller/v1/board/BoardController.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public class BoardController {
2828
private final BoardService boardService;
2929
private final ResponseService responseService;
3030

31+
@ApiImplicitParams({
32+
@ApiImplicitParam(name = "X-AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header")
33+
})
34+
@ApiOperation(value = "게시판 생성", notes = "신규 게시판을 생성한다.")
35+
@PostMapping(value = "/{boardName}")
36+
public SingleResult<Board> createBoard(@PathVariable String boardName) {
37+
return responseService.getSingleResult(boardService.insertBoard(boardName));
38+
}
39+
3140
@ApiOperation(value = "게시판 정보 조회", notes = "게시판 정보를 조회한다.")
3241
@GetMapping(value = "/{boardName}")
3342
public SingleResult<Board> boardInfo(@PathVariable String boardName) {
@@ -44,7 +53,7 @@ public ListResult<Post> posts(@PathVariable String boardName) {
4453
@ApiImplicitParam(name = "X-AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header")
4554
})
4655
@ApiOperation(value = "게시글 작성", notes = "게시글을 작성한다.")
47-
@PostMapping(value = "/{boardName}")
56+
@PostMapping(value = "/{boardName}/post")
4857
public SingleResult<Post> post(@PathVariable String boardName, @Valid @ModelAttribute ParamsPost post) {
4958
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
5059
String uid = authentication.getName();

‎src/main/java/com/rest/api/entity/board/Board.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package com.rest.api.entity.board;
22

33
import com.rest.api.entity.common.CommonDateEntity;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
46
import lombok.Getter;
57
import lombok.NoArgsConstructor;
68

79
import javax.persistence.*;
810

11+
@Builder
912
@Entity
1013
@Getter
1114
@NoArgsConstructor
15+
@AllArgsConstructor
1216
public class Board extends CommonDateEntity {
1317
@Id
1418
@GeneratedValue(strategy = GenerationType.IDENTITY)

‎src/main/java/com/rest/api/service/board/BoardService.java

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class BoardService {
2626
private final PostJpaRepo postJpaRepo;
2727
private final UserJpaRepo userJpaRepo;
2828

29+
public Board insertBoard(String boardName) {
30+
return boardJpaRepo.save(Board.builder().name(boardName).build());
31+
}
32+
2933
// 게시판 이름으로 게시판을 조회. 없을경우 CResourceNotExistException 처리
3034
public Board findBoard(String boardName) {
3135
return Optional.ofNullable(boardJpaRepo.findByName(boardName)).orElseThrow(CResourceNotExistException::new);

0 commit comments

Comments
 (0)