Skip to content
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

feat: 일지 엔티티 구현(1차) #11

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/unit/daybook/DaybookApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
public class DaybookApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.unit.daybook.domain.board.controller;

import com.unit.daybook.domain.board.dto.request.AddBoardRequestDto;
import com.unit.daybook.domain.board.dto.response.AddBoardResponseDto;
import com.unit.daybook.domain.board.service.BoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RequestMapping("/board")
@RestController
public class BoardController {

private final BoardService boardService;

@GetMapping("/{boardId}")
public String getBoard(@PathVariable("boardId") Long boardId) {
return "단일 조회 정보 " + boardId;
}

@GetMapping("/boards")
public String getBoards() {
return "목록 조회 정보";
}


@PostMapping
public AddBoardResponseDto addBoard(@RequestBody AddBoardRequestDto addBoardRequestDto) {
Long memberId = 1L; // TODO 인증
return boardService.addBoard(addBoardRequestDto, memberId);

}

@PostMapping("/{boardId}")
public String modifyBoard(@PathVariable("boardId") Long boardId) {
return "수정 성공";
}

@DeleteMapping("/{boardId}")
public String deleteBoard(@PathVariable("boardId") Long boardId) {
return "삭제 성공";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.unit.daybook.domain.board.dto.request;


public record AddBoardRequestDto(String content, Long respectBoardId) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.unit.daybook.domain.board.dto.response;

import com.unit.daybook.domain.board.entity.Board;

public record AddBoardResponseDto(
Long boardId,
String content,
Long respectBoardId
) {

public static AddBoardResponseDto from(Board board) {
return new AddBoardResponseDto(board.getBoardId(), board.getContent(), board.getRespectBoardId());
}

}
41 changes: 41 additions & 0 deletions src/main/java/com/unit/daybook/domain/board/entity/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.unit.daybook.domain.board.entity;

import com.unit.daybook.domain.board.dto.request.AddBoardRequestDto;
import com.unit.daybook.domain.common.model.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;


@Getter
@Entity
@Table(name = "board")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Board extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_id")
private Long boardId;

@Column
private String content;

@Column(name = "respect_board_id")
private Long respectBoardId;


@Builder(access = AccessLevel.PRIVATE)
public Board(Long boardId, String content, Long respectBoardId) {
this.boardId = boardId;
this.content = content;
this.respectBoardId = respectBoardId;
}

public static Board createBoard(AddBoardRequestDto addBoardRequestDto) {
return Board.builder()
.content(addBoardRequestDto.content())
.respectBoardId(addBoardRequestDto.respectBoardId())
.build();
}

}
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.Board;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BoardRepository extends JpaRepository<Board, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.unit.daybook.domain.board.service;

import com.unit.daybook.domain.board.dto.request.AddBoardRequestDto;
import com.unit.daybook.domain.board.dto.response.AddBoardResponseDto;
import com.unit.daybook.domain.board.entity.Board;
import com.unit.daybook.domain.board.repository.BoardRepository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
@RequiredArgsConstructor
public class BoardService {

private final BoardRepository boardRepository;

public AddBoardResponseDto addBoard(AddBoardRequestDto addBoardRequestDto, Long memberId) {
return AddBoardResponseDto.from(boardRepository.save(Board.createBoard(addBoardRequestDto)));
}

}
Loading