Skip to content

Commit

Permalink
[Feat] #386 - 행운 친구 콕찌르기 API 뷰 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Sep 25, 2024
1 parent b7947fc commit ddd79f0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public class DailySoptuneRepository {
}

extension DailySoptuneRepository: DailySoptuneRepositoyInterface {

public func getTodaysFortuneCard() -> AnyPublisher<Domain.DailySoptuneCardModel, any Error> {
fortuneService.getTodaysFortuneCard()
.map { $0.toDomain() }
.eraseToAnyPublisher()
}

public func getFriendRandomUser() -> AnyPublisher<Domain.PokeFriendRandomUserModel, any Error> {
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()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import Combine

public protocol DailySoptuneRepositoyInterface {
func getTodaysFortuneCard() -> AnyPublisher<DailySoptuneCardModel, Error>
func getFriendRandomUser() -> AnyPublisher<PokeFriendRandomUserModel, Error>
func getRandomUser() -> AnyPublisher<[PokeRandomUserInfoModel], Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import Core

public protocol DailySoptuneUseCase {
var todaysFortuneCard: PassthroughSubject<DailySoptuneCardModel, Never> { get }
var friendRandomUser: PassthroughSubject<PokeFriendRandomUserModel, Never> { get }
var randomUser: PassthroughSubject<[PokeRandomUserInfoModel], Never> { get }

func getTodaysFortuneCard()
func getFriendRandomUser()
func getRandomUser()
}

public class DefaultDailySoptuneUseCase {
Expand All @@ -24,7 +24,7 @@ public class DefaultDailySoptuneUseCase {
public let cancelBag = CancelBag()

public let todaysFortuneCard = PassthroughSubject<DailySoptuneCardModel, Never>()
public let friendRandomUser = PassthroughSubject<PokeFriendRandomUserModel, Never>()
public let randomUser = PassthroughSubject<[PokeRandomUserInfoModel], Never>()

public init(repository: DailySoptuneRepositoyInterface) {
self.repository = repository
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DailySoptuneResultViewModel: DailySoptuneResultViewModelType {

public struct Output {
let todaysFortuneCard = PassthroughSubject<DailySoptuneCardModel, Never>()
let randomUser = PassthroughSubject<PokeRandomUserInfoModel, Never>()
}

// MARK: - Initialization
Expand All @@ -53,6 +54,7 @@ extension DailySoptuneResultViewModel {
input.viewDidLoad
.sink { [weak self] _ in
self?.onNaviBackTap?()
self?.useCase.getRandomUser()
}.store(in: cancelBag)

input.receiveTodaysFortuneCardTap
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Combine

import DSKit
import Core
import Domain
import PokeFeature

public final class DailySoptuneResultPokeView: UIView {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public protocol PokeService {
func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher<PokeFriendRandomUserEntity, Error>
func getFriendList() -> AnyPublisher<PokeMyFriendsEntity, Error>
func getFriendList(relation: String, page: Int) -> AnyPublisher<PokeMyFriendsListEntity, Error>
func getRandomUsers(randomType: String, size: Int) -> AnyPublisher<PokeRandomListEntity, Error>
func getRandomUsers(randomType: String?, size: Int) -> AnyPublisher<PokeRandomListEntity, Error>
func getPokeMessages(messageType: String) -> AnyPublisher<PokeMessagesEntity, Error>
func poke(userId: Int, message: String, isAnonymous: Bool) -> AnyPublisher<PokeUserEntity, Error>
}
Expand Down Expand Up @@ -53,18 +53,18 @@ extension DefaultPokeService: PokeService {
"size": size
]


return requestObjectInCombine(.getFriendRandomUser(params: params))
}

public func getFriendList() -> AnyPublisher<PokeMyFriendsEntity, Error> {
requestObjectInCombine(.getFriendList)
}

public func getRandomUsers(randomType: String, size: Int) -> AnyPublisher<PokeRandomListEntity, Error> {
let params: [String: Any] = [
"randomType": randomType,
"size": size
]
public func getRandomUsers(randomType: String?, size: Int) -> AnyPublisher<PokeRandomListEntity, Error> {
var params: [String: Any] = [:]
if let randomType = randomType { params["randomType"] = randomType }
params["size"] = size

return requestObjectInCombine(.getRandomUsers(params: params))
}
Expand Down

0 comments on commit ddd79f0

Please sign in to comment.