Skip to content

Commit

Permalink
[Feat] Keyneez#46 - 저장 탭 API 연결 성공
Browse files Browse the repository at this point in the history
  • Loading branch information
kpk0616 committed Jan 13, 2023
1 parent 6593fb2 commit df94cb4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Keyneez/Keyneez/Global/NetworkLayer/ContentAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ extension ContentAPI: TargetType {
case .getSearchContent:
return URLConstant.searchContent
case .postLikeContent:
return URLConstant.likeContent
case .getLikedContent:
return URLConstant.saveContent
case .getLikedContent:
return URLConstant.likeContent
}
}

Expand Down
4 changes: 2 additions & 2 deletions Keyneez/Keyneez/Global/NetworkLayer/ContentAPIProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ final class ContentAPIProvider {
let target = ContentAPI.getDetailContent(token: token, contentId: contentId)
requestFrom(target, modelType: ContentDetailResponseDto.self, completion: completion)
}
func getLikedContent(token: String, completion: @escaping (Result<LikeContentResponseDto?, Error>) -> Void) {
func getLikedContent(token: String, completion: @escaping (Result<[MyLikedContentResponseDto]?, Error>) -> Void) {
let target = ContentAPI.getLikedContent(token: token)
requestFrom(target, modelType: LikeContentResponseDto.self, completion: completion)
requestFrom(target, modelType: [MyLikedContentResponseDto].self, completion: completion)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Foundation

struct MyLikedContentResponseDto: Codable {
let contentKey: Int
let contentTitle,
startAt,
let contentTitle: String
let startAt,
endAt,
contentImg: String
contentImg: String?
}
4 changes: 2 additions & 2 deletions Keyneez/Keyneez/Tab/Home/ContentRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol ContentRepository {
func getAllContents(token: String, completion: @escaping([HomeContentResponseDto]) -> Void)
func getDetailContent(token: String, contentId: Int, completion: @escaping(ContentDetailResponseDto) -> Void)
func getSearchContent(token: String, keyword: String, completion: @escaping([SearchContentResponseDto]) -> Void)
func getLikedContent(token: String, completion: @escaping([LikeContentResponseDto]) -> Void)
func getLikedContent(token: String, completion: @escaping([MyLikedContentResponseDto]) -> Void)
}

final class KeyneezContentRepository: ContentRepository {
Expand Down Expand Up @@ -52,7 +52,7 @@ final class KeyneezContentRepository: ContentRepository {
}
}

func getLikedContent(token: String, completion: @escaping ([LikeContentResponseDto]) -> Void) {
func getLikedContent(token: String, completion: @escaping ([MyLikedContentResponseDto]) -> Void) {
ContentAPIProvider.shared.getLikedContent(token: token) { result in
switch result {
case .success(let data):
Expand Down
18 changes: 10 additions & 8 deletions Keyneez/Keyneez/Tab/Like/LikeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UIKit

final class LikeViewController: NiblessViewController, NavigationBarProtocol {
let repository: ContentRepository = KeyneezContentRepository()
var likedContentDataSource: [MyLikedContentResponseDto] = []

lazy var navigationView: UIView = NavigationViewBuilder(barViews: [.button(with: myLikeButton), .flexibleBox, .iconButton(with: editButton)]).build()
private lazy var myLikeButton: UIButton = .init(primaryAction: touchUpMyLikeButton).then {
Expand Down Expand Up @@ -57,14 +58,15 @@ final class LikeViewController: NiblessViewController, NavigationBarProtocol {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
guard let token = UserSession.shared.accessToken else { return }
repository.get(token: token, keyword: keyword!) {
[weak self] arr in
repository.getLikedContent(token: token) {
[weak self] result in
guard let self else {return}
self.searchDatasource = arr
self.setSearchResultCountingLabel(count: searchDatasource.count)
self.likedContentDataSource = result
DispatchQueue.main.async {
self.homeSearchCollectionView.reloadData()
self.likeCollectionView.reloadData()
}
}
}
}

extension LikeViewController {
Expand Down Expand Up @@ -118,13 +120,13 @@ extension LikeViewController: UICollectionViewDelegateFlowLayout {
// MARK: - UICollectionViewDataSource
extension LikeViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return homeSearchList.count
return likedContentDataSource.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let homeSearchCell = collectionView.dequeueReusableCell(
guard let likedContentCell = collectionView.dequeueReusableCell(
withReuseIdentifier: HomeSearchCollectionViewCell.identifier, for: indexPath)
as? HomeSearchCollectionViewCell else { return UICollectionViewCell() }
// homeSearchCell.bindHomeSearchData(model: homeSearchList[indexPath.item])
return homeSearchCell
return likedContentCell
}
}

0 comments on commit df94cb4

Please sign in to comment.