Skip to content

Commit

Permalink
[Feat] sopt-makers#327 - 친구의 친구 추천 API Response 뷰 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Dec 20, 2023
1 parent 5eff457 commit 5741337
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ extension PokeMainRepository: PokeMainRepositoryInterface {
.map { $0.map { $0.toDomain() } }
.eraseToAnyPublisher()
}

public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error> {
pokeService.getFriendRandomUser()
.map { $0.map { $0.toDomain() } }
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import Combine
public protocol PokeMainRepositoryInterface {
func getWhoPokeToMe() -> AnyPublisher<PokeUserModel?, Error>
func getFriend() -> AnyPublisher<[PokeUserModel], Error>
func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error>
}
13 changes: 13 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/PokeMainUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import Core
public protocol PokeMainUseCase {
var pokedToMeUser: PassthroughSubject<PokeUserModel?, Never> { get }
var myFriend: PassthroughSubject<[PokeUserModel], Never> { get }
var friendRandomUsers: PassthroughSubject<[PokeFriendRandomUserModel], Never> { get }

func getWhoPokedToMe()
func getFriend()
func getFriendRandomUser()
}

public class DefaultPokeMainUseCase {
Expand All @@ -24,6 +26,8 @@ public class DefaultPokeMainUseCase {

public let pokedToMeUser = PassthroughSubject<PokeUserModel?, Never>()
public let myFriend = PassthroughSubject<[PokeUserModel], Never>()
public let friendRandomUsers = PassthroughSubject<[PokeFriendRandomUserModel], Never>()


public init(repository: PokeMainRepositoryInterface) {
self.repository = repository
Expand Down Expand Up @@ -51,4 +55,13 @@ extension DefaultPokeMainUseCase: PokeMainUseCase {
self?.myFriend.send(friend)
}.store(in: cancelBag)
}

public func getFriendRandomUser() {
repository.getFriendRandomUser()
.sink { event in
print("GetFriendRandomUser State: \(event)")
} receiveValue: { [weak self] randomUsers in
self?.friendRandomUsers.send(randomUsers)
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit

import DSKit
import Core
import Domain

public final class PokeProfileCardView: UIView {

Expand Down Expand Up @@ -102,12 +103,12 @@ public final class PokeProfileCardView: UIView {
}

// MARK: - Methods
func setData(with model: ProfileCardContentModel) {

func setData(with model: PokeUserModel) {
self.userId = model.userId
self.profileImageView.setImage(with: model.avatarUrl)
self.profileImageView.setImage(with: model.profileImage)
self.nameLabel.text = model.name
self.partLabel.text = model.partInfomation
self.partLabel.text = model.part
}

@discardableResult
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,37 @@ extension PokeMainVC {
let output = viewModel.transform(from: input, cancelBag: cancelBag)

output.pokedToMeUser
.sink { [weak self] model in
self?.pokedUserContentView.configure(with: model)
.withUnretained(self)
.sink { owner, model in
owner.pokedUserContentView.configure(with: model)
}.store(in: cancelBag)

output.pokedUserSectionWillBeHidden
.assign(to: \.isHidden, onWeak: pokedSectionGroupView)
.store(in: cancelBag)

output.myFriend
.sink { model in
self.friendSectionContentView.setData(with: model)
.withUnretained(self)
.sink { owner, model in
owner.friendSectionContentView.setData(with: model)
}.store(in: cancelBag)

output.friendsSectionWillBeHidden
.assign(to: \.isHidden, onWeak: friendSectionGroupView)
.store(in: cancelBag)

// 테스트를 위해 더미 데이터를 넣도록 임시 세팅
pokedSectionHeaderView.rightButtonTap
.sink { _ in
self.firstProfileCardGroupView.setProfileCard(with: [.init(userId: 77, avatarUrl: "sdafds", name: "test2", partInfomation: "server"), .init(userId: 999, avatarUrl: "", name: "test3", partInfomation: "pm")], friendName: "someone")
output.friendRandomUsers
.withUnretained(self)
.sink { owner, randomUsers in
let profileCardGroupViews = [owner.firstProfileCardGroupView, owner.secondProfileCardGroupView]

self.secondProfileCardGroupView.setProfileCard(with: [.init(userId: 1, avatarUrl: "sdafds", name: "test4", partInfomation: "server")], friendName: "aaa")
for (i, profileCardGroupView) in profileCardGroupViews.enumerated() {
let randomUser = randomUsers[safe: i]
profileCardGroupView.isHidden = (randomUser == nil)
if let randomUser {
profileCardGroupView.setData(with: randomUser)
}
}
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class PokeMainViewModel:
let pokedUserSectionWillBeHidden = PassthroughSubject<Bool, Never>()
let myFriend = PassthroughSubject<PokeUserModel, Never>()
let friendsSectionWillBeHidden = PassthroughSubject<Bool, Never>()
let friendRandomUsers = PassthroughSubject<[PokeFriendRandomUserModel], Never>()
}

// MARK: - initialization
Expand All @@ -65,6 +66,7 @@ extension PokeMainViewModel {
.sink { [weak self] _ in
self?.useCase.getWhoPokedToMe()
self?.useCase.getFriend()
self?.useCase.getFriendRandomUser()
}.store(in: cancelBag)

input.naviBackButtonTap
Expand Down Expand Up @@ -132,6 +134,11 @@ extension PokeMainViewModel {
.map { $0.isEmpty }
.subscribe(output.friendsSectionWillBeHidden)
.store(in: cancelBag)

useCase.friendRandomUsers
.prefix(2)
.subscribe(output.friendRandomUsers)
.store(in: cancelBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Combine

import Core
import DSKit
import Domain

public final class ProfileCardGroupView: UIView {

Expand Down Expand Up @@ -109,14 +110,15 @@ extension ProfileCardGroupView {
// MARK: - Methods

extension ProfileCardGroupView {
func setProfileCard(with models: [ProfileCardContentModel], friendName: String) {
self.friendNameLabel.text = friendName
let models = models.prefix(2)

func setData(with model: PokeFriendRandomUserModel) {
self.friendNameLabel.text = model.friendName
let randomUsers = model.friendList.prefix(2)

handleProfileCardCount(count: models.count)
handleProfileCardCount(count: randomUsers.count)

for (index, model) in models.enumerated() {
index == 0 ? leftProfileCardView.setData(with: model) : rightProfileCardView.setData(with: model)
for (index, user) in randomUsers.enumerated() {
index == 0 ? leftProfileCardView.setData(with: user) : rightProfileCardView.setData(with: user)
}
}

Expand Down
5 changes: 4 additions & 1 deletion SOPT-iOS/Projects/Modules/Networks/Sources/API/PokeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Core
public enum PokeAPI {
case getWhoPokedToMe
case getFriend
case getFriendRandomUser
}

extension PokeAPI: BaseAPI {
Expand All @@ -26,12 +27,14 @@ extension PokeAPI: BaseAPI {
return "/to/me"
case .getFriend:
return "/friend"
case .getFriendRandomUser:
return "/friend/random-user"
}
}

public var method: Moya.Method {
switch self {
case .getWhoPokedToMe, .getFriend:
case .getWhoPokedToMe, .getFriend, .getFriendRandomUser:
return .get
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public typealias DefaultPokeService = BaseService<PokeAPI>
public protocol PokeService {
func getWhoPokedToMe() -> AnyPublisher<PokeUserEntity?, Error>
func getFriend() -> AnyPublisher<[PokeUserEntity], Error>
func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error>
}

extension DefaultPokeService: PokeService {
Expand All @@ -26,4 +27,8 @@ extension DefaultPokeService: PokeService {
public func getFriend() -> AnyPublisher<[PokeUserEntity], Error> {
requestObjectInCombine(.getFriend)
}

public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error> {
requestObjectInCombine(.getFriendRandomUser)
}
}

0 comments on commit 5741337

Please sign in to comment.