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
@@ -0,0 +1,40 @@
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.response.InfraDTO;
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.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;

@RestController
@RequestMapping("/api/v1/notices/infra")
@RequiredArgsConstructor
public class NoticeInfraApi implements NoticeInfraApiSpec {

/// 서비스 의존성
private final NoticeInfraUseCase service;

/// 주변 인프라 조회
@GetMapping("/{noticeId}")
public ApiResponse<InfraDTO.NoticeInfraResponse> showNotice(
@PathVariable String noticeId) {

/// 서비스 계층
NoticeInfra noticeInfra = service.getNoticeInfraById(noticeId);

/// DTO 수정
InfraDTO.NoticeInfraResponse response = InfraDTO.NoticeInfraResponse.from(noticeInfra);

/// 응답
return ApiResponse.ok(response);
}

/// 원하는 인프라를 바탕으로 많이 존재하는 지역을 설정


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

import com.pinHouse.server.platform.domain.facility.*;
import com.pinHouse.server.platform.domain.notice.NoticeInfra;
import io.micrometer.common.lang.Nullable;
import lombok.Builder;
import java.util.List;

/**
* 인프라 관련 응답 DTO 클래스입니다.
*/
public record InfraDTO() {

/**
* 도서관 정보 응답 객체입니다.
*
* @param libraryName 도서관 이름
* @param address 도서관 주소
*/

@Builder
public record LibraryResponse(
String libraryName,
String address
) {

/// 정적 팩토리 메서드
public static LibraryResponse from(Library library) {
return LibraryResponse.builder()
.libraryName(library.getName())
.address(library.getAddress())
.build();
}

/// 정적 팩토리 메서드
public static List<LibraryResponse> from(List<Library> libraries) {
return libraries.stream()
.map(LibraryResponse::from)
.toList();
}
}

/**
* 동물 관련 시설 응답 객체입니다.
*
* @param name 시설명
* @param category 카테고리명
*/
@Builder
public record AnimalResponse(
String name,
String category,
String address
) {
/** 도메인 Animal → 응답 객체 변환 */
public static AnimalResponse from(Animal animal) {
return AnimalResponse.builder()
.name(animal.getName())
.category(animal.getCategory())
.address(animal.getAddress())
.build();
}

/** 도메인 List<Animal> → 응답 목록 변환 */
public static List<AnimalResponse> from(List<Animal> animals) {
return animals.stream()
.map(AnimalResponse::from)
.toList();
}
}

/**
* 스포츠 시설 응답 객체입니다.
*
* @param name 시설명
* @param type 시설 유형명
*/
@Builder
public record SportResponse(
String name,
String type,
String address
) {
/** 도메인 Sport → 응답 객체 변환 */
public static SportResponse from(Sport sport) {
return SportResponse.builder()
.name(sport.getName())
.type(sport.getFacilityTypeName())
.address(sport.getAddress())
.build();
}

/** 도메인 List<Sport> → 응답 목록 변환 */
public static List<SportResponse> from(List<Sport> sports) {
return sports.stream()
.map(SportResponse::from)
.toList();
}
}

/**
* 공원 시설 응답 객체입니다.
*
* @param name 공원 명칭
* @param category 분류명
*/
@Builder
public record ParkResponse(
String name,
String category
) {
/** 도메인 Park → 응답 객체 변환 */
public static ParkResponse from(Park park) {
return ParkResponse.builder()
.name(park.getName())
.category(park.getCategory())
.build();
}

/** 도메인 List<Park> → 응답 목록 변환 */
public static List<ParkResponse> from(List<Park> parks) {
return parks.stream()
.map(ParkResponse::from)
.toList();
}
}

/**
* 산책로 정보 응답 객체입니다.
*
* @param name 코스명
* @param level 난이도
*/
@Builder
public record WalkingResponse(
String name,
String level,
String address
) {
/** 도메인 Walking → 응답 객체 변환 */
public static WalkingResponse from(Walking walking) {
return WalkingResponse.builder()
.name(walking.getWalkingCourseName())
.level(walking.getCourseLevelName())
.address(walking.getAddress())
.build();
}

/** 도메인 List<Walking> → 응답 목록 변환 */
public static List<WalkingResponse> from(List<Walking> walkings) {
return walkings.stream()
.map(WalkingResponse::from)
.toList();
}
}

/**
* 공지 인프라 통합 응답 객체입니다.
*
* @param libraries 도서관 응답 목록
* @param animals 동물 응답 목록
* @param sports 스포츠 응답 목록
* @param parks 공원 응답 목록
* @param walkings 산책로 응답 목록
*/
@Builder
public record NoticeInfraResponse(
@Nullable List<LibraryResponse> libraries,
@Nullable List<AnimalResponse> animals,
@Nullable List<SportResponse> sports,
@Nullable List<ParkResponse> parks,
@Nullable List<WalkingResponse> walkings
) {
/** NoticeInfra → 응답 DTO로 일괄 변환 */
public static NoticeInfraResponse from(NoticeInfra noticeInfra) {
return NoticeInfraResponse.builder()
.libraries(LibraryResponse.from(noticeInfra.getLibraries()))
.animals(AnimalResponse.from(noticeInfra.getAnimals()))
.sports(SportResponse.from(noticeInfra.getSports()))
.parks(ParkResponse.from(noticeInfra.getParks()))
.walkings(WalkingResponse.from(noticeInfra.getWalkings()))
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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.InfraDTO;
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;

@Tag(name = "공고 주변 인프라 API", description = "인프라를 바탕으로 조회하는 API 입니다.")
public interface NoticeInfraApiSpec {

@Operation(
summary = "공고 주변 인프라 조회 API",
description = "공고 주변 3KM내 존재하는 인프라를 확인하는 API입니다."
)
@GetMapping("/{noticeId}")
ApiResponse<InfraDTO.NoticeInfraResponse> showNotice(
@Parameter(example = "18407")
@PathVariable String noticeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.pinHouse.server.platform.adapter.out;

import com.pinHouse.server.platform.adapter.out.mongo.facility.*;
import com.pinHouse.server.platform.application.out.facility.FacilityPort;
import com.pinHouse.server.platform.domain.facility.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class FacilityMongoAdapter implements FacilityPort {

/// 외부 의존성
private final LibraryDocumentRepository libraryRepository;
private final ParkDocumentRepository parkRepository;
private final SportDocumentRepository sportRepository;
private final WalkingDocumentRepository walkingRepository;
private final AnimalDocumentRepository animalRepository;

@Override
public List<Library> loadLibrariesNearBy(double longitude, double latitude, double radiusInKm) {
return libraryRepository.findByLocation(longitude, latitude,radiusInKm).stream()
.map(LibraryDocument::toDomain)
.toList();
}

@Override
public List<Park> loadParksNearBy(double longitude, double latitude, double radiusInKm) {
return parkRepository.findByLocation(longitude, latitude,radiusInKm).stream()
.map(ParkDocument::toDomain)
.toList();
}

@Override
public List<Sport> loadSportsNearBy(double longitude, double latitude, double radiusInKm) {
return sportRepository.findByLocation(longitude, latitude,radiusInKm).stream()
.map(SportDocument::toDomain)
.toList();
}

@Override
public List<Walking> loadWalkingsNearBy(double longitude, double latitude, double radiusInKm) {
return walkingRepository.findByLocation(longitude, latitude,radiusInKm).stream()
.map(WalkingDocument::toDomain)
.toList();
}

@Override
public List<Animal> loadAnimalsNearBy(double longitude, double latitude, double radiusInKm) {
return animalRepository.findByLocation(longitude, latitude,radiusInKm).stream()
.map(AnimalDocument::toDomain)
.toList();
}
}
Loading
Loading