BoardServiceImpl
페이지 정보
본문
package web.service;
import java.util.Optional;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import web.domain.Board;
import web.dto.BoardDTO;
import web.repository.BoardRepository;
@Service
@Log4j2
@RequiredArgsConstructor
@Transactional
public class BoardServiceImpl implements BoardService {
private final ModelMapper modelMapper;
private final BoardRepository boardRepository;
@Override
public Long register(BoardDTO boardDTO) {
Board board = modelMapper.map(boardDTO, Board.class);
Long bno = boardRepository.save(board).getBno();
return bno;
}
@Override
public BoardDTO readOne(Long bno) {
Optional<Board> result = boardRepository.findById(bno);
Board board = result.orElseThrow();
BoardDTO boardDTO = modelMapper.map(board, BoardDTO.class);
return boardDTO;
}
@Override
public void modify(BoardDTO boardDTO) {
Optional<Board> result = boardRepository.findById(boardDTO.getBno());
Board board = result.orElseThrow();
board.change(boardDTO.getTitle(), boardDTO.getContent()); //제목,내용 수정
boardRepository.save(board);
}
@Override
public void remove(Long bno) {
boardRepository.deleteById(bno);
}
}
- 이전글BoardService 24.06.18
- 다음글BoardServiceTests 24.06.18
댓글목록
등록된 댓글이 없습니다.