Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop -> main #159

Merged
merged 2 commits into from
Jun 10, 2024
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 @@ -63,17 +63,12 @@ public ResponseEntity<Response<BranchWithSpaceDto>> getBranchWithSpace(@PathVari
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = Response.class))),
@ApiResponse(responseCode = "404", description = "조회 실패", content = @Content(schema = @Schema(implementation = Response.class)))})
@Operation(summary = "주변 지점 조회", description = "현재 위치 기준 가까운 위치 지점 최대 2개 반환")
@Parameters({
@Parameter(name = "latitude", description = "사용자 위도"),
@Parameter(name = "longitude", description = "사용자 경도")
})
@GetMapping("/distance")
public ResponseEntity<Response<List<BranchDistanceResponseDto>>> getNearBranchesByPosition(
@RequestParam double latitude,
@RequestParam double longitude
@Operation(summary = "주변 지점 조회", description = "현재 이용 지점 기준 가까운 위치 지점 최대 2개 반환")
@GetMapping("/{branchId}/near")
public ResponseEntity<Response<List<BranchDistanceResponseDto>>> getNearBranchesByCurrentBranch(
@PathVariable(name = "branchId") Long branchId
){
return ResponseEntity.ok(Response.success(branchService.getNearBranchByPosition(latitude, longitude)));
return ResponseEntity.ok(Response.success(branchService.getNearBranchesByCurrentBranch(branchId)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.sabujak.branch.dto.response.BranchResponseDto;
import com.example.sabujak.branch.dto.response.BranchWithSpaceDto;
import com.example.sabujak.branch.entity.Branch;
import com.example.sabujak.branch.exception.BranchErrorCode;
import com.example.sabujak.branch.exception.BranchException;
import com.example.sabujak.branch.repository.BranchRepository;
import com.example.sabujak.space.repository.meetingroom.MeetingRoomRepository;
Expand All @@ -16,6 +17,7 @@
import java.util.List;

import static com.example.sabujak.branch.exception.BranchErrorCode.ENTITY_NOT_FOUND_BY_NAME;
import static java.util.function.Predicate.not;

@Service
@Slf4j
Expand Down Expand Up @@ -49,10 +51,17 @@ public BranchWithSpaceDto getBranchWithSpace(LocalDateTime now, String branchNam
return new BranchWithSpaceDto(branch.getBranchId(), branch.getBranchName(),branch.getBranchAddress(),branchTotalMeetingRoomCount,branchActiveMeetingRoomCount);
}

public List<BranchDistanceResponseDto> getNearBranchByPosition(double latitude, double longitude) {
log.info("[BranchService getNearBranch] latitude: {}, longitude: {}", latitude, longitude);
public List<BranchDistanceResponseDto> getNearBranchesByCurrentBranch(Long branchId) {

return branchRepository.findAll().stream().sorted((a, b) -> {

Branch currentBranch = branchRepository.findById(branchId).orElseThrow(() -> new BranchException(BranchErrorCode.BRANCH_NOT_FOUND));
double latitude = currentBranch.getBranchLatitude();
double longitude = currentBranch.getBranchLongitude();
log.info("[BranchService getNearBranchesByCurrentBranch] branchId: {}", currentBranch.getBranchId());

return branchRepository.findAll().stream()
.filter(not(branch -> branch.getBranchId().equals(branchId)))
.sorted((a, b) -> {
double calA = calculateDistance(latitude, longitude, a.getBranchLatitude(), a.getBranchLongitude());
double calB = calculateDistance(latitude, longitude, b.getBranchLatitude(), b.getBranchLongitude());
if (calA < calB)
Expand Down
Loading