-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBoardService.java
More file actions
41 lines (26 loc) · 1.14 KB
/
BoardService.java
File metadata and controls
41 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.makefire.anonymous.service.board;
import com.makefire.anonymous.domain.board.entity.Board;
import com.makefire.anonymous.domain.board.repository.BoardRepository;
import com.makefire.anonymous.rest.dto.request.board.BoardSaveRequestDTO;
import com.makefire.anonymous.rest.dto.response.board.BoardResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class BoardService {
private final BoardRepository boardRepository;
public List<BoardResponseDTO> findAll() {
return boardRepository.findAll().stream().map(BoardResponseDTO::new).collect(Collectors.toList());
}
public BoardResponseDTO findById(Long id) {
Board entity = boardRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("해당 게시물이 없습니다. id=" + id));
return new BoardResponseDTO(entity);
}
public Long save(BoardSaveRequestDTO requestDTO) {
return boardRepository.save(requestDTO.toEntity())
.getId();
}
}