BoardServiceImpl > SPRING_DATA_JPA

본문 바로가기
사이트 내 전체검색

SPRING_DATA_JPA

BoardServiceImpl

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 195회 작성일 24-07-02 09:19

본문

package web.service;


import java.util.List;

import java.util.Optional;

import java.util.stream.Collectors;


import org.modelmapper.ModelMapper;

import org.springframework.data.domain.Page;

import org.springframework.data.domain.Pageable;

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.dto.BoardListAllDTO;

import web.dto.BoardListReplyCountDTO;

import web.dto.PageRequestDTO;

import web.dto.PageResponseDTO;

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);

Board board = dtoToEntity(boardDTO);


Long bno = boardRepository.save(board).getBno();


return bno;

}


@Override

public BoardDTO readOne(Long bno) {

//Optional<Board> result = boardRepository.findById(bno);

//board_image까지 조인 처리 적용

Optional<Board> result = boardRepository.findByIdWithImages(bno);


Board board = result.orElseThrow();


//BoardDTO boardDTO = modelMapper.map(board, BoardDTO.class);

BoardDTO boardDTO = entityToDTO(board);


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);

}


@Override

public PageResponseDTO<BoardDTO> list(PageRequestDTO pageRequestDTO) {

String[] types = pageRequestDTO.getTypes();

String keyword = pageRequestDTO.getKeyword();

Pageable pageable = pageRequestDTO.getPageable("bno");


Page<Board> result = boardRepository.searchAll(types, keyword, pageable);

List<BoardDTO> dtoList = result.getContent().stream()

.map(board -> modelMapper.map(board, BoardDTO.class))

.collect(Collectors.toList());


return PageResponseDTO.<BoardDTO>withAll()

.pageRequestDTO(pageRequestDTO)

.dtoList(dtoList)

.total((int)result.getTotalElements())

.build();

}


@Override

public PageResponseDTO<BoardListReplyCountDTO> listWithReplyCount(PageRequestDTO pageRequestDTO) {

String[] types = pageRequestDTO.getTypes();

String keyword = pageRequestDTO.getKeyword();

Pageable pageable = pageRequestDTO.getPageable("bno");


Page<BoardListReplyCountDTO> result = boardRepository.searchWithReplyCount(types, keyword, pageable);


return PageResponseDTO.<BoardListReplyCountDTO>withAll()

.pageRequestDTO(pageRequestDTO)

.dtoList(result.getContent())

.total((int)result.getTotalElements())

.build();

}


@Override

public PageResponseDTO<BoardListAllDTO> listWithAll(PageRequestDTO pageRequestDTO) {

// Querydsl의 처리 후 수정

return null;

}


}


댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
94
어제
199
최대
10,760
전체
275,123
Copyright © dancePKT . All rights reserved.