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] 콕 찌르기 개편 #372

Merged
merged 10 commits into from
Jun 6, 2024
6 changes: 3 additions & 3 deletions SOPT-iOS/Projects/Core/Sources/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public struct I18N {
public static let poke = "콕 찌르기"
public static let someonePokedMe = "누가 나를 찔렀어요"
public static let pokeMyFriends = "내 친구를 찔러보세요"
public static let pokeNearbyFriends = "내 친구의 친구를 찔러보세요"
public static let pokeNearbyFriends = "나와 공통점이 있는 친구들을 찔러보세요"
public static let emptyFriendDescription = "아직 없어요 T.T\n내 친구가 더 많은 친구가 생길 때까지 기다려주세요"
public static let refreshGuide = "화면을 당기면\n다른 친구를 볼 수 있어요"
public static let refreshGuide = "화면을 밑으로 당기면\n다른 친구를 볼 수 있어요"
public static let pokeSuccess = "콕 찌르기를 완료했어요"
public static func makingFriendCompleted(name: String) -> String {
return "찌르기 답장으로\n\(name)님과 친구가 되었어요!"
Expand All @@ -344,7 +344,7 @@ public struct I18N {
public static func friendsBaseline(_ count: Int) -> String {
return "\(count)번 이상 찌르면 될 수 있어요"
}
public static let emptyViewDescription = "아직 없어요 T.T\n더 많은 찌르기로 달성해보세요"
public static let emptyViewDescription = "아직 없어요 T.T\n나와 비슷한 친구가 생길 때까지 기다려주세요"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ extension PokeMainRepository: PokeMainRepositoryInterface {
.eraseToAnyPublisher()
}

public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error> {
pokeService.getFriendRandomUser()
.map { $0.map { $0.toDomain() } }
public func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher<PokeFriendRandomUserModel, Error> {
pokeService.getFriendRandomUser(randomType: randomType, size: size)
.map { $0.toDomain() }
.eraseToAnyPublisher()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import Networks

extension PokeFriendRandomUserEntity {
public func toDomain() -> PokeFriendRandomUserModel {
return PokeFriendRandomUserModel(friendId: friendId,
playgroundId: playgroundId,
friendName: friendName,
friendProfileImage: friendProfileImage,
friendList: friendList.map { $0.toDomain() })
return PokeFriendRandomUserModel(randomInfoList: randomInfoList.map { $0.toDomain() })
}
}

extension PokeRandomInfoListEntity {
public func toDomain() -> PokeRandomInfoListModel {
return .init(randomType: PokeRandomUserType(rawValue: randomType), randomTitle: randomTitle, userInfoList: userInfoList.map { $0.toDomain() })
}
}
26 changes: 14 additions & 12 deletions SOPT-iOS/Projects/Data/Sources/Transform/PokeUserTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ 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,
mutualRelationMessage: mutualRelationMessage,
isFirstMeet: isFirstMeet,
isAlreadyPoke: isAlreadyPoke)
return PokeUserModel(userId: userId,
playgroundId: playgroundId,
profileImage: profileImage,
name: name,
generation: generation,
part: part,
pokeNum: pokeNum,
message: message,
relationName: relationName,
mutualRelationMessage: mutualRelationMessage,
isFirstMeet: isFirstMeet,
isAlreadyPoke: isAlreadyPoke,
isAnonymous: isAnonymous,
anonymousName: anonymousName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
import Foundation

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

public init(friendId: Int, playgroundId: Int, friendName: String, friendProfileImage: String, friendList: [PokeUserModel]) {
self.friendId = friendId
self.playgroundId = playgroundId
self.friendName = friendName
self.friendProfileImage = friendProfileImage
self.friendList = friendList
}
public let randomInfoList: [PokeRandomInfoListModel]

public init(randomInfoList: [PokeRandomInfoListModel]) {
self.randomInfoList = randomInfoList
}
}

public struct PokeRandomInfoListModel {
public let randomType: PokeRandomUserType?
public let randomTitle: String
public let userInfoList: [PokeUserModel]

public init(randomType: PokeRandomUserType?, randomTitle: String, userInfoList: [PokeUserModel]) {
self.randomType = randomType
self.randomTitle = randomTitle
self.userInfoList = userInfoList
}
}
54 changes: 29 additions & 25 deletions SOPT-iOS/Projects/Domain/Sources/Model/PokeUserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@ 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 mutualRelationMessage: 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, mutualRelationMessage: 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.mutualRelationMessage = mutualRelationMessage
self.isFirstMeet = isFirstMeet
self.isAlreadyPoke = isAlreadyPoke
}
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 mutualRelationMessage: String
public let isFirstMeet, isAlreadyPoke: Bool
public let isAnonymous: Bool
public let anonymousName: String

public init(userId: Int, playgroundId: Int, profileImage: String, name: String, generation: Int, part: String, pokeNum: Int, message: String, relationName: String, mutualRelationMessage: String, isFirstMeet: Bool, isAlreadyPoke: Bool, isAnonymous: Bool, anonymousName: String) {
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.mutualRelationMessage = mutualRelationMessage
self.isFirstMeet = isFirstMeet
self.isAlreadyPoke = isAlreadyPoke
self.isAnonymous = isAnonymous
self.anonymousName = anonymousName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import Combine
public protocol PokeMainRepositoryInterface: PokeRepositoryInterface {
func getWhoPokeToMe() -> AnyPublisher<PokeUserModel?, Error>
func getFriend() -> AnyPublisher<[PokeUserModel], Error>
func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error>
func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher<PokeFriendRandomUserModel, Error>
func checkPokeNewUser() -> AnyPublisher<Bool, Error>
}
158 changes: 79 additions & 79 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/PokeMainUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,91 +11,91 @@ 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 }
var pokedResponse: PassthroughSubject<PokeUserModel, Never> { get }
var madeNewFriend: PassthroughSubject<PokeUserModel, Never> { get }
var errorMessage: PassthroughSubject<String?, Never> { get }
var isPokeNewUser: PassthroughSubject<Bool, Never> { get set }
var pokedToMeUser: PassthroughSubject<PokeUserModel?, Never> { get }
var myFriend: PassthroughSubject<[PokeUserModel], Never> { get }
var friendRandomUsers: PassthroughSubject<PokeFriendRandomUserModel, Never> { get }
var pokedResponse: PassthroughSubject<PokeUserModel, Never> { get }
var madeNewFriend: PassthroughSubject<PokeUserModel, Never> { get }
var errorMessage: PassthroughSubject<String?, Never> { get }
var isPokeNewUser: PassthroughSubject<Bool, Never> { get set }

func getWhoPokedToMe()
func getFriend()
func getFriendRandomUser()
func poke(userId: Int, message: PokeMessageModel, willBeNewFriend: Bool)
func checkPokeNewUser()
func getWhoPokedToMe()
func getFriend()
func getFriendRandomUser(randomType: PokeRandomUserType, size: Int)
func poke(userId: Int, message: PokeMessageModel, willBeNewFriend: Bool)
func checkPokeNewUser()
}

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 let pokedResponse = PassthroughSubject<PokeUserModel, Never>()
public let madeNewFriend = PassthroughSubject<PokeUserModel, Never>()
public let errorMessage = PassthroughSubject<String?, Never>()
public var isPokeNewUser = PassthroughSubject<Bool, Never>()
public let repository: PokeMainRepositoryInterface
public let cancelBag = CancelBag()

public init(repository: PokeMainRepositoryInterface) {
self.repository = repository
}
public let pokedToMeUser = PassthroughSubject<PokeUserModel?, Never>()
public let myFriend = PassthroughSubject<[PokeUserModel], Never>()
public let friendRandomUsers = PassthroughSubject<PokeFriendRandomUserModel, Never>()
public let pokedResponse = PassthroughSubject<PokeUserModel, Never>()
public let madeNewFriend = PassthroughSubject<PokeUserModel, Never>()
public let errorMessage = PassthroughSubject<String?, Never>()
public var isPokeNewUser = PassthroughSubject<Bool, 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)
}
public func poke(userId: Int, message: PokeMessageModel, willBeNewFriend: Bool) {
self.repository
.poke(userId: userId, message: message.content)
.catch { [weak self] error in
let message = error.toastMessage
self?.errorMessage.send(message)
return Empty<PokeUserModel, Never>()
}.sink { [weak self] user in
self?.pokedResponse.send(user)
if willBeNewFriend {
self?.madeNewFriend.send(user)
}
}.store(in: self.cancelBag)
}
public func checkPokeNewUser() {
repository.checkPokeNewUser()
.catch { error in
print("CheckPokeNewUser State: \(error)")
return Just(false)
}.sink { [weak self] isNewUser in
self?.isPokeNewUser.send(isNewUser)
}.store(in: cancelBag)
}
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(randomType: PokeRandomUserType, size: Int) {
repository.getFriendRandomUser(randomType: randomType.rawValue, size: size)
.sink { event in
print("GetFriendRandomUser State: \(event)")
} receiveValue: { [weak self] randomUsers in
self?.friendRandomUsers.send(randomUsers)
}.store(in: cancelBag)
}

