-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccaae90
commit e3b83a9
Showing
8 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
iOS/Projects/Features/Home/Sources/Data/FeedRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// FeedRepository.swift | ||
// HomeFeature | ||
// | ||
// Created by MaraMincho on 12/7/23. | ||
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import CommonNetworkingKeyManager | ||
import Foundation | ||
import Trinet | ||
|
||
// MARK: - FeedRepository | ||
|
||
public struct FeedRepository: FeedRepositoryRepresentable { | ||
let decoder = JSONDecoder() | ||
let provider: TNProvider<FeedEndPoint> | ||
init(session: URLSessionProtocol = URLSession.shared) { | ||
provider = .init(session: session) | ||
} | ||
|
||
public func fetchFeed(at page: Int) -> AnyPublisher<[FeedElement], Never> { | ||
return Future<[FeedElement], Error> { promise in | ||
Task { [provider] in | ||
do { | ||
let data = try await provider.request(.fetchPosts(page: page), interceptor: TNKeychainInterceptor.shared) | ||
let feedElementList = try decoder.decode([FeedElement].self, from: data) | ||
promise(.success(feedElementList)) | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
} | ||
.catch { _ in return Empty() } | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
|
||
// MARK: - FeedEndPoint | ||
|
||
public enum FeedEndPoint: TNEndPoint { | ||
case fetchPosts(page: Int) | ||
public var path: String { | ||
return "" | ||
} | ||
|
||
public var method: TNMethod { | ||
return .post | ||
} | ||
|
||
public var query: Encodable? { | ||
return nil | ||
} | ||
|
||
public var body: Encodable? { | ||
switch self { | ||
case let .fetchPosts(page): | ||
return page | ||
} | ||
} | ||
|
||
public var headers: TNHeaders { | ||
return .default | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ojects/Features/Home/Sources/Domain/RepositoryInterface/FeedRepositoryRepresentable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// FeedRepositoryRepresentable.swift | ||
// HomeFeature | ||
// | ||
// Created by MaraMincho on 1/2/24. | ||
// Copyright © 2024 kr.codesquad.boostcamp8. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
// MARK: - FeedRepositoryRepresentable | ||
|
||
public protocol FeedRepositoryRepresentable { | ||
func fetchFeed(at page: Int) -> AnyPublisher<[FeedElement], Never> | ||
} |
11 changes: 0 additions & 11 deletions
11
...tures/Home/Sources/Presntaion/HomeScene/ViewController/HomeViewController+Extension.swift
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...ces/Presntaion/HomeScene/ViewController/HomeViewController+UICollectionViewDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// HomeViewController+UICollectionViewDelegate.swift | ||
// HomeFeature | ||
// | ||
// Created by MaraMincho on 1/2/24. | ||
// Copyright © 2024 kr.codesquad.boostcamp8. All rights reserved. | ||
// | ||
|
||
import Log | ||
import UIKit | ||
|
||
extension HomeViewController: UICollectionViewDelegate { | ||
func scrollViewDidEndDragging(_: UIScrollView, willDecelerate _: Bool) { | ||
Log.make().debug("스크롤 끝남") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters