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 @@ -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
Expand All @@ -19,4 +21,15 @@ public class AreaController {
public List<AreaInfoResponse> areaListGetByBuildingId(@PathVariable Long buildingId) {
return areaService.getAreaListByBuildingId(buildingId);
}

@GetMapping("/{buildingId}/areas/paged")
@Operation(
summary = "Get Paged Areas by Building ID",
description = "건물 ID로 구역 리스트 조회 - 페이지네이션")
public Page<AreaInfoResponse> pagedAreaListGetByBuildingId(
@PathVariable Long buildingId,
@RequestParam(required = false) String keyword,
Pageable pageable) {
return areaService.pagedAreaListGetByBuildingId(buildingId, keyword, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Area, Long> {
List<Area> findAllByBuilding_BuildingId(Long buildingId);

Page<Area> findByBuilding_BuildingId(Long buildingId, Pageable pageable);

Optional<Area> findByTenantIdAndAreaCode(String tenantId, String areaCode);

Page<Area> findByBuilding_BuildingIdAndAreaNameContainingIgnoreCase(
Long buildingId, String keyword, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AreaInfoResponse> getAreaListByBuildingId(Long buildingId);

Page<AreaInfoResponse> pagedAreaListGetByBuildingId(
Long buildingId, String keyword, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +21,7 @@ public class AreaServiceImpl implements AreaService {

private final AreaRepository areaRepository;
private final BuildingRepository buildingRepository;
private final TenantValidator tenantValidator;

public List<AreaInfoResponse> getAreaListByBuildingId(Long buildingId) {

Expand All @@ -30,4 +35,26 @@ public List<AreaInfoResponse> getAreaListByBuildingId(Long buildingId) {
.map(AreaInfoResponse::from)
.toList();
}

public Page<AreaInfoResponse> pagedAreaListGetByBuildingId(
Long buildingId, String keyword, Pageable pageable) {

String tenantId = tenantValidator.getTenantId();

if (!buildingRepository.existsByTenantIdAndBuildingId(tenantId, buildingId)) {
throw new CommonException(BuildingErrorCode.BUILDING_NOT_FOUND);
}

Page<Area> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Page<Building> findByTenantIdAndBuildingNameContainingIgnoreCase(
String tenantId, String keyWord, Pageable pageable);

Optional<Building> findByTenantIdAndBuildingCode(String tenantId, String buildingCode);

boolean existsByTenantIdAndBuildingId(String tenantId, Long buildingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
PageableHandlerMethodArgumentResolver resolver =
new PageableHandlerMethodArgumentResolver();
resolver.setMaxPageSize(500);
resolver.setFallbackPageable(PageRequest.of(0, 10));
resolver.setFallbackPageable(PageRequest.of(0, 5));
resolvers.add(resolver);
}
}