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

Chore/#131 북마크 종류 별 정보 조회 API 에러 임시 대응 #136

Merged
merged 1 commit into from
Mar 29, 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
4 changes: 2 additions & 2 deletions Reet-Place/Reet-Place.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@
CODE_SIGN_ENTITLEMENTS = "Reet-Place/Reet-PlaceDebug.entitlements";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = C9U8778A7W;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -1790,7 +1790,7 @@
CODE_SIGN_ENTITLEMENTS = "Reet-Place/Reet-PlaceRelease.entitlements";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = C9U8778A7W;
GENERATE_INFOPLIST_FILE = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class BookmarkTypeCVC: BaseCollectionViewCell {
break
}

countLabel.text = String(typeInfo.cnt)
// TODO: - 북마크 종류 별 정보 조회 API 수정 시 복구
// countLabel.text = String(typeInfo.cnt)
countLabel.isHidden = true

// 북마크가 없으면 기본 이미지 노출
if typeInfo.cnt > 0 {
thumbnailImageView.contentMode = .scaleAspectFill
thumbnailImageView.layer.borderWidth = 0.0

// TODO: - UIImageView+의 setImage 함수 placeholder 파라미터 추가 됨 (임시 코드 - UIImage() 삽입)
thumbnailImageView.setImage(with: typeInfo.thumbnailUrlString)
} else {
thumbnailImageView.contentMode = .scaleAspectFit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class AllBookmarkButton: UIButton {
stackView.addArrangedSubview($0)
}

countLabel.text = String(count)
// TODO: - 북마크 종류 별 정보 조회 API 수정 시 복구
// countLabel.text = String(count)
countLabel.isHidden = true

rightImageView.snp.makeConstraints {
$0.width.equalTo(rightImageView.snp.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ final class BookmarkVC: BaseNavigationViewController {
}

private let viewModel = BookmarkVM()

private var wishListInfo: TypeInfo?
private var historyInfo: TypeInfo?


// MARK: - Life Cycle
Expand Down Expand Up @@ -244,8 +241,6 @@ extension BookmarkVC {
viewModel.output.BookmarkWishlistInfo
.withUnretained(self)
.subscribe(onNext: { owner, data in
owner.wishListInfo = data

DispatchQueue.main.async {
owner.bookmarkTypeCV.reloadData()
}
Expand All @@ -256,8 +251,6 @@ extension BookmarkVC {
viewModel.output.BookmarkHistoryInfo
.withUnretained(self)
.subscribe(onNext: { owner, data in
owner.historyInfo = data

DispatchQueue.main.async {
owner.bookmarkTypeCV.reloadData()
}
Expand Down Expand Up @@ -306,15 +299,12 @@ extension BookmarkVC: UICollectionViewDelegate {
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let wishListInfo = wishListInfo,
let historyInfo = historyInfo else { return }

var bookmarkSearchType: BookmarkSearchType = .want

if indexPath.row == 0 {
guard wishListInfo.cnt != 0 else { return }
guard viewModel.output.BookmarkWishlistInfo.value.cnt != 0 else { return }
} else {
guard historyInfo.cnt != 0 else { return }
guard viewModel.output.BookmarkHistoryInfo.value.cnt != 0 else { return }
bookmarkSearchType = .done
}

Expand All @@ -330,16 +320,12 @@ extension BookmarkVC: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BookmarkTypeCVC.className, for: indexPath) as? BookmarkTypeCVC else { return UICollectionViewCell() }

guard let wishListInfo = wishListInfo,
let historyInfo = historyInfo else { return cell }

if indexPath.row == 0 {
cell.configureData(typeInfo: wishListInfo)
cell.configureData(typeInfo: viewModel.output.BookmarkWishlistInfo.value)
}

if indexPath.row == 1 {
cell.configureData(typeInfo: historyInfo)
cell.configureData(typeInfo: viewModel.output.BookmarkHistoryInfo.value)
}

return cell
Expand Down
55 changes: 46 additions & 9 deletions Reet-Place/Reet-Place/Screen/BookMark/ViewModel/BookmarkVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ final class BookmarkVM: BaseViewModel {

var BookmarkAllCnt = BehaviorRelay<Int>(value: 0)

var BookmarkWishlistInfo = PublishRelay<TypeInfo>()
var BookmarkWishlistInfo = BehaviorRelay<TypeInfo>(value: .init(type: "WANT", cnt: 0, thumbnailUrlString: ""))

var BookmarkHistoryInfo = PublishRelay<TypeInfo>()
var BookmarkHistoryInfo = BehaviorRelay<TypeInfo>(value: .init(type: "GONE", cnt: 0, thumbnailUrlString: ""))
}

init() {
Expand Down Expand Up @@ -69,13 +69,17 @@ extension BookmarkVM: Output {
extension BookmarkVM {

func getBookmarkMock() {
BookmarkMainModel.getMock { [weak self] data in
guard let self = self else { return }

self.output.BookmarkAllCnt.accept(data.bookmarkMainInfo[0].cnt + data.bookmarkMainInfo[1].cnt)
self.output.BookmarkWishlistInfo.accept(data.bookmarkMainInfo[0])
self.output.BookmarkHistoryInfo.accept(data.bookmarkMainInfo[1])
}
// BookmarkMainModel.getMock { [weak self] data in
// guard let self = self else { return }
//
// self.output.BookmarkAllCnt.accept(data.bookmarkMainInfo[0].cnt + data.bookmarkMainInfo[1].cnt)
// self.output.BookmarkWishlistInfo.accept(data.bookmarkMainInfo[0])
// self.output.BookmarkHistoryInfo.accept(data.bookmarkMainInfo[1])
// }
//
// TODO: - 북마크 종류 별 정보 조회 API 수정 시 복구
getBookmarkList(type: .want)
getBookmarkList(type: .done)
}

/// 서버에 북마크 개수 요청
Expand Down Expand Up @@ -104,4 +108,37 @@ extension BookmarkVM {
.disposed(by: bag)
}

// TODO: - 북마크 종류 별 정보 조회 API 수정 시 제거
/// 가고싶어요, 다녀왔어요 북마크를 1 페이지 씩 조회해 존재 여부 확인
func getBookmarkList(type: BookmarkSearchType) {
let page = 0
let path = "/api/bookmarks?searchType=\(type.rawValue)&page=\(page)&size=10&sort=LATEST"
let resource = URLResource<BookmarkListResponseModel>(path: path)

apiSession.requestGet(urlResource: resource)
.withUnretained(self)
.subscribe(onNext: { owner, result in
switch result {
case .success(let data):
let isExist: Bool = !data.content.isEmpty

if type == .want {
if isExist { owner.output.BookmarkAllCnt.accept(100) }
owner.output.BookmarkWishlistInfo
.accept(.init(type: "WANT",
cnt: isExist ? 100 : 0,
thumbnailUrlString: "https://picsum.photos/600/400"))
} else if type == .done {
if isExist { owner.output.BookmarkAllCnt.accept(100) }
owner.output.BookmarkHistoryInfo
.accept(.init(type: "GONE",
cnt: isExist ? 100 : 0,
thumbnailUrlString: "https://picsum.photos/600/300"))
}
case .failure(let error):
owner.apiError.onNext(error)
}
})
.disposed(by: bag)
}
}
Loading