diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/DailySoptuneRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/DailySoptuneRepository.swift index 25791238..d8a965e2 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/DailySoptuneRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/DailySoptuneRepository.swift @@ -30,16 +30,16 @@ public class DailySoptuneRepository { } extension DailySoptuneRepository: DailySoptuneRepositoyInterface { + public func getTodaysFortuneCard() -> AnyPublisher { fortuneService.getTodaysFortuneCard() .map { $0.toDomain() } .eraseToAnyPublisher() } - public func getFriendRandomUser() -> AnyPublisher { - pokeService.getFriendRandomUser(randomType: "", size: 1) - .map { $0.toDomain() } + public func getRandomUser() -> AnyPublisher<[Domain.PokeRandomUserInfoModel], any Error> { + pokeService.getRandomUsers(randomType: "ALL_USER", size: 1) + .map { $0.randomInfoList.map { $0.toDomain() }} .eraseToAnyPublisher() } } - diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/DailySoptuneRepositoyInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/DailySoptuneRepositoyInterface.swift index 6c347072..594debd4 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/DailySoptuneRepositoyInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/DailySoptuneRepositoyInterface.swift @@ -10,5 +10,5 @@ import Combine public protocol DailySoptuneRepositoyInterface { func getTodaysFortuneCard() -> AnyPublisher - func getFriendRandomUser() -> AnyPublisher + func getRandomUser() -> AnyPublisher<[PokeRandomUserInfoModel], Error> } diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/DailySoptuneUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/DailySoptuneUseCase.swift index 030a8d2d..50225ce7 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/DailySoptuneUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/DailySoptuneUseCase.swift @@ -12,10 +12,10 @@ import Core public protocol DailySoptuneUseCase { var todaysFortuneCard: PassthroughSubject { get } - var friendRandomUser: PassthroughSubject { get } + var randomUser: PassthroughSubject<[PokeRandomUserInfoModel], Never> { get } func getTodaysFortuneCard() - func getFriendRandomUser() + func getRandomUser() } public class DefaultDailySoptuneUseCase { @@ -24,7 +24,7 @@ public class DefaultDailySoptuneUseCase { public let cancelBag = CancelBag() public let todaysFortuneCard = PassthroughSubject() - public let friendRandomUser = PassthroughSubject() + public let randomUser = PassthroughSubject<[PokeRandomUserInfoModel], Never>() public init(repository: DailySoptuneRepositoyInterface) { self.repository = repository @@ -42,12 +42,12 @@ extension DefaultDailySoptuneUseCase: DailySoptuneUseCase { }.store(in: cancelBag) } - public func getFriendRandomUser() { - repository.getFriendRandomUser() + public func getRandomUser() { + repository.getRandomUser() .sink { event in - print("GetFriendRandomUser State: \(event)") + print("GetRandomUser State: \(event)") } receiveValue: { [weak self] randomUser in - self?.friendRandomUser.send(friendRandomUser) + self?.randomUser.send(randomUser) }.store(in: cancelBag) } } diff --git a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/VC/DailySoptuneResultVC.swift b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/VC/DailySoptuneResultVC.swift index bd6d06ce..404a2385 100644 --- a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/VC/DailySoptuneResultVC.swift +++ b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/VC/DailySoptuneResultVC.swift @@ -148,5 +148,11 @@ extension DailySoptuneResultVC { ) let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag) + + output.randomUser + .withUnretained(self) + .sink { owner, model in + owner.dailySoptuneResultPokeView.setData(with: model.userInfoList[0]) + }.store(in: self.cancelBag) } } diff --git a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/ViewModel/DailySoptuneResultViewModel.swift b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/ViewModel/DailySoptuneResultViewModel.swift index d21b6f27..c2c2c597 100644 --- a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/ViewModel/DailySoptuneResultViewModel.swift +++ b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/ViewModel/DailySoptuneResultViewModel.swift @@ -36,6 +36,7 @@ public class DailySoptuneResultViewModel: DailySoptuneResultViewModelType { public struct Output { let todaysFortuneCard = PassthroughSubject() + let randomUser = PassthroughSubject() } // MARK: - Initialization @@ -53,6 +54,7 @@ extension DailySoptuneResultViewModel { input.viewDidLoad .sink { [weak self] _ in self?.onNaviBackTap?() + self?.useCase.getRandomUser() }.store(in: cancelBag) input.receiveTodaysFortuneCardTap @@ -68,6 +70,12 @@ extension DailySoptuneResultViewModel { useCase.todaysFortuneCard .subscribe(output.todaysFortuneCard) .store(in: cancelBag) + + useCase.randomUser + .asDriver() + .sink(receiveValue: { values in + output.randomUser.send(values[0]) + }).store(in: cancelBag) } func setCurrentDateString() -> String { diff --git a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/Views/DailySoptuneResultPokeView.swift b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/Views/DailySoptuneResultPokeView.swift index 3519cc18..40ec0f97 100644 --- a/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/Views/DailySoptuneResultPokeView.swift +++ b/SOPT-iOS/Projects/Features/DailySoptuneFeature/Sources/DailySoptuneScene/Views/DailySoptuneResultPokeView.swift @@ -11,6 +11,7 @@ import Combine import DSKit import Core +import Domain import PokeFeature public final class DailySoptuneResultPokeView: UIView { @@ -34,18 +35,18 @@ public final class DailySoptuneResultPokeView: UIView { $0.backgroundColor = DSKitAsset.Colors.white.color $0.clipsToBounds = true $0.contentMode = .scaleAspectFill + $0.layer.borderColor = DSKitAsset.Colors.success.color.cgColor + $0.layer.borderWidth = 2 } private let nameLabel = UILabel().then { $0.font = UIFont.MDS.body1.font $0.textColor = DSKitAsset.Colors.gray30.color - $0.text = "이재현" } private let partLabel = UILabel().then { $0.font = UIFont.MDS.label4.font $0.textColor = DSKitAsset.Colors.gray300.color - $0.text = "31기 iOS" } private let kokButton = PokeKokButton() @@ -126,3 +127,19 @@ extension DailySoptuneResultPokeView { } } } + +// MARK: - Methods + +extension DailySoptuneResultPokeView { + + func setData(with model: PokeUserModel) { + self.configure(with: model) + } + + private func configure(with model: PokeUserModel) { + self.nameLabel.text = model.name + self.partLabel.text = "\(model.generation)기 \(model.part)" + self.profileImageView.setImage(with: model.isAnonymous ? model.anonymousImage : model.profileImage) + } + +} diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift index ac4d1e50..9d48dfda 100644 --- a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift @@ -21,7 +21,7 @@ public protocol PokeService { func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher func getFriendList() -> AnyPublisher func getFriendList(relation: String, page: Int) -> AnyPublisher - func getRandomUsers(randomType: String, size: Int) -> AnyPublisher + func getRandomUsers(randomType: String?, size: Int) -> AnyPublisher func getPokeMessages(messageType: String) -> AnyPublisher func poke(userId: Int, message: String, isAnonymous: Bool) -> AnyPublisher } @@ -53,6 +53,7 @@ extension DefaultPokeService: PokeService { "size": size ] + return requestObjectInCombine(.getFriendRandomUser(params: params)) } @@ -60,11 +61,10 @@ extension DefaultPokeService: PokeService { requestObjectInCombine(.getFriendList) } - public func getRandomUsers(randomType: String, size: Int) -> AnyPublisher { - let params: [String: Any] = [ - "randomType": randomType, - "size": size - ] + public func getRandomUsers(randomType: String?, size: Int) -> AnyPublisher { + var params: [String: Any] = [:] + if let randomType = randomType { params["randomType"] = randomType } + params["size"] = size return requestObjectInCombine(.getRandomUsers(params: params)) }