Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class EstateOwnerShipAdapter implements EstateOwnerShipPort {
Expand All @@ -33,4 +35,12 @@ public void deleteOwnership(Long userId, String kaptCode) {
repository.deleteByKaptCodeAndUserId(kaptCode, userId);
}

@Override
public List<EstateOwnership> loadMyOwnerships(Long userId) {

return repository.findByUserId(userId).stream()
.map(EstateOwnershipJpaEntity::toDomain)
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public Page<Favorite> loadUserFavoriteByType(Long userId, FavoriteType type, Pag
.map(FavoriteJpaEntity::toDomain);
}

@Override
public List<Favorite> loadUserFavoriteByType(Long userId, FavoriteType type) {
return repository.findByUserIdAndType(userId, type).stream()
.map(FavoriteJpaEntity::toDomain)
.toList();
}

@Override
public boolean checkFavoriteByUserIdAndTypeAndCode(Long userId, FavoriteType type, String code) {
if (type.equals(FavoriteType.REGION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface EstateOwnershipJpaRepository extends JpaRepository<EstateOwnershipJpaEntity, Long> {

boolean existsByKaptCodeAndUserId(String kaptCode, Long userId);

void deleteByKaptCodeAndUserId(String kaptCode, Long userId);

List<EstateOwnershipJpaEntity> findByUserId(Long userId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface FavoriteJpaRepository extends JpaRepository<FavoriteJpaEntity,

Page<FavoriteJpaEntity> findByUserIdAndType(Long userId, FavoriteType type, Pageable pageable);

List<FavoriteJpaEntity> findByUserIdAndType(Long userId, FavoriteType type);

Optional<FavoriteJpaEntity> findByIdAndUserId(Long id, Long userId);

boolean existsByUserIdAndKaptCode(Long userId, String kaptCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
package com.zipte.platform.server.application.in.dashboard;

import com.zipte.platform.server.domain.estate.Estate;
import com.zipte.platform.server.domain.estate.EstatePrice;
import com.zipte.platform.server.domain.region.Region;
import com.zipte.platform.server.domain.region.RegionPrice;

import java.util.List;

public interface DashBoardUseCase {

/*
매매 / 관심 지역 관심 지역 - 실거래가 동향 관심 지역으로 설정한 지역의 가격 변화에 대한 알림을 받는다.
매매 / 관심 아파트 관심 아파트 - 시세 변화 관심 아파트의 가격 변화에 대한 알림을 받는다.
전체 / 맞춤형 아파트 제공 맞춤형 추천 매물 현황 추천시스템을 통해 관심 아파트로 설정한 유사 아파트를 제공한다.
나의 아파트 가격 변화 / 나의 아파트 가격 변화 조회 / 개인정보에 등록한 나의 아파트의 가격 변화를 그래프로 확인한다.
*/


/// 관심 지역 조회하기
List<Region> getFavoriteRegion(Long userId);

/// 관심 지역 가격 조회하기
List<RegionPrice> getFavoriteRegionPrices(Long userId);


/// 관심 아파트 목록 조회하기
List<Estate> getFavoriteEstates(Long userId);


/// 관심 아파트 가격 목록 조회하기
List<EstatePrice> getFavoriteEstatePrice(Long userId);


/// AI 추천 목록 조회하기


/// 주거지 인증을 한 나의 아파트 조회하기
List<EstatePrice> getMyEstatePrices(Long userId);



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.zipte.platform.server.domain.estateOwnership.EstateOwnership;

import java.util.*;

public interface EstateOwnerShipPort {

/// 저장하기
Expand All @@ -15,4 +17,7 @@ public interface EstateOwnerShipPort {
void deleteOwnership(Long userId, String kaptCode);


/// 대시보드용
List<EstateOwnership> loadMyOwnerships(Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface FavoritePort {
// 관심 목록 조회하기
Page<Favorite> loadUserFavoriteByType(Long userId, FavoriteType type, Pageable pageable);

List<Favorite> loadUserFavoriteByType(Long userId, FavoriteType type);

// 중복 여부 판단 조회
boolean checkFavoriteByUserIdAndTypeAndCode(Long userId, FavoriteType type, String code);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.zipte.platform.server.application.service;

import com.zipte.platform.core.response.ErrorCode;
import com.zipte.platform.server.application.in.dashboard.DashBoardUseCase;
import com.zipte.platform.server.application.out.estate.EstatePricePort;
import com.zipte.platform.server.application.out.estate.LoadEstatePort;
import com.zipte.platform.server.application.out.estateOwnership.EstateOwnerShipPort;
import com.zipte.platform.server.application.out.favorite.FavoritePort;
import com.zipte.platform.server.application.out.region.RegionPort;
import com.zipte.platform.server.application.out.region.RegionPricePort;
import com.zipte.platform.server.application.out.user.UserPort;
import com.zipte.platform.server.domain.estate.Estate;
import com.zipte.platform.server.domain.estate.EstatePrice;
import com.zipte.platform.server.domain.estateOwnership.EstateOwnership;
import com.zipte.platform.server.domain.favorite.Favorite;
import com.zipte.platform.server.domain.favorite.FavoriteType;
import com.zipte.platform.server.domain.region.Region;
import com.zipte.platform.server.domain.region.RegionPrice;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

@Service
@Transactional
@RequiredArgsConstructor
public class DashBoardService implements DashBoardUseCase {


private final UserPort userPort;

private final FavoritePort favoritePort;

private final RegionPort regionPort;

private final RegionPricePort regionPricePort;

private final LoadEstatePort loadEstatePort;

private final EstatePricePort estatePricePort;

private final EstateOwnerShipPort estateOwnerShipPort;

/// 나의 관심 지역 조회
@Override
public List<Region> getFavoriteRegion(Long userId) {
/// 유저 예외 처리
if (userPort.checkExistingById(userId)) {
throw new NoSuchElementException(ErrorCode.NOT_USER.getMessage());
}

/// 유저의 관심 지역 목록 조회하기
List<Favorite> regionList = favoritePort.loadUserFavoriteByType(userId, FavoriteType.REGION);


/// 관심 지역 목록을 바탕으로 조회하기
List<Region> response = new ArrayList<>();


regionList.forEach(favorite -> {
String regionCode = favorite.getRegionCode();
Region region = regionPort.loadRegion(regionCode)
.orElseThrow(() -> new NoSuchElementException(ErrorCode.NOT_REGION.getMessage()));

response.add(region);
});

return response;
}

@Override
public List<RegionPrice> getFavoriteRegionPrices(Long userId) {

/// 유저 예외 처리
if (userPort.checkExistingById(userId)) {
throw new NoSuchElementException(ErrorCode.NOT_USER.getMessage());
}

/// 유저의 관심 지역 목록 조회하기
List<Favorite> regionList = favoritePort.loadUserFavoriteByType(userId, FavoriteType.REGION);

/// 관심 지역 목록을 바탕으로 가격 조회하기
List<RegionPrice> response = new ArrayList<>();

regionList.forEach(region -> {
String regionCode = region.getRegionCode();
RegionPrice regionPrice = regionPricePort.loadRegionPriceByCode(regionCode)
.orElseThrow(() -> new NoSuchElementException(ErrorCode.NOT_REGION_PRICE.getMessage()));

response.add(regionPrice);
});

return response;
}


/// 나의 관심 아파트 조회
@Override
public List<Estate> getFavoriteEstates(Long userId) {
/// 유저 예외 처리
if (userPort.checkExistingById(userId)) {
throw new NoSuchElementException(ErrorCode.NOT_USER.getMessage());
}

/// 유저의 관심 목록 조회하기
List<Favorite> estateList = favoritePort.loadUserFavoriteByType(userId, FavoriteType.APARTMENT);

/// 유저 관련 아파트 조회
List<Estate> response = new ArrayList<>();


estateList.forEach(favorite -> {
String kaptCode = favorite.getKaptCode();
Estate estate = loadEstatePort.loadEstateByCode(kaptCode)
.orElseThrow(() -> new NoSuchElementException(ErrorCode.NOT_ESTATE.getMessage()));
response.add(estate);
});

return response;
}


@Override
public List<EstatePrice> getFavoriteEstatePrice(Long userId) {

/// 유저 예외 처리
if (userPort.checkExistingById(userId)) {
throw new NoSuchElementException(ErrorCode.NOT_USER.getMessage());
}

/// 유저의 관심 목록 조회하기
List<Favorite> regionList = favoritePort.loadUserFavoriteByType(userId, FavoriteType.APARTMENT);

/// 관심 아파트 목록을 바탕으로 가격 조회하기
// flatMap을 통해 새롭게 정의 해봄
return regionList.stream()
.map(Favorite::getKaptCode)
.map(estatePricePort::loadAllEstatePrices)
.flatMap(List::stream)
.toList();
}


/// 나의 소유 아파트 조회
@Override
public List<EstatePrice> getMyEstatePrices(Long userId) {

/// 유저 예외 처리
if (userPort.checkExistingById(userId)) {
throw new NoSuchElementException(ErrorCode.NOT_USER.getMessage());
}

/// 나의 주거지 인증 아파트 목록 조회
List<EstateOwnership> ownerships = estateOwnerShipPort.loadMyOwnerships(userId);

return ownerships.stream()
.map(EstateOwnership::getKaptCode)
.map(estatePricePort::loadAllEstatePrices)
.flatMap(List::stream)
.toList();
}
}
Loading