Skip to content

Commit

Permalink
[tomato-market/plan#22] API 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunuk17 committed Nov 10, 2023
1 parent 627a50c commit 781bdc9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/tomato/market/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,18 @@ public ResponseDto<FavoriteDto> getFavorite(String userId, Integer postNum) {
.data(favoriteDto)
.build();
}

@GetMapping("/board/favorite/list")
public ResponseDto<List<FavoriteDto>> getFavoriteList(String userId) {
logger.info("BoardController.getFavoriteList() is called");

List<FavoriteDto> favoriteDtoList = boardService.getFavoriteList(userId);
logger.info("BoardController.getFavoriteList() : 관심 목록 조회 성공");

return ResponseDto.<List<FavoriteDto>>builder()
.status(HttpStatus.OK)
.message("관심 목록 조회 성공")
.data(favoriteDtoList)
.build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/tomato/market/dao/BoardDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface BoardDao {
FavoriteEntity save(FavoriteEntity favoriteEntity);

FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum);

List<FavoriteEntity> findByUserId(String userId);
}
12 changes: 12 additions & 0 deletions src/main/java/com/tomato/market/dao/impl/BoardDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,16 @@ public FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum) {
logger.info("BoardDaoImpl.findByUserIdAndPostNum() : 데이터 조회 성공");
return favoriteEntity;
}

@Override
public List<FavoriteEntity> findByUserId(String userId) {
logger.info("BoardDaoImpl.findByUserId() is called");
List<FavoriteEntity> favoriteEntities = favoriteRepository.findByUserId(userId);
if (favoriteEntities == null) {
logger.warn("BoardDaoImpl.findByUserId() : 데이터 조회 실패");
return null;
}
logger.info("BoardDaoImpl.findByUserId() : 데이터 조회 성공");
return favoriteEntities;
}
}
Original file line number Diff line number Diff line change
@@ -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, Integer> {
FavoriteEntity findByUserIdAndPostNum(String userId, Integer postNum);

List<FavoriteEntity> findByUserId(String userId);
}
2 changes: 2 additions & 0 deletions src/main/java/com/tomato/market/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public interface BoardService {
FavoriteDto addFavorite(String userId, Integer postNum, Integer status);

FavoriteDto getFavorite(String userId, Integer postNum);

List<FavoriteDto> getFavoriteList(String userId);
}
16 changes: 16 additions & 0 deletions src/main/java/com/tomato/market/service/impl/BoardServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,20 @@ public FavoriteDto getFavorite(String userId, Integer postNum) {
logger.info("BoardServiceImpl.getFavorite() : 데이터 조회 성공");
return FavoriteDto.toFavoriteDto(result);
}

@Override
public List<FavoriteDto> getFavoriteList(String userId) {
logger.info("BoardServiceImpl.getFavoriteList() is called");
List<FavoriteEntity> favoriteEntities = boardDao.findByUserId(userId);
if (favoriteEntities == null) {
logger.warn("BoardServiceImpl.getFavoriteList() : 관심 목록 조회 실패");
throw new BoardException("관심 목록 조회에 실패했습니다.");
}
logger.info("BoardServiceImpl.getFavoriteList() : 관심 목록 조회 성공");
List<FavoriteDto> favoriteDtoList = new ArrayList<>();
for (FavoriteEntity favoriteEntity : favoriteEntities) {
favoriteDtoList.add(FavoriteDto.toFavoriteDto(favoriteEntity));
}
return favoriteDtoList;
}
}

0 comments on commit 781bdc9

Please sign in to comment.