Skip to content

Commit

Permalink
Refactor: api 연결 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JEONG-J committed May 9, 2024
1 parent b3c6637 commit 116136b
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions ttubeokAR/ttubeokAR/ExploreView/ExploreDetail/DetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,56 @@ class DetailViewModel: NSObject, ObservableObject,CLLocationManagerDelegate {
}

// MARK: - ScrollProperty
@Published var currentPage: Int = 0
var currentPage: Int = 0
var isLoading: Bool = false

//MARK: - API Fetch 함수
/// 장소 타입에 맞춰 API 호출
/// - Parameter place: 전달 받은 장소 타입
public func fetchDetails(for place: ExploreDetailInfor) {
self.placeType = place.placeType.spot ? .spot : .store
self.placeId = place.placeId

guard let placeId = self.placeId else {
print("placeId nil 저장됨")
return
}


if place.placeType.spot {
self.placeType = .spot
self.placeId = place.placeId
walkWayGet(get: placeId ?? 0)

walkWayGet(get: placeId)
}
else if place.placeType.store {
self.placeType = .store
self.placeId = place.placeId
storeGet(get: placeId ?? 0)
self.placeId = place.placeId
storeGet(get: placeId)
}
}

//MARK: - 방명록 API Fetch 함수

/// 방명록 카드 스크롤 API 호출
/// - Parameter page: 페이징을 값 입력
public func fetchScrollData(page: Int) {
private func fetchScrollData(page: Int) {
if placeType == .spot {

getSpotData(page: page, placeId: placeId ?? 0)
} else if placeType == .store {

getStoreData(page: page, placeId: placeId ?? 0)
}
}

/// 방명록 스크롤 다음 페이지 로드
public func nextPageLoading() {
guard !isLoading else { return }
isLoading = true
currentPage += 1
fetchScrollData(page: currentPage)
}

/// 초기 방명록 스크롤 페이지 로드
/// - Parameter page: 다음 페이지 로드
public func initialFetchScroll(page: Int) {
fetchScrollData(page: page)
}

//MARK: - 산책로 상세 조회 처리

/// 선택한 산책로 데이터를 가져온다.
Expand Down

0 comments on commit 116136b

Please sign in to comment.