Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #327 콕찌르기 메인 - API 연결 #328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions SOPT-iOS/Projects/Data/Sources/Repository/PokeMainRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// PokeMainRepository.swift
// Data
//
// Created by sejin on 12/19/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Combine

import Core
import Domain
import Networks

public class PokeMainRepository {

private let pokeService: PokeService
private let cancelBag = CancelBag()

public init(service: PokeService) {
self.pokeService = service
}
}

extension PokeMainRepository: PokeMainRepositoryInterface {
public func getWhoPokeToMe() -> AnyPublisher<Domain.PokeUserModel?, Error> {
pokeService.getWhoPokedToMe()
.map { $0?.toDomain() }
.eraseToAnyPublisher()
}

public func getFriend() -> AnyPublisher<[PokeUserModel], Error> {
pokeService.getFriend()
.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
@@ -0,0 +1,21 @@
//
// PokeFriendRandomUserTransform.swift
// Data
//
// Created by sejin on 12/20/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

import Domain
import Networks

extension PokeFriendRandomUserEntity {
public func toDomain() -> PokeFriendRandomUserModel {
return PokeFriendRandomUserModel(friendId: friendId,
friendName: friendName,
friendProfileImage: friendProfileImage,
friendList: friendList.map { $0.toDomain() })
}
}
29 changes: 29 additions & 0 deletions SOPT-iOS/Projects/Data/Sources/Transform/PokeUserTransform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PokeUserTransform.swift
// Data
//
// Created by sejin on 12/19/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

import Domain
import Networks

extension PokeUserEntity {
public func toDomain() -> PokeUserModel {
return PokeUserModel(userId: userId,
playgroundId: playgroundId,
profileImage: profileImage,
name: name,
generation: generation,
part: part,
pokeNum: pokeNum,
message: message,
relationName: relationName,
mutual: mutual,
isFirstMeet: isFirstMeet,
isAlreadyPoke: isAlreadyPoke)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,12 @@ extension AppDelegate {
)
}
)
container.register(interface: PokeMainRepositoryInterface.self,
implement: {
PokeMainRepository(
service: DefaultPokeService()
)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PokeFriendRandomUserModel.swift
// Domain
//
// Created by sejin on 12/20/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

public struct PokeFriendRandomUserModel {
public let friendId: Int
public let friendName, friendProfileImage: String
public let friendList: [PokeUserModel]

public init(friendId: Int, friendName: String, friendProfileImage: String, friendList: [PokeUserModel]) {
self.friendId = friendId
self.friendName = friendName
self.friendProfileImage = friendProfileImage
self.friendList = friendList
}
}
38 changes: 38 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/Model/PokeUserModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// PokeUserModel.swift
// Domain
//
// Created by sejin on 12/19/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Foundation

// MARK: - Empty
public struct PokeUserModel: Codable {
public let userId: Int
public let playgroundId: Int
public let profileImage, name: String
public let generation: Int
public let part: String
public let pokeNum: Int
public let message: String
public let relationName: String
public let mutual: [String]
public let isFirstMeet, isAlreadyPoke: Bool

public init(userId: Int, playgroundId: Int, profileImage: String, name: String, generation: Int, part: String, pokeNum: Int, message: String, relationName: String, mutual: [String], isFirstMeet: Bool, isAlreadyPoke: Bool) {
self.userId = userId
self.playgroundId = playgroundId
self.profileImage = profileImage
self.name = name
self.generation = generation
self.part = part
self.pokeNum = pokeNum
self.message = message
self.relationName = relationName
self.mutual = mutual
self.isFirstMeet = isFirstMeet
self.isAlreadyPoke = isAlreadyPoke
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// PokeMainRepositoryInterface.swift
// Domain
//
// Created by sejin on 12/19/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Combine

public protocol PokeMainRepositoryInterface {
func getWhoPokeToMe() -> AnyPublisher<PokeUserModel?, Error>
func getFriend() -> AnyPublisher<[PokeUserModel], Error>
func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error>
}
67 changes: 67 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/PokeMainUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// PokeMainUseCase.swift
// Domain
//
// Created by sejin on 12/19/23.
// Copyright © 2023 SOPT-iOS. All rights reserved.
//

import Combine

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 {
public let repository: PokeMainRepositoryInterface
public let cancelBag = CancelBag()

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
}
}

extension DefaultPokeMainUseCase: PokeMainUseCase {
public func getWhoPokedToMe() {
repository.getWhoPokeToMe()
.catch { _ in
Just<PokeUserModel?>(nil)
}
.sink { event in
print("GetPokedToMe State: \(event)")
} receiveValue: { [weak self] pokeUser in
self?.pokedToMeUser.send(pokeUser)
}.store(in: cancelBag)
}

public func getFriend() {
repository.getFriend()
.sink { event in
print("GetFriend State: \(event)")
} receiveValue: { [weak self] friend in
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 @@ -13,6 +13,8 @@ import DSKit

final public class PokeChipView: UIView {
public enum ChipType {
case newUser
case singleFriend(friendName: String)
case withPokeCount(relation: String, pokeCount: String)
case acquaintance(friendname: String, relationCount: String)
}
Expand Down Expand Up @@ -72,6 +74,10 @@ final public class PokeChipView: UIView {
extension PokeChipView {
public func configure(with pokechipType: ChipType) {
switch pokechipType {
case .newUser:
self.titleLabel.text = "새로운 친구"
case let .singleFriend(friendName):
self.titleLabel.text = "\(friendName)의 친구"
case let .withPokeCount(relation, pokeCount):
self.titleLabel.text = relation + Constant.dotWithWhiteSpace + pokeCount + "콕"
case let .acquaintance(friendname, relationCount):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public final class PokeKokButton: UIButton {
self.backgroundColor = backgroundColor
}

public func setIsFriend(with isFriend: Bool) {
self.isFriend = isFriend
}

private func setIcon() {
let icon = self.isFriend ? DSKitAsset.Assets.iconKok.image : DSKitAsset.Assets.iconEyes.image
self.setImage(icon.withTintColor(DSKitAsset.Colors.black.color), for: .normal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ final public class PokeNotificationListContentView: UIView {
// NOTE: NotifcationDetailView에서는 description의 numberOfLine Value가 2에요
private let isDetailView: Bool

private var userId: Int?

// MARK: - View Lifecycle
public init(
isDetailView: Bool = true,
Expand Down Expand Up @@ -138,20 +140,22 @@ extension PokeNotificationListContentView {

extension PokeNotificationListContentView {
public func configure(with model: NotificationListContentModel) {
self.userId = model.userId
self.profileImageView.setImage(with: model.avatarUrl, relation: model.pokeRelation)
self.nameLabel.text = model.name
self.partInfoLabel.text = model.partInfomation
self.descriptionLabel.attributedText = model.description.applyMDSFont()
self.pokeChipView.configure(with: model.chipInfo)
self.pokeKokButton.isEnabled = !model.isPoked
self.pokeKokButton.setIsFriend(with: !model.isFirstMeet)
}

public func poked() {
// TBD
}

public func signalForPokeButtonClicked() -> Driver<Void> {
self.pokeKokButton.tap
public func signalForPokeButtonClicked() -> Driver<Int?> {
self.pokeKokButton.tap.map { self.userId }.asDriver()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import UIKit

import DSKit
import Core
import Domain

public final class PokeProfileCardView: UIView {

// MARK: - Properties

typealias UserId = String
typealias UserId = Int

lazy var kokButtonTap: Driver<UserId?> = kokButton.tap.map { self.userId }.asDriver()

var userId: String?
var userId: Int?

// MARK: - UI Components

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
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import UIKit

import DSKit
import Core
import Domain

public final class PokeProfileListView: UIView {

// MARK: - Properties

typealias UserId = String
typealias UserId = Int

lazy var kokButtonTap: Driver<UserId?> = kokButton.tap.map { self.userId }.asDriver()

var viewType: ProfileListType

var userId: String?
var userId: Int?

// MARK: - UI Components

Expand Down Expand Up @@ -171,12 +172,12 @@ public final class PokeProfileListView: UIView {
// MARK: - Methods

@discardableResult
func setData(with model: ProfileListContentModel) -> Self {
func setData(with model: PokeUserModel) -> Self {
self.userId = model.userId
self.profileImageView.setImage(with: model.avatarUrl, relation: model.relation)
self.profileImageView.setImage(with: model.profileImage, relation: model.pokeRelation)
self.nameLabel.text = model.name
self.partLabel.text = model.partInfomation
self.kokCountLabel.text = "\(model.pokeCount)콕"
self.partLabel.text = model.part
self.kokCountLabel.text = "\(model.pokeNum)콕"
return self
}

Expand Down
Loading