diff --git a/src/main/java/com/unit/daybook/domain/board/controller/BoardController.java b/src/main/java/com/unit/daybook/domain/board/controller/BoardController.java new file mode 100644 index 0000000..448abe9 --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/controller/BoardController.java @@ -0,0 +1,44 @@ +package com.unit.daybook.domain.board.controller; + +import com.unit.daybook.domain.board.dto.BoardAddReqDto; +import com.unit.daybook.domain.board.dto.BoardAddResDto; +import com.unit.daybook.domain.board.service.BoardService; +import org.springframework.web.bind.annotation.*; + +@RequestMapping("/board") +@RestController +public class BoardController { + + private final BoardService boardService; + + public BoardController(BoardService boardService) { + this.boardService = boardService; + } + @GetMapping("/{boardId}") + public String getBoard(@PathVariable("boardId") Long boardId) { + return "단일 조회 정보 " + boardId; + } + + @GetMapping("/boards") + public String getBoards() { + return "목록 조회 정보"; + } + + + @PostMapping + public BoardAddResDto addBoard(@RequestBody BoardAddReqDto boardAddReqDto) { + Long memberId = 1L; // TODO 인증 + return boardService.addBoard(boardAddReqDto, memberId); + + } + + @PostMapping("/{boardId}") + public String modifyBoard(@PathVariable("boardId") Long boardId) { + return "수정 성공"; + } + + @DeleteMapping("/{boardId}") + public String deleteBoard(@PathVariable("boardId") Long boardId) { + return "삭제 성공"; + } +} diff --git a/src/main/java/com/unit/daybook/domain/board/dto/BoardAddReqDto.java b/src/main/java/com/unit/daybook/domain/board/dto/BoardAddReqDto.java new file mode 100644 index 0000000..28efa97 --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/dto/BoardAddReqDto.java @@ -0,0 +1,22 @@ +package com.unit.daybook.domain.board.dto; + +import com.unit.daybook.domain.board.entity.BoardEntity; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@Getter +@NoArgsConstructor +public class BoardAddReqDto { + private String content; + private Long respectBoardId; + + + public BoardEntity toEntity() { + BoardEntity entity = new BoardEntity(); + entity.setContent(content); + entity.setRespectBoardId(respectBoardId); + return entity; + } +} diff --git a/src/main/java/com/unit/daybook/domain/board/dto/BoardAddResDto.java b/src/main/java/com/unit/daybook/domain/board/dto/BoardAddResDto.java new file mode 100644 index 0000000..dca3ca1 --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/dto/BoardAddResDto.java @@ -0,0 +1,27 @@ +package com.unit.daybook.domain.board.dto; + +import com.unit.daybook.domain.board.entity.BoardEntity; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class BoardAddResDto { + private Long boardId; + private String content; + private Long respectBoardId; + private LocalDateTime createdAt; + + private LocalDateTime modifiedAt; + + @Builder + public BoardAddResDto(BoardEntity entity) { + this.boardId = entity.getBoardId(); + this.content = entity.getContent(); + this.respectBoardId = entity.getRespectBoardId(); + this.createdAt = null; + this.modifiedAt = null; + } + +} diff --git a/src/main/java/com/unit/daybook/domain/board/entity/BoardEntity.java b/src/main/java/com/unit/daybook/domain/board/entity/BoardEntity.java new file mode 100644 index 0000000..8eead37 --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/entity/BoardEntity.java @@ -0,0 +1,25 @@ +package com.unit.daybook.domain.board.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@Table(name = "board") +@Entity +public class BoardEntity { + + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + private Long boardId; + + @Column + private String content; + + @Column + private Long respectBoardId; + + + +} diff --git a/src/main/java/com/unit/daybook/domain/board/repository/BoardRepository.java b/src/main/java/com/unit/daybook/domain/board/repository/BoardRepository.java new file mode 100644 index 0000000..5d7ff78 --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/repository/BoardRepository.java @@ -0,0 +1,10 @@ +package com.unit.daybook.domain.board.repository; + +import com.unit.daybook.domain.board.entity.BoardEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BoardRepository extends JpaRepository { + +} diff --git a/src/main/java/com/unit/daybook/domain/board/service/BoardService.java b/src/main/java/com/unit/daybook/domain/board/service/BoardService.java new file mode 100644 index 0000000..6b9f4de --- /dev/null +++ b/src/main/java/com/unit/daybook/domain/board/service/BoardService.java @@ -0,0 +1,25 @@ +package com.unit.daybook.domain.board.service; + +import com.unit.daybook.domain.board.dto.BoardAddReqDto; +import com.unit.daybook.domain.board.dto.BoardAddResDto; +import com.unit.daybook.domain.board.entity.BoardEntity; +import com.unit.daybook.domain.board.repository.BoardRepository; +import jakarta.transaction.Transactional; +import org.springframework.stereotype.Service; + +@Service +public class BoardService { + public BoardService(BoardRepository boardRepository) { + this.boardRepository = boardRepository; + } + + private final BoardRepository boardRepository; + + @Transactional + public BoardAddResDto addBoard(BoardAddReqDto boardAddReqDto, Long memberId) { + BoardEntity entity = boardRepository.save(boardAddReqDto.toEntity()); + return BoardAddResDto.builder() + .entity(entity) + .build(); + } +}