diff --git a/src/main/java/com/doubleo/hospitalservice/domain/area/controller/AreaController.java b/src/main/java/com/doubleo/hospitalservice/domain/area/controller/AreaController.java index 39ef4f5..7e17149 100644 --- a/src/main/java/com/doubleo/hospitalservice/domain/area/controller/AreaController.java +++ b/src/main/java/com/doubleo/hospitalservice/domain/area/controller/AreaController.java @@ -5,6 +5,8 @@ import io.swagger.v3.oas.annotations.Operation; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; @RestController @@ -19,4 +21,15 @@ public class AreaController { public List areaListGetByBuildingId(@PathVariable Long buildingId) { return areaService.getAreaListByBuildingId(buildingId); } + + @GetMapping("/{buildingId}/areas/paged") + @Operation( + summary = "Get Paged Areas by Building ID", + description = "건물 ID로 구역 리스트 조회 - 페이지네이션") + public Page pagedAreaListGetByBuildingId( + @PathVariable Long buildingId, + @RequestParam(required = false) String keyword, + Pageable pageable) { + return areaService.pagedAreaListGetByBuildingId(buildingId, keyword, pageable); + } } diff --git a/src/main/java/com/doubleo/hospitalservice/domain/area/repository/AreaRepository.java b/src/main/java/com/doubleo/hospitalservice/domain/area/repository/AreaRepository.java index db53e53..d7476e0 100644 --- a/src/main/java/com/doubleo/hospitalservice/domain/area/repository/AreaRepository.java +++ b/src/main/java/com/doubleo/hospitalservice/domain/area/repository/AreaRepository.java @@ -3,10 +3,17 @@ import com.doubleo.hospitalservice.domain.area.domain.Area; import java.util.List; import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface AreaRepository extends JpaRepository { List findAllByBuilding_BuildingId(Long buildingId); + Page findByBuilding_BuildingId(Long buildingId, Pageable pageable); + Optional findByTenantIdAndAreaCode(String tenantId, String areaCode); + + Page findByBuilding_BuildingIdAndAreaNameContainingIgnoreCase( + Long buildingId, String keyword, Pageable pageable); } diff --git a/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaService.java b/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaService.java index 2333b25..1b5c9f9 100644 --- a/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaService.java +++ b/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaService.java @@ -2,7 +2,12 @@ import com.doubleo.hospitalservice.domain.area.dto.response.AreaInfoResponse; import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; public interface AreaService { List getAreaListByBuildingId(Long buildingId); + + Page pagedAreaListGetByBuildingId( + Long buildingId, String keyword, Pageable pageable); } diff --git a/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaServiceImpl.java b/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaServiceImpl.java index 1bee7d1..ceb8d36 100644 --- a/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaServiceImpl.java +++ b/src/main/java/com/doubleo/hospitalservice/domain/area/service/AreaServiceImpl.java @@ -1,13 +1,17 @@ package com.doubleo.hospitalservice.domain.area.service; +import com.doubleo.hospitalservice.domain.area.domain.Area; import com.doubleo.hospitalservice.domain.area.dto.response.AreaInfoResponse; import com.doubleo.hospitalservice.domain.area.repository.AreaRepository; import com.doubleo.hospitalservice.domain.building.repository.BuildingRepository; +import com.doubleo.hospitalservice.global.config.util.TenantValidator; import com.doubleo.hospitalservice.global.exception.CommonException; import com.doubleo.hospitalservice.global.exception.errorcode.BuildingErrorCode; import jakarta.transaction.Transactional; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service @@ -17,6 +21,7 @@ public class AreaServiceImpl implements AreaService { private final AreaRepository areaRepository; private final BuildingRepository buildingRepository; + private final TenantValidator tenantValidator; public List getAreaListByBuildingId(Long buildingId) { @@ -30,4 +35,26 @@ public List getAreaListByBuildingId(Long buildingId) { .map(AreaInfoResponse::from) .toList(); } + + public Page pagedAreaListGetByBuildingId( + Long buildingId, String keyword, Pageable pageable) { + + String tenantId = tenantValidator.getTenantId(); + + if (!buildingRepository.existsByTenantIdAndBuildingId(tenantId, buildingId)) { + throw new CommonException(BuildingErrorCode.BUILDING_NOT_FOUND); + } + + Page areaPage; + + if (keyword == null || keyword.isBlank()) { + areaPage = areaRepository.findByBuilding_BuildingId(buildingId, pageable); + } else { + areaPage = + areaRepository.findByBuilding_BuildingIdAndAreaNameContainingIgnoreCase( + buildingId, keyword, pageable); + } + + return areaPage.map(AreaInfoResponse::from); + } } diff --git a/src/main/java/com/doubleo/hospitalservice/domain/building/repository/BuildingRepository.java b/src/main/java/com/doubleo/hospitalservice/domain/building/repository/BuildingRepository.java index d0c5e44..37c6e5f 100644 --- a/src/main/java/com/doubleo/hospitalservice/domain/building/repository/BuildingRepository.java +++ b/src/main/java/com/doubleo/hospitalservice/domain/building/repository/BuildingRepository.java @@ -18,4 +18,6 @@ Page findByTenantIdAndBuildingNameContainingIgnoreCase( String tenantId, String keyWord, Pageable pageable); Optional findByTenantIdAndBuildingCode(String tenantId, String buildingCode); + + boolean existsByTenantIdAndBuildingId(String tenantId, Long buildingId); } diff --git a/src/main/java/com/doubleo/hospitalservice/global/config/web/WebConfig.java b/src/main/java/com/doubleo/hospitalservice/global/config/web/WebConfig.java index a364fb1..fd8b52f 100644 --- a/src/main/java/com/doubleo/hospitalservice/global/config/web/WebConfig.java +++ b/src/main/java/com/doubleo/hospitalservice/global/config/web/WebConfig.java @@ -15,7 +15,7 @@ public void addArgumentResolvers(List resolvers) PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver(); resolver.setMaxPageSize(500); - resolver.setFallbackPageable(PageRequest.of(0, 10)); + resolver.setFallbackPageable(PageRequest.of(0, 5)); resolvers.add(resolver); } }