public func poke(userId: Int, message: PokeMessageModel, willBeNewFriend: Bool) {
self.repository
.poke(userId: userId, message: message.content)
.catch { [weak self] error in
let message = error.toastMessage
self?.errorMessage.send(message)
return Empty<PokeUserModel, Never>()
}.sink { [weak self] user in
self?.pokedResponse.send(user)
if willBeNewFriend {
self?.madeNewFriend.send(user)
}
}.store(in: self.cancelBag)
}

public func checkPokeNewUser() {
repository.checkPokeNewUser()
.catch { error in
print("CheckPokeNewUser State: \(error)")
return Just(false)
}.sink { [weak self] isNewUser in
self?.isPokeNewUser.send(isNewUser)
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// PokeAnonymousFriendUpgradePresentable.swift
// PokeFeature
//
// Created by Aiden.lee on 2024/06/02.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import BaseFeatureDependency
import Core

public protocol PokeAnonymousFriendUpgradePresentable: ViewControllable { }
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public protocol PokeFeatureBuildable {
func makePokeMessageTemplateBottomSheet(messageType: PokeMessageType) -> PokeMessageTemplatesPresentable
func makePokeNotificationList() -> PokeNotificationPresentable
func makePokeMakingFriendCompleted(friendName: String) -> PokeMakingFriendCompletedPresentable
func makePokeAnonymousFriendUpgrade(user: PokeUserModel) -> PokeAnonymousFriendUpgradePresentable
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import Domain
public protocol PokeMainViewControllable: ViewControllable { }

public protocol PokeMainCoordinatable {
var onNaviBackTap: (() -> Void)? { get set }
var onPokeNotificationsTap: (() -> Void)? { get set }
var onMyFriendsTap: (() -> Void)? { get set }
var onProfileImageTapped: ((Int) -> Void)? { get set }
var onPokeButtonTapped: ((PokeUserModel) -> Driver<(PokeUserModel, PokeMessageModel)>)? { get set }
var onNewFriendMade: ((String) -> Void)? { get set }
var switchToOnboarding: (() -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
var onPokeNotificationsTap: (() -> Void)? { get set }
var onMyFriendsTap: (() -> Void)? { get set }
var onProfileImageTapped: ((Int) -> Void)? { get set }
var onPokeButtonTapped: ((PokeUserModel) -> Driver<(PokeUserModel, PokeMessageModel)>)? { get set }
var onNewFriendMade: ((String) -> Void)? { get set }
var onAnonymousFriendUpgrade: ((PokeUserModel) -> Void)? { get set }
var switchToOnboarding: (() -> Void)? { get set }
}

public typealias PokeMainViewModelType = ViewModelType & PokeMainCoordinatable
Expand Down
Loading