Skip to content

Commit

Permalink
Merge pull request #270 from CaZaIt/refactor/favorites
Browse files Browse the repository at this point in the history
[Chore] #268 - favorites DTO 네이밍 변경
  • Loading branch information
parkrootseok authored May 10, 2023
2 parents 717f010 + c772679 commit 03f06f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shop.cazait.domain.cafe.exception.CafeException;
import shop.cazait.domain.favorites.dto.GetFavoritesRes;
import shop.cazait.domain.favorites.dto.PostFavoritesRes;
import shop.cazait.domain.favorites.dto.response.FavoritesListOutDTO;
import shop.cazait.domain.favorites.dto.response.FavoritesCreateOutDTO;
import shop.cazait.domain.favorites.service.FavoritesService;
import shop.cazait.domain.user.exception.UserException;
import shop.cazait.global.common.dto.response.SuccessResponse;
Expand All @@ -36,18 +36,18 @@ public class FavoritesApiController {
@Parameter(name = "userId", description = "즐겨찾기를 등록할 유저 ID"),
@Parameter(name = "cafeId", description = "즐겨찾기로 등록할 카페 ID")
})
public SuccessResponse<PostFavoritesRes> addFavorites(@PathVariable Long userId,
@PathVariable Long cafeId)
public SuccessResponse<FavoritesCreateOutDTO> addFavorites(@PathVariable Long userId,
@PathVariable Long cafeId)
throws CafeException, UserException {
return new SuccessResponse<>(CREATE_FAVORITES, favoritesService.addFavorites(userId, cafeId));
}

@GetMapping("/user/{userId}")
@Operation(summary = "즐겨찾기 조회", description = "유저 ID를 받아 모든 즐겨찾기를 조회한다.")
@Parameter(name = "userId", description = "즐겨찾기를 조회할 유저 ID")
public SuccessResponse<List<GetFavoritesRes>> getFavorites(@PathVariable Long userId) {
public SuccessResponse<List<FavoritesListOutDTO>> getFavorites(@PathVariable Long userId) {

List<GetFavoritesRes> result = favoritesService.getFavorites(userId);
List<FavoritesListOutDTO> result = favoritesService.getFavorites(userId);
SuccessStatus resultStatus = SUCCESS;

if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package shop.cazait.domain.favorites.dto;
package shop.cazait.domain.favorites.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;

@Schema(description = "즐겨찾기 등록 Response : 등록한 즐겨찾기 정보")
@Schema(name = "즐겨찾기 등록 Response", description = "등록한 즐겨찾기 정보")
@Getter
@Builder(access = AccessLevel.PRIVATE)
public class PostFavoritesRes {
public class FavoritesCreateOutDTO {

@Schema(description = "즐겨찾기 ID", example = "1")
private Long id;

public static PostFavoritesRes of(Long favoritesId) {
return PostFavoritesRes.builder()
public static FavoritesCreateOutDTO of(Long favoritesId) {
return FavoritesCreateOutDTO.builder()
.id(favoritesId)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package shop.cazait.domain.favorites.dto;
package shop.cazait.domain.favorites.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
Expand All @@ -9,10 +9,10 @@
import shop.cazait.domain.cafeimage.entity.CafeImage;
import shop.cazait.domain.favorites.entity.Favorites;

@Schema(description = "즐겨찾기 Response : 즐겨찾기로 등록한 모든 카페에 대한 정보")
@Schema(name = "즐겨찾기 Response", description = "즐겨찾기로 등록한 모든 카페에 대한 정보")
@Getter
@Builder(access = AccessLevel.PROTECTED)
public class GetFavoritesRes {
public class FavoritesListOutDTO {

@Schema(description = "즐겨찾기 ID", example = "1")
private Long favoritesId;
Expand All @@ -38,10 +38,10 @@ public class GetFavoritesRes {
@Schema(description = "카페 이미지", example = "image.png")
private List<String> imageUrl;

public static List<GetFavoritesRes> of(List<Favorites> findFavorites) {
public static List<FavoritesListOutDTO> of(List<Favorites> findFavorites) {
return findFavorites.stream()
.map(favorites -> {
return GetFavoritesRes.builder()
return FavoritesListOutDTO.builder()
.favoritesId(favorites.getId())
.cafeId(favorites.getCafe().getId())
.name(favorites.getCafe().getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import shop.cazait.domain.cafe.entity.Cafe;
import shop.cazait.domain.cafe.exception.CafeException;
import shop.cazait.domain.cafe.repository.CafeRepository;
import shop.cazait.domain.favorites.dto.GetFavoritesRes;
import shop.cazait.domain.favorites.dto.PostFavoritesRes;
import shop.cazait.domain.favorites.dto.response.FavoritesListOutDTO;
import shop.cazait.domain.favorites.dto.response.FavoritesCreateOutDTO;
import shop.cazait.domain.favorites.entity.Favorites;
import shop.cazait.domain.favorites.exception.FavoritesException;
import shop.cazait.domain.favorites.repository.FavoritesRepository;
Expand All @@ -33,7 +33,7 @@ public class FavoritesService {
/**
* 즐겨찾기 추가
*/
public PostFavoritesRes addFavorites(Long userId, Long cafeId) throws CafeException, UserException {
public FavoritesCreateOutDTO addFavorites(Long userId, Long cafeId) throws CafeException, UserException {

User user = getUser(userId);
Cafe cafe = getCafe(cafeId);
Expand All @@ -45,7 +45,7 @@ public PostFavoritesRes addFavorites(Long userId, Long cafeId) throws CafeExcept

Long favoritesId = favoritesRepository.save(favorites).getId();

return PostFavoritesRes.of(favoritesId);
return FavoritesCreateOutDTO.of(favoritesId);

}

Expand All @@ -72,11 +72,11 @@ private Cafe getCafe(Long cafeId) throws CafeException {
* 즐겨찾기 조회
*/
@Transactional(readOnly = true)
public List<GetFavoritesRes> getFavorites(Long userId) {
public List<FavoritesListOutDTO> getFavorites(Long userId) {

List<Favorites> favorites = favoritesRepository.findAllByUserId(userId).orElse(null);

return GetFavoritesRes.of(favorites);
return FavoritesListOutDTO.of(favorites);

}

Expand Down

0 comments on commit 03f06f3

Please sign in to comment.