Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -2,6 +2,7 @@

import com.pinHouse.server.core.response.response.ApiResponse;
import com.pinHouse.server.platform.adapter.in.web.dto.response.NoticeSupplyDTO;
import com.pinHouse.server.platform.adapter.in.web.swagger.DepositApiSpec;
import com.pinHouse.server.platform.application.in.NoticeUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -12,7 +13,7 @@
@RestController
@RequestMapping("/api/v1/notices/deposit")
@RequiredArgsConstructor
public class DepositApi {
public class DepositApi implements DepositApiSpec {

private final NoticeUseCase noticeService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pinHouse.server.platform.adapter.in.web;

import com.pinHouse.server.platform.adapter.in.web.swagger.DistanceApiSpec;
import com.pinHouse.server.platform.application.out.distance.DistancePort;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -9,7 +10,7 @@
@RestController
@RequestMapping("/api/v1/distance")
@RequiredArgsConstructor
public class DistanceApi {
public class DistanceApi implements DistanceApiSpec {

private final DistancePort distancePort;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.pinHouse.server.platform.adapter.in.web;

import com.pinHouse.server.core.response.response.ApiResponse;
import com.pinHouse.server.platform.adapter.in.web.dto.FacilityType;
import com.pinHouse.server.platform.adapter.in.web.dto.response.InfraDTO;
import com.pinHouse.server.platform.adapter.in.web.dto.response.NoticeDTO;
import com.pinHouse.server.platform.adapter.in.web.swagger.NoticeInfraApiSpec;
import com.pinHouse.server.platform.application.in.NoticeInfraUseCase;
import com.pinHouse.server.platform.domain.notice.Notice;
import com.pinHouse.server.platform.domain.notice.NoticeInfra;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/v1/notices/infra")
Expand All @@ -35,6 +36,17 @@ public ApiResponse<InfraDTO.NoticeInfraResponse> showNotice(
}

/// 원하는 인프라를 바탕으로 많이 존재하는 지역을 설정
@GetMapping("/type")
public ApiResponse<List<NoticeDTO.NoticeListResponse>> showNoticeList(
@RequestParam List<FacilityType> facilityTypes
) {
// 1. 시설 타입별로 지역(행정동 등)별 시설 수 집계
List<Notice> notices = service.getNoticesByInfraTypesWithAllMinCount(facilityTypes);

// 4. 응답 DTO 구성
List<NoticeDTO.NoticeListResponse> responses = NoticeDTO.NoticeListResponse.from(notices);

return ApiResponse.ok(responses);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pinHouse.server.platform.adapter.in.web.dto;

public enum FacilityType {

LIBRARY, // 도서관
PARK, // 공원
ANIMAL, // 동물 관련 시설
WALKING, // 산책로
SPORT // 스포츠 시설

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pinHouse.server.platform.adapter.in.web.swagger;

import com.pinHouse.server.core.response.response.ApiResponse;
import com.pinHouse.server.platform.adapter.in.web.dto.response.NoticeSupplyDTO;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Tag(name = "예산 시뮬레이터 API", description = "보증금/최대전환월세를 계산하는 API입니다.")
public interface DepositApiSpec {

@PutMapping("/{noticeId}")
ApiResponse<NoticeSupplyDTO.NoticeLeaseOptionResponse> update(

@Parameter(example = "18384", description = "공고 ID")
@PathVariable String noticeId,

@Parameter(example = "26A", description = "주거 타입")
@RequestParam String housingType,

@Parameter(example = "0.001", description = "변환율")
@RequestParam double percentage);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pinHouse.server.platform.adapter.in.web.swagger;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.UnsupportedEncodingException;

@Tag(name = "거리 시뮬레이터 API", description = "원하는 주소를 바탕으로 대중교통 시뮬레이터를 하는 API입니다.")
public interface DistanceApiSpec {

@Operation(
summary = "거리 시뮬레이터 API",
description = "출발 좌표와 도착 좌표를 통해 계산을 진행합니다.")
@GetMapping()
String getDistance(
@RequestParam double startY,
@RequestParam double startX,
@RequestParam double endY,
@RequestParam double endX
) throws UnsupportedEncodingException;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.pinHouse.server.platform.adapter.in.web.swagger;

import com.pinHouse.server.core.response.response.ApiResponse;
import com.pinHouse.server.platform.adapter.in.web.dto.FacilityType;
import com.pinHouse.server.platform.adapter.in.web.dto.response.InfraDTO;
import com.pinHouse.server.platform.adapter.in.web.dto.response.NoticeDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Tag(name = "공고 주변 인프라 API", description = "인프라를 바탕으로 조회하는 API 입니다.")
public interface NoticeInfraApiSpec {
Expand All @@ -19,4 +24,13 @@ public interface NoticeInfraApiSpec {
ApiResponse<InfraDTO.NoticeInfraResponse> showNotice(
@Parameter(example = "18407")
@PathVariable String noticeId);

@Operation(
summary = "인프라에 따른 공고 조회 API",
description = "해당 인프라가 2개 이상 존재하는 공고를 조회하는 API입니다."
)
@GetMapping("/type")
ApiResponse<List<NoticeDTO.NoticeListResponse>> showNoticeList(
@RequestParam List<FacilityType> facilityTypes
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
Expand All @@ -35,4 +36,12 @@ public Optional<Notice> loadById(String noticeId) {
return repository.findByNoticeId(noticeId)
.map(NoticeDocument::toDomain);
}

@Override
public List<Notice> loadAllNotices() {
return repository.findAll().stream()
.map(NoticeDocument::toDomain)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.pinHouse.server.platform.application.in;

import com.pinHouse.server.platform.adapter.in.web.dto.FacilityType;
import com.pinHouse.server.platform.domain.notice.Notice;
import com.pinHouse.server.platform.domain.notice.NoticeInfra;

import java.util.List;

/**
* - 공고 주변의 인프라 목록 조회할 인터페이스
*/
Expand All @@ -13,5 +16,5 @@ public interface NoticeInfraUseCase {
NoticeInfra getNoticeInfraById(String noticeId);

// 원하는 인프라 바탕으로 많이 존재하는 공고 조회
Notice getNoticeByInfra();
List<Notice> getNoticesByInfraTypesWithAllMinCount(List<FacilityType> facilityTypes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Optional;
import java.util.*;

/**
* DB에 넣는 포트를 정의한 인터페이스입니다.
Expand All @@ -19,4 +19,7 @@ public interface NoticePort {
/// 상세 조회
Optional<Notice> loadById(String id);

/// 모든 공고 가져오기
List<Notice> loadAllNotices();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pinHouse.server.platform.application.service;

import com.pinHouse.server.core.response.response.ErrorCode;
import com.pinHouse.server.platform.adapter.in.web.dto.FacilityType;
import com.pinHouse.server.platform.application.in.NoticeInfraUseCase;
import com.pinHouse.server.platform.application.out.facility.FacilityPort;
import com.pinHouse.server.platform.application.out.notice.NoticePort;
Expand Down Expand Up @@ -78,17 +79,32 @@ public NoticeInfra getNoticeInfraById(String noticeId) {
return NoticeInfra.of(notice, libraries, animals, sports, walkings, parks);
}

///
@Override
public Notice getNoticeByInfra() {
return null;
}

// =================
// 인프라 바탕으로 공고 조회
// =================


@Override
public List<Notice> getNoticesByInfraTypesWithAllMinCount(List<FacilityType> facilityTypes) {
List<Notice> allNotices = noticePort.loadAllNotices();

return allNotices.stream()
.filter(notice -> {
double lng = notice.getLocation().getLongitude();
double lat = notice.getLocation().getLatitude();

// 모든 종류가 2개 이상이어야만 true 반환
return facilityTypes.stream().allMatch(facilityType -> {
List<? extends Facility> facilityList = switch (facilityType) {
case LIBRARY -> facilityPort.loadLibrariesNearBy(lng, lat, radiusInRadians);
case PARK -> facilityPort.loadParksNearBy(lng, lat, radiusInRadians);
case ANIMAL -> facilityPort.loadAnimalsNearBy(lng, lat, radiusInRadians);
case WALKING -> facilityPort.loadWalkingsNearBy(lng, lat, radiusInRadians);
case SPORT -> facilityPort.loadSportsNearBy(lng, lat, radiusInRadians);
};
return facilityList.size() >= 2;
});
})
.toList();
}


// =================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Animal {
public class Animal implements Facility{

/// 아이디
private String id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.pinHouse.server.platform.domain.facility;

import com.pinHouse.server.platform.domain.location.Location;

public interface Facility {

/**
* 시설의 위치 정보를 반환합니다.
* @return 시설 위치 객체
*/
Location getLocation();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Library {
public class Library implements Facility{

private String id;
private Integer code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
@AllArgsConstructor
@Builder
public class Park {
public class Park implements Facility{

/// 아이디
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Sport {
public class Sport implements Facility{

private String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Walking {
public class Walking implements Facility{

private String id;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.pinHouse.server.platform.domain.notice;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class NoticeCount {

private String noticeId;

private int libraryCount;

private int animalCount;

private int parkCount;

private int sportCount;

private int walkCount;

/// 정적 팩토리 메서드
public NoticeCount of(String noticeId, int libraryCount, int animalCount, int parkCount, int sportCount) {
return NoticeCount.builder()
.noticeId(noticeId)
.libraryCount(libraryCount)
.animalCount(animalCount)
.parkCount(parkCount)
.sportCount(sportCount)
.build();
}
}
Loading