-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14df19d
commit 6762406
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/com/unit/daybook/domain/board/controller/BoardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "삭제 성공"; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/unit/daybook/domain/board/dto/BoardAddReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/unit/daybook/domain/board/dto/BoardAddResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/unit/daybook/domain/board/entity/BoardEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/unit/daybook/domain/board/repository/BoardRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BoardEntity, Long> { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/unit/daybook/domain/board/service/BoardService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |