From 781bdc964ad5c1380b1b427f928e83bf12dae74b Mon Sep 17 00:00:00 2001 From: Hyunuk Date: Sat, 11 Nov 2023 03:17:41 +0900 Subject: [PATCH] =?UTF-8?q?[tomato-market/plan#22]=20API=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/controller/BoardController.java | 14 ++++++++++++++ .../java/com/tomato/market/dao/BoardDao.java | 2 ++ .../com/tomato/market/dao/impl/BoardDaoImpl.java | 12 ++++++++++++ .../data/repository/FavoriteRepository.java | 4 ++++ .../com/tomato/market/service/BoardService.java | 2 ++ .../market/service/impl/BoardServiceImpl.java | 16 ++++++++++++++++ 6 files changed, 50 insertions(+) diff --git a/src/main/java/com/tomato/market/controller/BoardController.java b/src/main/java/com/tomato/market/controller/BoardController.java index b504946..a72f062 100644 --- a/src/main/java/com/tomato/market/controller/BoardController.java +++ b/src/main/java/com/tomato/market/controller/BoardController.java @@ -207,4 +207,18 @@ public ResponseDto getFavorite(String userId, Integer postNum) { .data(favoriteDto) .build(); } + + @GetMapping("/board/favorite/list") + public ResponseDto> getFavoriteList(String userId) { + logger.info("BoardController.getFavoriteList() is called"); + + List favoriteDtoList = boardService.getFavoriteList(userId); + logger.info("BoardController.getFavoriteList() : 관심 목록 조회 성공"); + + return ResponseDto.>builder() + .status(HttpStatus.OK) + .message("관심 목록 조회 성공") + .data(favoriteDtoList) + .build(); + } } diff --git a/src/main/java/com/tomato/market/dao/BoardDao.java b/src/main/java/com/tomato/market/dao/BoardDao.java index b0f4e9f..0a1c816 100644 --- a/src/main/java/com/tomato/market/dao/BoardDao.java +++ b/src/main/java/com/tomato/market/dao/BoardDao.java @@ -27,4 +27,6 @@ public interface BoardDao { FavoriteEntity save(FavoriteEntity favoriteEntity); FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum); + + List findByUserId(String userId); } diff --git a/src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java b/src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java index efb38f9..1fde28b 100644 --- a/src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java +++ b/src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java @@ -162,4 +162,16 @@ public FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum) { logger.info("BoardDaoImpl.findByUserIdAndPostNum() : 데이터 조회 성공"); return favoriteEntity; } + + @Override + public List findByUserId(String userId) { + logger.info("BoardDaoImpl.findByUserId() is called"); + List favoriteEntities = favoriteRepository.findByUserId(userId); + if (favoriteEntities == null) { + logger.warn("BoardDaoImpl.findByUserId() : 데이터 조회 실패"); + return null; + } + logger.info("BoardDaoImpl.findByUserId() : 데이터 조회 성공"); + return favoriteEntities; + } } diff --git a/src/main/java/com/tomato/market/data/repository/FavoriteRepository.java b/src/main/java/com/tomato/market/data/repository/FavoriteRepository.java index 641c425..cf1ec65 100644 --- a/src/main/java/com/tomato/market/data/repository/FavoriteRepository.java +++ b/src/main/java/com/tomato/market/data/repository/FavoriteRepository.java @@ -1,9 +1,13 @@ package com.tomato.market.data.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import com.tomato.market.data.entity.FavoriteEntity; public interface FavoriteRepository extends JpaRepository { FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum); + + List findByUserId(String userId); } diff --git a/src/main/java/com/tomato/market/service/BoardService.java b/src/main/java/com/tomato/market/service/BoardService.java index 83c6046..a691cc9 100644 --- a/src/main/java/com/tomato/market/service/BoardService.java +++ b/src/main/java/com/tomato/market/service/BoardService.java @@ -29,4 +29,6 @@ public interface BoardService { FavoriteDto addFavorite(String userId, Integer postNum, Integer status); FavoriteDto getFavorite(String userId, Integer postNum); + + List getFavoriteList(String userId); } diff --git a/src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java b/src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java index f24077b..d36dcb3 100644 --- a/src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java +++ b/src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java @@ -237,4 +237,20 @@ public FavoriteDto getFavorite(String userId, Integer postNum) { logger.info("BoardServiceImpl.getFavorite() : 데이터 조회 성공"); return FavoriteDto.toFavoriteDto(result); } + + @Override + public List getFavoriteList(String userId) { + logger.info("BoardServiceImpl.getFavoriteList() is called"); + List favoriteEntities = boardDao.findByUserId(userId); + if (favoriteEntities == null) { + logger.warn("BoardServiceImpl.getFavoriteList() : 관심 목록 조회 실패"); + throw new BoardException("관심 목록 조회에 실패했습니다."); + } + logger.info("BoardServiceImpl.getFavoriteList() : 관심 목록 조회 성공"); + List favoriteDtoList = new ArrayList<>(); + for (FavoriteEntity favoriteEntity : favoriteEntities) { + favoriteDtoList.add(FavoriteDto.toFavoriteDto(favoriteEntity)); + } + return favoriteDtoList; + } }