diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/PokeOnboardingRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/PokeOnboardingRepository.swift index 150578cb..31e63208 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/PokeOnboardingRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/PokeOnboardingRepository.swift @@ -13,33 +13,36 @@ import Domain import Networks public final class PokeOnboardingRepository { - private let pokeService: PokeService - - public init(pokeService: PokeService) { - self.pokeService = pokeService - } + private let pokeService: PokeService + + public init(pokeService: PokeService) { + self.pokeService = pokeService + } } extension PokeOnboardingRepository: PokeOnboardingRepositoryInterface { - public func getRandomAcquaintances() -> AnyPublisher<[PokeUserModel], Error> { - self.pokeService - .getRandomUsers() - .map { $0.map { $0.toDomain() } } - .eraseToAnyPublisher() - } - - public func getMesseageTemplates(type: PokeMessageType) -> AnyPublisher { - self.pokeService - .getPokeMessages(messageType: type.rawValue) - .map { $0.toDomain() } - .eraseToAnyPublisher() - } - - public func poke(userId: Int, message: String) -> AnyPublisher { - self.pokeService - .poke(userId: userId, message: message) - .mapErrorToPokeError() - .map { $0.toDomain() } - .eraseToAnyPublisher() - } + public func getRandomAcquaintances( + randomUserType: PokeRandomUserType, + size: Int + ) -> AnyPublisher<[PokeUserModel], Error> { + self.pokeService + .getRandomUsers(randomType: randomUserType.rawValue, size: size) + .map { $0.map { $0.toDomain() } } + .eraseToAnyPublisher() + } + + public func getMesseageTemplates(type: PokeMessageType) -> AnyPublisher { + self.pokeService + .getPokeMessages(messageType: type.rawValue) + .map { $0.toDomain() } + .eraseToAnyPublisher() + } + + public func poke(userId: Int, message: String) -> AnyPublisher { + self.pokeService + .poke(userId: userId, message: message) + .mapErrorToPokeError() + .map { $0.toDomain() } + .eraseToAnyPublisher() + } } diff --git a/SOPT-iOS/Projects/Domain/Sources/Model/PokeRandomUserType.swift b/SOPT-iOS/Projects/Domain/Sources/Model/PokeRandomUserType.swift new file mode 100644 index 00000000..c70f083e --- /dev/null +++ b/SOPT-iOS/Projects/Domain/Sources/Model/PokeRandomUserType.swift @@ -0,0 +1,18 @@ +// +// PokeRandomUserType.swift +// Domain +// +// Created by Ian on 6/2/24. +// Copyright © 2024 SOPT-iOS. All rights reserved. +// + +public enum PokeRandomUserType: String { + case all = "ALL" + case generation = "GENERATION" + case mbti = "MBTI" + case sojuCapacity = "SOJU_CAPACITY" +} + +public enum PokeRandomUserQueryCount { + static let onboardingPage = 6 +} diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/PokeOnboardingRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/PokeOnboardingRepositoryInterface.swift index 345d10f3..2babef05 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/PokeOnboardingRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/PokeOnboardingRepositoryInterface.swift @@ -9,6 +9,8 @@ import Combine public protocol PokeOnboardingRepositoryInterface: PokeRepositoryInterface { - func getRandomAcquaintances() -> AnyPublisher<[PokeUserModel], Error> - func getMesseageTemplates(type: PokeMessageType) -> AnyPublisher + func getRandomAcquaintances(randomUserType: PokeRandomUserType, size: Int) -> AnyPublisher<[PokeUserModel], Error> + func getMesseageTemplates(type: PokeMessageType) -> AnyPublisher } + + diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/PokeOnboardingUsecase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/PokeOnboardingUsecase.swift index f32b47a6..50a81f0f 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/PokeOnboardingUsecase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/PokeOnboardingUsecase.swift @@ -11,53 +11,52 @@ import Combine import Core public protocol PokeOnboardingUsecase { - func getRandomAcquaintances() - func poke(userId: Int, message: PokeMessageModel) - - var randomAcquaintances: PassthroughSubject<[PokeUserModel], Never> { get } - var pokedResponse: PassthroughSubject { get } - var errorMessage: PassthroughSubject { get } + func getRandomAcquaintances() + func poke(userId: Int, message: PokeMessageModel) + + var randomAcquaintances: PassthroughSubject<[PokeUserModel], Never> { get } + var pokedResponse: PassthroughSubject { get } + var errorMessage: PassthroughSubject { get } } public final class DefaultPokeOnboardingUsecase { - private let repository: PokeOnboardingRepositoryInterface - private let cancelBag = CancelBag() - - public let randomAcquaintances = PassthroughSubject<[PokeUserModel], Never>() - public let pokedResponse = PassthroughSubject() - public let errorMessage = PassthroughSubject() - - public init(repository: PokeOnboardingRepositoryInterface) { - self.repository = repository - } + private let repository: PokeOnboardingRepositoryInterface + private let cancelBag = CancelBag() + + public let randomAcquaintances = PassthroughSubject<[PokeUserModel], Never>() + public let pokedResponse = PassthroughSubject() + public let errorMessage = PassthroughSubject() + + public init(repository: PokeOnboardingRepositoryInterface) { + self.repository = repository + } } extension DefaultPokeOnboardingUsecase: PokeOnboardingUsecase { - public func getRandomAcquaintances() { - self.repository - .getRandomAcquaintances() - .sink( - receiveCompletion: { _ in }, - receiveValue: { [weak self] value in - self?.randomAcquaintances.send(value) - } - ).store(in: self.cancelBag) - } - - public func poke(userId: Int, message: PokeMessageModel) { - self.repository - .poke(userId: userId, message: message.content) - .catch { [weak self] error in - let message = error.toastMessage - self?.errorMessage.send(message) - return Empty() - } - .sink( - receiveCompletion: { _ in }, - receiveValue: { [weak self] value in - self?.pokedResponse.send(value) - } - ).store(in: self.cancelBag) - } + public func getRandomAcquaintances() { + self.repository + .getRandomAcquaintances(randomUserType: .all, size: PokeRandomUserQueryCount.onboardingPage) + .sink( + receiveCompletion: { _ in }, + receiveValue: { [weak self] value in + self?.randomAcquaintances.send(value) + } + ).store(in: self.cancelBag) + } + + public func poke(userId: Int, message: PokeMessageModel) { + self.repository + .poke(userId: userId, message: message.content) + .catch { [weak self] error in + let message = error.toastMessage + self?.errorMessage.send(message) + return Empty() + } + .sink( + receiveCompletion: { _ in }, + receiveValue: { [weak self] value in + self?.pokedResponse.send(value) + } + ).store(in: self.cancelBag) + } } - diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/API/PokeAPI.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/API/PokeAPI.swift index 5a44333e..37915ff3 100644 --- a/SOPT-iOS/Projects/Modules/Networks/Sources/API/PokeAPI.swift +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/API/PokeAPI.swift @@ -13,66 +13,68 @@ import Moya import Core public enum PokeAPI { - case isNewUser - case getWhoPokedToMe - case getWhoPokedToMeList(pageIndex: String) - case getFriend - case getFriendRandomUser - case getFriendList - case getFriendListWithRelation(relation: String, page: Int) - case getRandomUsers - case getPokeMessages(messageType: String) - case poke(userId: String, params: Parameters) + case isNewUser + case getWhoPokedToMe + case getWhoPokedToMeList(pageIndex: String) + case getFriend + case getFriendRandomUser + case getFriendList + case getFriendListWithRelation(relation: String, page: Int) + case getRandomUsers(params: Parameters) + case getPokeMessages(messageType: String) + case poke(userId: String, params: Parameters) } extension PokeAPI: BaseAPI { - public static var apiType: APIType = .poke - - public var path: String { - switch self { - case .isNewUser: - return "/new" - case .getWhoPokedToMe: - return "/to/me" - case .getWhoPokedToMeList: - return "/to/me/list" - case .getFriend: - return "/friend" - case .getFriendRandomUser: - return "/friend/random-user" - case .getFriendList, .getFriendListWithRelation: - return "/friend/list" - case .getRandomUsers: - return "/random-user" - case .getPokeMessages: - return "/message" - case .poke(let userId, _): - return "/\(userId)" - } + public static var apiType: APIType = .poke + + public var path: String { + switch self { + case .isNewUser: + return "/new" + case .getWhoPokedToMe: + return "/to/me" + case .getWhoPokedToMeList: + return "/to/me/list" + case .getFriend: + return "/friend" + case .getFriendRandomUser: + return "/friend/random-user" + case .getFriendList, .getFriendListWithRelation: + return "/friend/list" + case .getRandomUsers: + return "/random-user" + case .getPokeMessages: + return "/message" + case .poke(let userId, _): + return "/\(userId)" } - - public var method: Moya.Method { - switch self { - case .isNewUser, .getWhoPokedToMe, .getWhoPokedToMeList, .getFriend, .getFriendListWithRelation, .getFriendRandomUser, - .getFriendList, .getRandomUsers, .getPokeMessages: - return .get - case .poke: - return .put - } + } + + public var method: Moya.Method { + switch self { + case .isNewUser, .getWhoPokedToMe, .getWhoPokedToMeList, .getFriend, .getFriendListWithRelation, .getFriendRandomUser, + .getFriendList, .getRandomUsers, .getPokeMessages: + return .get + case .poke: + return .put } - - public var task: Moya.Task { - switch self { - case .getWhoPokedToMeList(let pageIndex): - return .requestParameters(parameters: ["page": pageIndex], encoding: URLEncoding.queryString) - case .getPokeMessages(let messageType): - return .requestParameters(parameters: ["messageType": messageType], encoding: URLEncoding.queryString) - case .getFriendListWithRelation(let relation, let page): - return .requestParameters(parameters: ["type": relation, "page": page], encoding: URLEncoding.queryString) - case .poke(_, let params): - return .requestParameters(parameters: params, encoding: JSONEncoding.default) - default: - return .requestPlain - } + } + + public var task: Moya.Task { + switch self { + case .getWhoPokedToMeList(let pageIndex): + return .requestParameters(parameters: ["page": pageIndex], encoding: URLEncoding.queryString) + case .getPokeMessages(let messageType): + return .requestParameters(parameters: ["messageType": messageType], encoding: URLEncoding.queryString) + case .getFriendListWithRelation(let relation, let page): + return .requestParameters(parameters: ["type": relation, "page": page], encoding: URLEncoding.queryString) + case .poke(_, let params): + return .requestParameters(parameters: params, encoding: JSONEncoding.default) + case .getRandomUsers(let params): + return .requestParameters(parameters: params, encoding: URLEncoding.queryString) + default: + return .requestPlain } + } } diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/PokeUserEntity.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/PokeUserEntity.swift index 95e4c5e2..f3701303 100644 --- a/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/PokeUserEntity.swift +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Entity/PokeUserEntity.swift @@ -9,39 +9,44 @@ import Foundation public struct PokeUserEntity { - public let userId: Int - public let playgroundId: Int - public let profileImage: String - public let 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 userId: Int + public let playgroundId: Int + public let profileImage: String + public let 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 } extension PokeUserEntity: Codable { - public enum CodingKeys: CodingKey { - case userId, playgroundId, profileImage, name, generation, part, pokeNum, - message, relationName, mutualRelationMessage, isFirstMeet, isAlreadyPoke - } + public enum CodingKeys: CodingKey { + case userId, playgroundId, profileImage, name, generation, part, pokeNum, + message, relationName, mutualRelationMessage, isFirstMeet, isAlreadyPoke, + isAnonymous, anonymousName + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - self.userId = try container.decode(Int.self, forKey: .userId) - self.playgroundId = try container.decode(Int.self, forKey: .playgroundId) - self.profileImage = try container.decodeIfPresent(String.self, forKey: .profileImage) ?? "" - self.name = try container.decode(String.self, forKey: .name) - self.generation = try container.decode(Int.self, forKey: .generation) - self.part = try container.decode(String.self, forKey: .part) - self.pokeNum = try container.decode(Int.self, forKey: .pokeNum) - self.message = try container.decode(String.self, forKey: .message) - self.relationName = try container.decode(String.self, forKey: .relationName) - self.mutualRelationMessage = try container.decode(String.self, forKey: .mutualRelationMessage) - self.isFirstMeet = try container.decode(Bool.self, forKey: .isFirstMeet) - self.isAlreadyPoke = try container.decode(Bool.self, forKey: .isAlreadyPoke) - } + self.userId = try container.decode(Int.self, forKey: .userId) + self.playgroundId = try container.decode(Int.self, forKey: .playgroundId) + self.profileImage = try container.decodeIfPresent(String.self, forKey: .profileImage) ?? "" + self.name = try container.decode(String.self, forKey: .name) + self.generation = try container.decode(Int.self, forKey: .generation) + self.part = try container.decode(String.self, forKey: .part) + self.pokeNum = try container.decode(Int.self, forKey: .pokeNum) + self.message = try container.decode(String.self, forKey: .message) + self.relationName = try container.decode(String.self, forKey: .relationName) + self.mutualRelationMessage = try container.decode(String.self, forKey: .mutualRelationMessage) + self.isFirstMeet = try container.decode(Bool.self, forKey: .isFirstMeet) + self.isAlreadyPoke = try container.decode(Bool.self, forKey: .isAlreadyPoke) + self.isAnonymous = try container.decode(Bool.self, forKey: .isAnonymous) + self.anonymousName = try container.decode(String.self, forKey: .anonymousName) + } } diff --git a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift index b89b95ce..81907110 100644 --- a/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift +++ b/SOPT-iOS/Projects/Modules/Networks/Sources/Service/PokeService.swift @@ -14,58 +14,73 @@ import Moya public typealias DefaultPokeService = BaseService public protocol PokeService { - func isNewUser() -> AnyPublisher - func getWhoPokedToMe() -> AnyPublisher - func getWhoPokedToMeList(pageIndex: String) -> AnyPublisher - func getFriend() -> AnyPublisher<[PokeUserEntity], Error> - func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error> - func getFriendList() -> AnyPublisher - func getFriendList(relation: String, page: Int) -> AnyPublisher - func getRandomUsers() -> AnyPublisher<[PokeUserEntity], Error> - func getPokeMessages(messageType: String) -> AnyPublisher - func poke(userId: Int, message: String) -> AnyPublisher + func isNewUser() -> AnyPublisher + func getWhoPokedToMe() -> AnyPublisher + func getWhoPokedToMeList(pageIndex: String) -> AnyPublisher + func getFriend() -> AnyPublisher<[PokeUserEntity], Error> + func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error> + func getFriendList() -> AnyPublisher + func getFriendList(relation: String, page: Int) -> AnyPublisher + func getRandomUsers(randomType: String, size: Int) -> AnyPublisher<[PokeUserEntity], Error> + func getPokeMessages(messageType: String) -> AnyPublisher + func poke(userId: Int, message: String, isAnonymous: Bool) -> AnyPublisher +} + +extension PokeService { + // TODO(@승호): 컴파일 되도록 임시 처리 합니다. 작업시에 수정해 주세요~ + public func poke(userId: Int, message: String, isAnonymous: Bool = false) -> AnyPublisher { + self.poke(userId: userId, message: message, isAnonymous: isAnonymous) + } } extension DefaultPokeService: PokeService { - public func isNewUser() -> AnyPublisher { - requestObjectInCombine(.isNewUser) - } - - public func getWhoPokedToMe() -> AnyPublisher { - requestObjectInCombine(.getWhoPokedToMe) - } - - public func getWhoPokedToMeList(pageIndex: String) -> AnyPublisher { - requestObjectInCombine(.getWhoPokedToMeList(pageIndex: pageIndex)) - } - - public func getFriend() -> AnyPublisher<[PokeUserEntity], Error> { - requestObjectInCombine(.getFriend) - } - - public func getFriendList(relation: String, page: Int) -> AnyPublisher { - requestObjectInCombine(.getFriendListWithRelation(relation: relation, page: page)) - } - - public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error> { - requestObjectInCombine(.getFriendRandomUser) - } - - public func getFriendList() -> AnyPublisher { - requestObjectInCombine(.getFriendList) - } - - public func getRandomUsers() -> AnyPublisher<[PokeUserEntity], Error> { - requestObjectInCombine(.getRandomUsers) - } - - public func getPokeMessages(messageType: String) -> AnyPublisher { - requestObjectInCombine(.getPokeMessages(messageType: messageType)) - } + public func isNewUser() -> AnyPublisher { + requestObjectInCombine(.isNewUser) + } + + public func getWhoPokedToMe() -> AnyPublisher { + requestObjectInCombine(.getWhoPokedToMe) + } + + public func getWhoPokedToMeList(pageIndex: String) -> AnyPublisher { + requestObjectInCombine(.getWhoPokedToMeList(pageIndex: pageIndex)) + } + + public func getFriend() -> AnyPublisher<[PokeUserEntity], Error> { + requestObjectInCombine(.getFriend) + } + + public func getFriendList(relation: String, page: Int) -> AnyPublisher { + requestObjectInCombine(.getFriendListWithRelation(relation: relation, page: page)) + } + + public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserEntity], Error> { + requestObjectInCombine(.getFriendRandomUser) + } + + public func getFriendList() -> AnyPublisher { + requestObjectInCombine(.getFriendList) + } + + public func getRandomUsers(randomType: String, size: Int) -> AnyPublisher<[PokeUserEntity], Error> { + let params: [String: Any] = [ + "randomType": randomType, + "size": size + ] + + return requestObjectInCombine(.getRandomUsers(params: params)) + } + + public func getPokeMessages(messageType: String) -> AnyPublisher { + requestObjectInCombine(.getPokeMessages(messageType: messageType)) + } + + public func poke(userId: Int, message: String, isAnonymous: Bool) -> AnyPublisher { + let params: [String: Any] = [ + "message": message, + "isAnonymous": isAnonymous + ] - public func poke(userId: Int, message: String) -> AnyPublisher { - let params: [String: Any] = ["message": message] - - return requestObjectWithNetworkErrorInCombine(.poke(userId: String(describing: userId), params: params)) - } + return requestObjectWithNetworkErrorInCombine(.poke(userId: String(describing: userId), params: params)) + } }