From 2891df4184de9500aaca6a07df55aad246fba9a2 Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Tue, 11 Apr 2023 22:46:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Feat]=20#144=20-=20UserId=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C,=20RankDetail=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Enum/MissionListSceneType.swift | 2 +- .../Sources/Literals/UserDefaultKeyLIst.swift | 1 - .../Repository/ListDetailRepository.swift | 10 +++--- .../Repository/MissionListRepository.swift | 31 +++++++++++++---- .../Repository/RankingRepository.swift | 2 +- .../Repository/SettingRepository.swift | 13 ++++---- .../Transform/RankDetailTransform.swift | 33 +++++++++++++++++++ .../Sources/Transform/Rankingtransform.swift | 1 - .../Domain/Sources/Model/RankingModel.swift | 4 +-- .../Domain/Sources/Model/SignInModel.swift | 19 ----------- .../ListDetailRepositoryInterface.swift | 2 +- .../MissionListRepositoryInterface.swift | 2 +- .../SignInRepositoryInterface.swift | 2 ++ .../Sources/UseCase/ListDetailUseCase.swift | 10 +----- .../Sources/UseCase/MissionListUseCase.swift | 10 +++--- .../Sources/UseCase/RankingUseCase.swift | 5 +-- .../Sources/SignInScene/VC/SignInVC.swift | 12 ++++++- .../MainFeature/Sources/MainFeature.swift | 9 ----- .../Sources/MainScene/VC/MainVC.swift | 11 +++++++ .../Sources/SettingScene/VC/SettingVC.swift | 2 +- .../StampFeatureViewControllable.swift | 2 +- .../ListDetailScene/VC/ListDetailVC.swift | 2 +- .../ViewModel/ListDetailViewModel.swift | 20 +++++------ .../MissionListScene/VC/MissionListVC.swift | 6 ++-- .../ViewModel/MissionListViewModel.swift | 6 ++-- .../RankingScene/Cells/RankingListCVC.swift | 3 +- .../Cells/RankingListTappable.swift | 4 +-- .../Sources/RankingScene/VC/RankingVC.swift | 9 +++-- .../Modules/Network/Sources/API/AuthAPI.swift | 10 +++--- .../Network/Sources/API/MissionAPI.swift | 8 ++--- .../Modules/Network/Sources/API/RankAPI.swift | 19 ++++++++--- .../Network/Sources/API/StampAPI.swift | 29 ++++++++-------- .../Modules/Network/Sources/API/UserAPI.swift | 16 ++++----- .../Sources/Entity/ListDetailEntity.swift | 6 ++-- .../Sources/Entity/MissionListEntity.swift | 1 - .../Sources/Entity/RankDetailEntity.swift | 23 +++++++++++++ .../Sources/Entity/RankingEntity.swift | 3 +- .../Network/Sources/Foundation/BaseAPI.swift | 18 +++++----- .../Network/Sources/Service/AuthService.swift | 12 +++---- .../Sources/Service/MissionService.swift | 18 +++++----- .../Network/Sources/Service/RankService.swift | 18 ++++++---- .../Sources/Service/StampService.swift | 24 +++++++------- .../Network/Sources/Service/UserService.swift | 7 ++-- .../Sources/ModuleFactory/DIContainer.swift | 6 ++-- 44 files changed, 253 insertions(+), 198 deletions(-) create mode 100644 SOPT-iOS/Projects/Data/Sources/Transform/RankDetailTransform.swift delete mode 100644 SOPT-iOS/Projects/Domain/Sources/Model/SignInModel.swift delete mode 100644 SOPT-iOS/Projects/Features/MainFeature/Sources/MainFeature.swift create mode 100644 SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankDetailEntity.swift diff --git a/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift b/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift index 8b92ca9cd..43913fe1d 100644 --- a/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift +++ b/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift @@ -9,7 +9,7 @@ @frozen public enum MissionListSceneType { case `default` - case ranking(userName: String, sentence: String, userId: Int) + case ranking(userName: String, sentence: String) var isRankingView: Bool { switch self { diff --git a/SOPT-iOS/Projects/Core/Sources/Literals/UserDefaultKeyLIst.swift b/SOPT-iOS/Projects/Core/Sources/Literals/UserDefaultKeyLIst.swift index a7e341f4b..5adc94595 100644 --- a/SOPT-iOS/Projects/Core/Sources/Literals/UserDefaultKeyLIst.swift +++ b/SOPT-iOS/Projects/Core/Sources/Literals/UserDefaultKeyLIst.swift @@ -12,7 +12,6 @@ public struct UserDefaultKeyList { public struct Auth { @UserDefaultWrapper(key: "deviceToken") public static var deviceToken @UserDefaultWrapper(key: "endpointArnForSNS") public static var endpointArnForSNS - @UserDefaultWrapper(key: "userId") public static var userId @UserDefaultWrapper(key: "appAccessToken") public static var appAccessToken @UserDefaultWrapper(key: "appRefreshToken") public static var appRefreshToken @UserDefaultWrapper(key: "playgroundToken") public static var playgroundToken diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/ListDetailRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/ListDetailRepository.swift index 0885a76ac..c967e3083 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/ListDetailRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/ListDetailRepository.swift @@ -14,7 +14,6 @@ import Network public class ListDetailRepository { - private let userId: Int = UserDefaultKeyList.Auth.userId ?? 1 private let stampService: StampService private let cancelBag = CancelBag() @@ -24,21 +23,20 @@ public class ListDetailRepository { } extension ListDetailRepository: ListDetailRepositoryInterface { - public func fetchListDetail(missionId: Int, userId: Int?) -> Driver { - let targetUserId = userId ?? (self.userId) - return stampService.fetchStampListDetail(userId: targetUserId, missionId: missionId) + public func fetchListDetail(missionId: Int) -> Driver { + return stampService.fetchStampListDetail(missionId: missionId) .map { $0.toDomain() } .asDriver() } public func postStamp(missionId: Int, stampData: [Any]) -> AnyPublisher { - return stampService.postStamp(userId: userId, missionId: missionId, requestModel: stampData) + return stampService.postStamp(missionId: missionId, requestModel: stampData) .map { $0.toDomain() } .eraseToAnyPublisher() } public func putStamp(missionId: Int, stampData: [Any]) -> Driver { - return stampService.putStamp(userId: userId, missionId: missionId, requestModel: stampData) + return stampService.putStamp(missionId: missionId, requestModel: stampData) .map { $0.toDomain() } .asDriver() } diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/MissionListRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/MissionListRepository.swift index 20ac50f27..10262327b 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/MissionListRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/MissionListRepository.swift @@ -15,29 +15,46 @@ import Network public class MissionListRepository { private let missionService: MissionService + private let rankService: RankService private let cancelBag = CancelBag() - public init(service: MissionService) { - self.missionService = service + public init(missionService: MissionService, rankService: RankService) { + self.missionService = missionService + self.rankService = rankService } } extension MissionListRepository: MissionListRepositoryInterface { - public func fetchMissionList(type: MissionListFetchType, userId: Int?) -> AnyPublisher<[MissionListModel], Error> { - let userId = userId ?? (UserDefaultKeyList.Auth.userId ?? 1) + public func fetchMissionList(type: MissionListFetchType, userName: String?) -> AnyPublisher<[MissionListModel], Error> { + guard let userName else { + return fetchMissionList(type: type) + } + + return fetchRankDetail(userName: userName) + } +} + +extension MissionListRepository { + private func fetchMissionList(type: MissionListFetchType) -> AnyPublisher<[MissionListModel], Error> { switch type { case .all: - return missionService.fetchAllMissionList(userId: userId) + return missionService.fetchAllMissionList() .map { $0.toDomain() } .eraseToAnyPublisher() case .complete: - return missionService.fetchCompleteMissionList(userId: userId) + return missionService.fetchCompleteMissionList() .map { $0.toDomain() } .eraseToAnyPublisher() case .incomplete: - return missionService.fetchIncompleteMissionList(userId: userId) + return missionService.fetchIncompleteMissionList() .map { $0.toDomain() } .eraseToAnyPublisher() } } + + private func fetchRankDetail(userName: String) -> AnyPublisher<[MissionListModel], Error> { + rankService.fetchRankDetail(userName: userName) + .map { $0.toDomain() } + .eraseToAnyPublisher() + } } diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/RankingRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/RankingRepository.swift index bd6355241..5be03fd94 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/RankingRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/RankingRepository.swift @@ -25,7 +25,7 @@ public class RankingRepository { extension RankingRepository: RankingRepositoryInterface { public func fetchRankingListModel() -> AnyPublisher<[Domain.RankingModel], Error> { return self.rankService - .fetchRankingList(userId: UserDefaultKeyList.Auth.userId ?? 1) + .fetchRankingList() .map({ entity in entity.map { $0.toDomain() } }) diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift index ccd81c6bc..6691d0f2c 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift @@ -14,7 +14,6 @@ import Network public class SettingRepository { - private let userId: Int = UserDefaultKeyList.Auth.userId ?? 0 private let authService: AuthService private let stampService: StampService private let rankService: RankService @@ -30,13 +29,13 @@ public class SettingRepository { extension SettingRepository: SettingRepositoryInterface { public func resetStamp() -> Driver { - stampService.resetStamp(userId: userId) + stampService.resetStamp() .map { $0 == 200 } .asDriver() } public func editSentence(sentence: String) -> AnyPublisher { - return rankService.editSentence(userId: userId, sentence: sentence) + return rankService.editSentence(sentence: sentence) .handleEvents(receiveOutput: { entity in UserDefaultKeyList.User.sentence = entity.toDomain() }) @@ -46,17 +45,19 @@ extension SettingRepository: SettingRepositoryInterface { } public func editNickname(nickname: String) -> AnyPublisher { - return authService.changeNickname(userId: userId, nickname: nickname) + return authService.changeNickname(nickname: nickname) .map { _ in true } .replaceError(with: false) .eraseToAnyPublisher() } public func withdrawal() -> AnyPublisher { - return authService.withdrawal(userId: userId) + return authService.withdrawal() .handleEvents(receiveOutput: { status in if status == 200 { - UserDefaultKeyList.Auth.userId = nil + UserDefaultKeyList.Auth.appAccessToken = nil + UserDefaultKeyList.Auth.appRefreshToken = nil + UserDefaultKeyList.Auth.playgroundToken = nil UserDefaultKeyList.User.sentence = nil } }) diff --git a/SOPT-iOS/Projects/Data/Sources/Transform/RankDetailTransform.swift b/SOPT-iOS/Projects/Data/Sources/Transform/RankDetailTransform.swift new file mode 100644 index 000000000..e9de91962 --- /dev/null +++ b/SOPT-iOS/Projects/Data/Sources/Transform/RankDetailTransform.swift @@ -0,0 +1,33 @@ +// +// RankDetailTransform.swift +// Data +// +// Created by Junho Lee on 2023/04/11. +// Copyright © 2023 SOPT-iOS. All rights reserved. +// + +import Foundation + +import Core +import Domain +import Network + +extension RankDetailEntity { + + public func toDomain() -> [MissionListModel] { + return self.userMissions + .map { $0.toMissionListModel() } + } +} + +extension UserMission { + public func toMissionListModel() -> MissionListModel { + return .init( + id: self.id, + title: self.title, + level: self.level, + isCompleted: true + ) + } +} + diff --git a/SOPT-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift b/SOPT-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift index f2d1af2dd..05d4f4a71 100644 --- a/SOPT-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift +++ b/SOPT-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift @@ -16,7 +16,6 @@ extension RankingEntity { public func toDomain() -> RankingModel { return .init(username: self.nickname, - usreId: self.userID, score: self.point, sentence: self.profileMessage ?? I18N.RankingList.noSentenceText) } diff --git a/SOPT-iOS/Projects/Domain/Sources/Model/RankingModel.swift b/SOPT-iOS/Projects/Domain/Sources/Model/RankingModel.swift index 4da4f7c14..5a52e3935 100644 --- a/SOPT-iOS/Projects/Domain/Sources/Model/RankingModel.swift +++ b/SOPT-iOS/Projects/Domain/Sources/Model/RankingModel.swift @@ -10,15 +10,13 @@ import Foundation public struct RankingModel: Hashable { public let username: String - public let userId: Int public let score: Int public let sentence: String public var isMyRanking: Bool = false - public init(username: String, usreId: Int, score: Int, sentence: String) { + public init(username: String, score: Int, sentence: String) { self.username = username - self.userId = usreId self.score = score self.sentence = sentence } diff --git a/SOPT-iOS/Projects/Domain/Sources/Model/SignInModel.swift b/SOPT-iOS/Projects/Domain/Sources/Model/SignInModel.swift deleted file mode 100644 index dd8c07e0e..000000000 --- a/SOPT-iOS/Projects/Domain/Sources/Model/SignInModel.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// SignInModel.swift -// Domain -// -// Created by devxsby on 2022/12/23. -// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. -// - -import Foundation - -public struct SignInModel { - let userId: Int? - let message: String? - - public init(userId: Int?, message: String?) { - self.userId = userId - self.message = message - } -} diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/ListDetailRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/ListDetailRepositoryInterface.swift index b7cf4e3d4..362f67aec 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/ListDetailRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/ListDetailRepositoryInterface.swift @@ -11,7 +11,7 @@ import Core import Combine public protocol ListDetailRepositoryInterface { - func fetchListDetail(missionId: Int, userId: Int?) -> Driver + func fetchListDetail(missionId: Int) -> Driver func postStamp(missionId: Int, stampData: [Any]) -> AnyPublisher func putStamp(missionId: Int, stampData: [Any]) -> Driver func deleteStamp(stampId: Int) -> Driver diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/MissionListRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/MissionListRepositoryInterface.swift index 13a995e3b..85cbe2136 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/MissionListRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/MissionListRepositoryInterface.swift @@ -11,5 +11,5 @@ import Combine import Core public protocol MissionListRepositoryInterface { - func fetchMissionList(type: MissionListFetchType, userId: Int?) -> AnyPublisher<[MissionListModel], Error> + func fetchMissionList(type: MissionListFetchType, userName: String?) -> AnyPublisher<[MissionListModel], Error> } diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift index d62c7b1cc..e822de800 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift @@ -8,6 +8,8 @@ import Combine +// TODO: - User 유형 설정 방식 생각하기 + public protocol SignInRepositoryInterface { func requestSignIn(token: String) -> AnyPublisher } diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/ListDetailUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/ListDetailUseCase.swift index 4ddef4735..95ee0a9ab 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/ListDetailUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/ListDetailUseCase.swift @@ -12,7 +12,6 @@ import Combine public protocol ListDetailUseCase { func fetchListDetail(missionId: Int) - func fetchOtherListDetail(userId: Int, missionId: Int) func postStamp(missionId: Int, stampData: ListDetailRequestModel) func putStamp(missionId: Int, stampData: ListDetailRequestModel) func deleteStamp(stampId: Int) @@ -37,14 +36,7 @@ public class DefaultListDetailUseCase { extension DefaultListDetailUseCase: ListDetailUseCase { public func fetchListDetail(missionId: Int) { - repository.fetchListDetail(missionId: missionId, userId: nil) - .sink { model in - self.listDetailModel.send(model) - }.store(in: self.cancelBag) - } - - public func fetchOtherListDetail(userId: Int, missionId: Int) { - repository.fetchListDetail(missionId: missionId, userId: userId) + repository.fetchListDetail(missionId: missionId) .sink { model in self.listDetailModel.send(model) }.store(in: self.cancelBag) diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/MissionListUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/MissionListUseCase.swift index 7a6875615..4a596290c 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/MissionListUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/MissionListUseCase.swift @@ -12,7 +12,7 @@ import Core public protocol MissionListUseCase { func fetchMissionList(type: MissionListFetchType) - func fetchOtherUserMissionList(type: MissionListFetchType, userId: Int) + func fetchOtherUserMissionList(userName: String) var missionListModelsFetched: PassthroughSubject<[MissionListModel], Error> { get set } } @@ -28,8 +28,8 @@ public class DefaultMissionListUseCase { } extension DefaultMissionListUseCase: MissionListUseCase { - public func fetchOtherUserMissionList(type: MissionListFetchType, userId: Int) { - repository.fetchMissionList(type: type, userId: userId) + public func fetchMissionList(type: MissionListFetchType) { + repository.fetchMissionList(type: type, userName: nil) .sink(receiveCompletion: { event in print("completion: \(event)") }, receiveValue: { model in @@ -38,8 +38,8 @@ extension DefaultMissionListUseCase: MissionListUseCase { .store(in: cancelBag) } - public func fetchMissionList(type: MissionListFetchType) { - repository.fetchMissionList(type: type, userId: nil) + public func fetchOtherUserMissionList(userName: String) { + repository.fetchMissionList(type: .complete, userName: userName) .sink(receiveCompletion: { event in print("completion: \(event)") }, receiveValue: { model in diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift index 060465e0d..0c6a17603 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift @@ -57,9 +57,10 @@ extension DefaultRankingUseCase: RankingUseCase { } private func findMyRankingIndex(model: [RankingModel]) -> Int { - let myUserId = UserDefaultKeyList.Auth.userId ?? 1 + // TODO: 랭킹 Index 로직 수정 + let myUserName = "" let index = model.firstIndex { model in - model.userId == myUserId + model.username == myUserName } ?? 0 return index } diff --git a/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/VC/SignInVC.swift b/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/VC/SignInVC.swift index 987c180db..ec6d74c2a 100644 --- a/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/VC/SignInVC.swift +++ b/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/VC/SignInVC.swift @@ -73,6 +73,7 @@ public class SignInVC: UIViewController, SignInViewControllable { public override func viewDidLoad() { super.viewDidLoad() self.bindViewModels() + self.bindViews() self.setUI() self.setLayout() } @@ -151,7 +152,7 @@ extension SignInVC { private func bindViewModels() { - let input = SignInViewModel.Input(playgroundSignInFinished: Driver.just("")) + let input = SignInViewModel.Input(playgroundSignInFinished: Driver.just("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyNiIsImV4cCI6MTY4MTE5OTY1NH0.wlceN1uUoQZYL5Uz4lOiomwLTNK2YxQ-dlv3rtZHUZM")) let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag) output.isSignInSuccess.sink { [weak self] isSignInSuccess in @@ -168,4 +169,13 @@ extension SignInVC { let navigation = UINavigationController(rootViewController: factory.makeMainVC(userType: userType).viewController) ViewControllerUtils.setRootViewController(window: self.view.window!, viewController: navigation, withAnimation: true) } + + private func bindViews() { + // TODO: - 플그 로그인으로 연결 + signInButton.publisher(for: .touchUpInside) + .withUnretained(self) + .sink { owner, _ in + owner.setRootViewToMain() + }.store(in: self.cancelBag) + } } diff --git a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainFeature.swift b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainFeature.swift deleted file mode 100644 index 52b3a06bb..000000000 --- a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainFeature.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// MainFeature.swift -// MainFeatureTests -// -// Created by 김영인 on 2023/03/17. -// Copyright © 2023 SOPT-iOS. All rights reserved. -// - -import Foundation diff --git a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift index f901352d8..2b4a9e0cc 100644 --- a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift +++ b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift @@ -99,11 +99,22 @@ extension MainVC { withReuseIdentifier: AppServiceHeaderView.className) self.collectionView.register(AppServiceCVC.self, forCellWithReuseIdentifier: AppServiceCVC.className) } + + private func pushSoptampFeature() { + let vc = factory.makeMissionListVC(sceneType: .default).viewController + navigationController?.pushViewController(vc, animated: true) + } } // MARK: - UICollectionViewDelegate extension MainVC: UICollectionViewDelegate { + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + // TODO: - 디버깅을 위한 임시 솝탬프 피쳐 연결 + if indexPath.section == 3 { + pushSoptampFeature() + } + } } // MARK: - UICollectionViewDataSource diff --git a/SOPT-iOS/Projects/Features/SettingFeature/Sources/SettingScene/VC/SettingVC.swift b/SOPT-iOS/Projects/Features/SettingFeature/Sources/SettingScene/VC/SettingVC.swift index dc82e009d..df1062d75 100644 --- a/SOPT-iOS/Projects/Features/SettingFeature/Sources/SettingScene/VC/SettingVC.swift +++ b/SOPT-iOS/Projects/Features/SettingFeature/Sources/SettingScene/VC/SettingVC.swift @@ -113,7 +113,7 @@ extension SettingVC { } private func logout() { - UserDefaultKeyList.Auth.userId = nil + UserDefaultKeyList.Auth.appAccessToken = nil self.changeRootViewController() } diff --git a/SOPT-iOS/Projects/Features/StampFeature/Interface/Sources/StampFeatureViewControllable.swift b/SOPT-iOS/Projects/Features/StampFeature/Interface/Sources/StampFeatureViewControllable.swift index 55083f2f9..e9c4c92a8 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Interface/Sources/StampFeatureViewControllable.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Interface/Sources/StampFeatureViewControllable.swift @@ -25,7 +25,7 @@ public protocol StampFeatureViewBuildable { starLevel: StarViewLevel, missionId: Int, missionTitle: String, - otherUserId: Int?) -> ListDetailViewControllable + isOtherUser: Bool) -> ListDetailViewControllable func makeMissionCompletedVC(starLevel: StarViewLevel, completionHandler: (() -> Void)?) -> MissionCompletedViewControllable func makeRankingVC() -> RankingViewControllable func makeStampGuideVC() -> StampGuideViewControllable diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/VC/ListDetailVC.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/VC/ListDetailVC.swift index cdb7dce36..72e98df57 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/VC/ListDetailVC.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/VC/ListDetailVC.swift @@ -465,7 +465,7 @@ extension ListDetailVC { self.missionImageView.isUserInteractionEnabled = false } - if viewModel.otherUserId != nil { + if viewModel.isOtherUser { self.naviBar.hideRightButton() } } diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/ViewModel/ListDetailViewModel.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/ViewModel/ListDetailViewModel.swift index c9e1d384c..356668c6b 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/ViewModel/ListDetailViewModel.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/ListDetailScene/ViewModel/ListDetailViewModel.swift @@ -20,8 +20,8 @@ public class ListDetailViewModel: ViewModelType { public var missionId: Int! public var missionTitle: String! public var stampId: Int! - public var otherUserId: Int! - + public var isOtherUser: Bool + // MARK: - Inputs public struct Input { @@ -41,14 +41,14 @@ public class ListDetailViewModel: ViewModelType { } // MARK: - init - - public init(useCase: ListDetailUseCase, sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String, otherUserId: Int?) { + + public init(useCase: ListDetailUseCase, sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String, isOtherUser: Bool) { self.useCase = useCase self.sceneType = sceneType self.starLevel = starLevel self.missionId = missionId self.missionTitle = missionTitle - self.otherUserId = otherUserId + self.isOtherUser = isOtherUser } } @@ -62,11 +62,7 @@ extension ListDetailViewModel { .withUnretained(self) .sink { owner, _ in if owner.sceneType == .completed { - if let otherUserId = self.otherUserId { - owner.useCase.fetchOtherListDetail(userId: otherUserId, missionId: owner.missionId) - } else { - owner.useCase.fetchListDetail(missionId: owner.missionId) - } + owner.useCase.fetchListDetail(missionId: owner.missionId) } }.store(in: cancelBag) @@ -95,10 +91,10 @@ extension ListDetailViewModel { .sink { _ in self.useCase.deleteStamp(stampId: self.stampId) }.store(in: self.cancelBag) - + return output } - + private func bindOutput(output: Output, cancelBag: CancelBag) { let listDetailModel = useCase.listDetailModel let editSuccess = useCase.editSuccess diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift index 66ac2b891..6042ba4d7 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift @@ -45,7 +45,7 @@ public class MissionListVC: UIViewController, MissionListViewControllable { .setTitle("전체 미션") .setTitleTypoStyle(.SoptampFont.h2) .setTitleButtonMenu(menuItems: self.menuItems) - case .ranking(let username, _, _): + case .ranking(let username, _): return STNavigationBar(self, type: .titleWithLeftButton) .setTitle(username) .setRightButton(.none) @@ -69,7 +69,7 @@ public class MissionListVC: UIViewController, MissionListViewControllable { private lazy var sentenceLabel: SentencePaddingLabel = { let lb = SentencePaddingLabel() - if case let .ranking(_, sentence, _) = sceneType { + if case let .ranking(_, sentence) = sceneType { lb.text = sentence } lb.setTypoStyle(.SoptampFont.subtitle1) @@ -360,7 +360,7 @@ extension MissionListVC: UICollectionViewDelegate { starLevel: starLevel, missionId: model.id, missionTitle: model.title, - otherUserId: viewModel.otherUserId).viewController + isOtherUser: true).viewController self.navigationController?.pushViewController(detailVC, animated: true) default: return diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/ViewModel/MissionListViewModel.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/ViewModel/MissionListViewModel.swift index 30ae05760..87c7ba7b6 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/ViewModel/MissionListViewModel.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/ViewModel/MissionListViewModel.swift @@ -17,7 +17,6 @@ public class MissionListViewModel: ViewModelType { private let useCase: MissionListUseCase private var cancelBag = CancelBag() public var missionListsceneType: MissionListSceneType! - public var otherUserId: Int? // MARK: - Inputs @@ -63,9 +62,8 @@ extension MissionListViewModel { private func fetchMissionList(type: MissionListFetchType) { switch self.missionListsceneType { - case .ranking(_, _, let userId): - self.otherUserId = userId - self.useCase.fetchOtherUserMissionList(type: .complete, userId: userId) + case .ranking(let userName, _): + self.useCase.fetchOtherUserMissionList(userName: userName) default: self.useCase.fetchMissionList(type: type) } diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListCVC.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListCVC.swift index 6a6776da6..7af81e017 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListCVC.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListCVC.swift @@ -155,7 +155,6 @@ extension RankingListCVC: RankingListTappable { func getModelItem() -> RankingListTapItem? { guard let model = model else { return nil } return RankingListTapItem.init(username: model.username, - sentence: model.sentence, - userId: model.userId) + sentence: model.sentence) } } diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListTappable.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListTappable.swift index a0806b9d0..671244d74 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListTappable.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/Cells/RankingListTappable.swift @@ -17,13 +17,11 @@ protocol RankingListTappable { public struct RankingListTapItem { public let username: String public let sentence: String - public let userId: Int } extension RankingModel { func toRankingListTapItem() -> RankingListTapItem { .init(username: self.username, - sentence: self.sentence, - userId: self.userId) + sentence: self.sentence) } } diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/VC/RankingVC.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/VC/RankingVC.swift index 9a440b3a3..9388ce150 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/VC/RankingVC.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/RankingScene/VC/RankingVC.swift @@ -227,9 +227,12 @@ extension RankingVC: UICollectionViewDelegate { } private func pushToOtherUserMissionListVC(item: RankingListTapItem) { - let otherUserMissionListVC = factory.makeMissionListVC(sceneType: .ranking(userName: item.username, - sentence: item.sentence, - userId: item.userId)).viewController + let otherUserMissionListVC = factory.makeMissionListVC( + sceneType: .ranking( + userName: item.username, + sentence: item.sentence + ) + ).viewController self.navigationController?.pushViewController(otherUserMissionListVC, animated: true) } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift index d4e756f45..21d88f9d4 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift @@ -13,8 +13,8 @@ import Moya public enum AuthAPI { case getNicknameAvailable(nickname: String) - case changeNickname(userId: Int, nickname: String) - case withdrawal(userId: Int) + case changeNickname(nickname: String) + case withdrawal case signIn(token: String) } @@ -25,8 +25,8 @@ extension AuthAPI: BaseAPI { // MARK: - Header public var headers: [String: String]? { switch self { - case .changeNickname(let userId, _), .withdrawal(let userId): - return HeaderType.userId(userId: userId).value + case .changeNickname, .withdrawal: + return HeaderType.jsonWithToken.value default: return HeaderType.json.value } } @@ -63,7 +63,7 @@ extension AuthAPI: BaseAPI { private var bodyParameters: Parameters? { var params: Parameters = [:] switch self { - case .changeNickname(_, let nickname): + case .changeNickname(let nickname): params["nickname"] = nickname case .signIn(let token): params["code"] = token diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/MissionAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/MissionAPI.swift index 4715d053f..45bdb01e6 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/MissionAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/MissionAPI.swift @@ -14,7 +14,7 @@ import Alamofire import Moya public enum MissionAPI { - case fetchMissionList(type: MissionListFetchType, userId: Int) + case fetchMissionList(type: MissionListFetchType) } extension MissionAPI: BaseAPI { @@ -24,8 +24,8 @@ extension MissionAPI: BaseAPI { // MARK: - Header public var headers: [String: String]? { switch self { - case .fetchMissionList(_, let userId): - return HeaderType.userId(userId: userId).value + case .fetchMissionList: + return HeaderType.jsonWithToken.value default: return HeaderType.json.value } } @@ -33,7 +33,7 @@ extension MissionAPI: BaseAPI { // MARK: - Path public var path: String { switch self { - case .fetchMissionList(let type, _): + case .fetchMissionList(let type): return "/\(type.path)" default: return "" } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift index 681a882e1..82d3e4c57 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift @@ -12,8 +12,9 @@ import Alamofire import Moya public enum RankAPI { - case rank(userId: Int) - case editSentence(userId: Int, sentence: String) + case rank + case rankDetail(userName: String) + case editSentence(sentence: String) } extension RankAPI: BaseAPI { @@ -23,8 +24,8 @@ extension RankAPI: BaseAPI { // MARK: - Header public var headers: [String: String]? { switch self { - case .rank(let userId), .editSentence(let userId, _): - return HeaderType.userId(userId: userId).value + case .rank, .editSentence, .rankDetail: + return HeaderType.jsonWithToken.value default: return HeaderType.json.value } } @@ -34,6 +35,8 @@ extension RankAPI: BaseAPI { switch self { case .rank: return "" + case .rankDetail: + return "/detail" case .editSentence: return "/profileMessage" } @@ -52,7 +55,9 @@ extension RankAPI: BaseAPI { private var bodyParameters: Parameters? { var params: Parameters = [:] switch self { - case .editSentence(_, let sentence): + case .rankDetail(let userName): + params["nickname"] = userName + case .editSentence(let sentence): params["profileMessage"] = sentence default: break } @@ -61,6 +66,8 @@ extension RankAPI: BaseAPI { private var parameterEncoding: ParameterEncoding { switch self { + case .rankDetail: + return URLEncoding.default default: return JSONEncoding.default } @@ -68,6 +75,8 @@ extension RankAPI: BaseAPI { public var task: Task { switch self { + case .rankDetail: + return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) case .editSentence: return .requestParameters(parameters: self.bodyParameters ?? [:], encoding: parameterEncoding) default: diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/StampAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/StampAPI.swift index 7ef6ac25a..01508884c 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/StampAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/StampAPI.swift @@ -12,11 +12,11 @@ import Alamofire import Moya public enum StampAPI { - case fetchStampListDetail(userId: Int, missionId: Int) - case postStamp(userId: Int, missionId: Int, requestModel: [Any]) - case putStamp(userId: Int, missionId: Int, requestModel: [Any]) + case fetchStampListDetail(missionId: Int) + case postStamp(missionId: Int, requestModel: [Any]) + case putStamp(missionId: Int, requestModel: [Any]) case deleteStamp(stampId: Int) - case resetStamp(userId: Int) + case resetStamp } extension StampAPI: BaseAPI { @@ -26,23 +26,21 @@ extension StampAPI: BaseAPI { // MARK: - Header public var headers: [String : String]? { switch self { - case .fetchStampListDetail(let userId, _), - .resetStamp(let userId): - return HeaderType.userId(userId: userId).value - case .postStamp(let userId, _, _), - .putStamp(let userId, _, _): - return HeaderType.multipart(userId: userId).value + case .fetchStampListDetail, .resetStamp: + return HeaderType.jsonWithToken.value + case .postStamp, .putStamp: + return HeaderType.multipartWithToken.value case .deleteStamp: - return HeaderType.json.value + return HeaderType.jsonWithToken.value } } // MARK: - Path public var path: String { switch self { - case .fetchStampListDetail(_, let missionId), - .postStamp(_ , let missionId, _), - .putStamp(_ , let missionId, _): + case .fetchStampListDetail(let missionId), + .postStamp(let missionId, _), + .putStamp(let missionId, _): return "/\(missionId)" case .deleteStamp(let stampId): return "/\(stampId)" @@ -82,8 +80,7 @@ extension StampAPI: BaseAPI { public var task: Task { switch self { - case .postStamp(_ , _, let requestModel), - .putStamp(_, _, let requestModel): + case .postStamp(_, let requestModel), .putStamp(_, let requestModel): var multipartData: [Moya.MultipartFormData] = [] let fileName = (self.method == .post) ? ".jpg" : ".png" diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift index 9a8e6a631..16de6ec43 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift @@ -12,7 +12,7 @@ import Alamofire import Moya public enum UserAPI { - case signIn(email: String, password: String) + case fetchUser } extension UserAPI: BaseAPI { @@ -22,16 +22,16 @@ extension UserAPI: BaseAPI { // MARK: - Path public var path: String { switch self { - case .signIn: - return "login" + case .fetchUser: + return "" } } // MARK: - Method public var method: Moya.Method { switch self { - case .signIn: - return .post + case .fetchUser: + return .get } } @@ -39,9 +39,7 @@ extension UserAPI: BaseAPI { private var bodyParameters: Parameters? { var params: Parameters = [:] switch self { - case .signIn(let email, let password): - params["email"] = email - params["password"] = password + default: break } return params } @@ -55,8 +53,6 @@ extension UserAPI: BaseAPI { public var task: Task { switch self { - case .signIn: - return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) default: return .requestPlain } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/ListDetailEntity.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/ListDetailEntity.swift index a57f27bb4..03cf8612d 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/ListDetailEntity.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/ListDetailEntity.swift @@ -14,21 +14,19 @@ public struct ListDetailEntity: Codable { public let id: Int public let contents: String public let images: [String] - public let userID, missionID: Int + public let missionID: Int enum CodingKeys: String, CodingKey { case createdAt, updatedAt, id, contents, images - case userID = "userId" case missionID = "missionId" } - public init(createdAt: String, updatedAt: String, id: Int, contents: String, images: [String], userID: Int, missionID: Int) { + public init(createdAt: String, updatedAt: String, id: Int, contents: String, images: [String], missionID: Int) { self.createdAt = createdAt self.updatedAt = updatedAt self.id = id self.contents = contents self.images = images - self.userID = userID self.missionID = missionID } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/MissionListEntity.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/MissionListEntity.swift index 43a092f61..eaafb6aca 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/MissionListEntity.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/MissionListEntity.swift @@ -14,7 +14,6 @@ public struct MissionListEntityElement: Codable { public let level: Int public let profileImage: [String]? public let isCompleted: Bool? - public let display: Bool? public var fetchTypeHandler: Bool? = false diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankDetailEntity.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankDetailEntity.swift new file mode 100644 index 000000000..cbd1c3f0f --- /dev/null +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankDetailEntity.swift @@ -0,0 +1,23 @@ +// +// RankDetailEntity.swift +// Network +// +// Created by Junho Lee on 2023/04/11. +// Copyright © 2023 SOPT-iOS. All rights reserved. +// + +import Foundation + +public struct RankDetailEntity: Codable { + public let nickname: String + public let profileMessage: String? + public let userMissions: [UserMission] +} + +public struct UserMission: Codable { + public let id: Int + public let title: String + public let level: Int + public let display: Bool + public let profileImage: String? +} diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankingEntity.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankingEntity.swift index a41ffa8e7..9ec7e3920 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankingEntity.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/RankingEntity.swift @@ -9,14 +9,13 @@ import Foundation public struct RankingEntity: Codable { - public let rank, userID: Int + public let rank: Int public let nickname: String public let point: Int public let profileMessage: String? enum CodingKeys: String, CodingKey { case rank - case userID = "userId" case nickname, point, profileMessage } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Foundation/BaseAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Foundation/BaseAPI.swift index bfbf3c0ad..c6e40f051 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Foundation/BaseAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Foundation/BaseAPI.swift @@ -9,6 +9,7 @@ import Alamofire import Moya import Foundation +import Core public enum APIType { case auth @@ -50,28 +51,25 @@ extension BaseAPI { } public var headers: [String: String]? { - return ["Content-Type": "application/json"] + return HeaderType.jsonWithToken.value } } public enum HeaderType { case json - case jsonUserId(userId: Int) - case userId(userId: Int) - case multipart(userId: Int) + case jsonWithToken + case multipartWithToken public var value: [String: String] { switch self { case .json: return ["Content-Type": "application/json"] - case .jsonUserId(let userId): + case .jsonWithToken: return ["Content-Type": "application/json", - "userId": String(userId)] - case .userId(let userId): - return ["userId": String(userId)] - case .multipart(let userId): + "Authorization": UserDefaultKeyList.Auth.appAccessToken ?? "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzb3B0LW1ha2VycyIsImlhdCI6MTY4MTIwMTkwNywic3ViIjoiMiIsImV4cCI6MTY4MTI4ODMwNywiaWQiOjIsInJvbGVzIjoiVVNFUiJ9.X-b45sMMQeUiyDnZEHdKEowor_g0wH_YlugeuAhWqYk"] + case .multipartWithToken: return ["Content-Type": "multipart/form-data", - "userId": String(userId)] + "Authorization": UserDefaultKeyList.Auth.appAccessToken ?? "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzb3B0LW1ha2VycyIsImlhdCI6MTY4MTIwMTkwNywic3ViIjoiMiIsImV4cCI6MTY4MTI4ODMwNywiaWQiOjIsInJvbGVzIjoiVVNFUiJ9.X-b45sMMQeUiyDnZEHdKEowor_g0wH_YlugeuAhWqYk"] } } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift index 35c8805fd..7c0f84f64 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift @@ -16,8 +16,8 @@ public typealias DefaultAuthService = BaseService public protocol AuthService { func getNicknameAvailable(nickname: String) -> AnyPublisher - func changeNickname(userId: Int, nickname: String) -> AnyPublisher - func withdrawal(userId: Int) -> AnyPublisher + func changeNickname(nickname: String) -> AnyPublisher + func withdrawal() -> AnyPublisher func signIn(token: String) -> AnyPublisher } @@ -27,12 +27,12 @@ extension DefaultAuthService: AuthService { return requestObjectInCombineNoResult(.getNicknameAvailable(nickname: nickname)) } - public func changeNickname(userId: Int, nickname: String) -> AnyPublisher { - return requestObjectInCombineNoResult(.changeNickname(userId: userId, nickname: nickname)) + public func changeNickname(nickname: String) -> AnyPublisher { + return requestObjectInCombineNoResult(.changeNickname(nickname: nickname)) } - public func withdrawal(userId: Int) -> AnyPublisher { - return requestObjectInCombineNoResult(.withdrawal(userId: userId)) + public func withdrawal() -> AnyPublisher { + return requestObjectInCombineNoResult(.withdrawal) } public func signIn(token: String) -> AnyPublisher { diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/MissionService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/MissionService.swift index 8c3b1c6ee..8885a73c5 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/MissionService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/MissionService.swift @@ -15,26 +15,26 @@ import Moya public typealias DefaultMissionService = BaseService public protocol MissionService { - func fetchAllMissionList(userId: Int) -> AnyPublisher - func fetchCompleteMissionList(userId: Int) -> AnyPublisher - func fetchIncompleteMissionList(userId: Int) -> AnyPublisher + func fetchAllMissionList() -> AnyPublisher + func fetchCompleteMissionList() -> AnyPublisher + func fetchIncompleteMissionList() -> AnyPublisher } extension DefaultMissionService: MissionService { - public func fetchAllMissionList(userId: Int) -> AnyPublisher { - requestObjectInCombine(MissionAPI.fetchMissionList(type: .all, userId: userId)) + public func fetchAllMissionList() -> AnyPublisher { + requestObjectInCombine(MissionAPI.fetchMissionList(type: .all)) } - public func fetchCompleteMissionList(userId: Int) -> AnyPublisher { - let response: AnyPublisher = requestObjectInCombine(MissionAPI.fetchMissionList(type: .complete, userId: userId)) + public func fetchCompleteMissionList() -> AnyPublisher { + let response: AnyPublisher = requestObjectInCombine(MissionAPI.fetchMissionList(type: .complete)) return response.map { entity in var newEntity = entity return newEntity.assignCompleteFetchType(true) }.eraseToAnyPublisher() } - public func fetchIncompleteMissionList(userId: Int) -> AnyPublisher { - let response: AnyPublisher = requestObjectInCombine(MissionAPI.fetchMissionList(type: .incomplete, userId: userId)) + public func fetchIncompleteMissionList() -> AnyPublisher { + let response: AnyPublisher = requestObjectInCombine(MissionAPI.fetchMissionList(type: .incomplete)) return response.map { entity in var newEntity = entity return newEntity.assignCompleteFetchType(false) diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift index 56c59cf24..606fcd51f 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift @@ -15,16 +15,22 @@ import Moya public typealias DefaultRankService = BaseService public protocol RankService { - func fetchRankingList(userId: Int) -> AnyPublisher<[RankingEntity], Error> - func editSentence(userId: Int, sentence: String) -> AnyPublisher + func fetchRankingList() -> AnyPublisher<[RankingEntity], Error> + func fetchRankDetail(userName: String) -> AnyPublisher + func editSentence(sentence: String) -> AnyPublisher } extension DefaultRankService: RankService { - public func fetchRankingList(userId: Int) -> AnyPublisher<[RankingEntity], Error> { - requestObjectInCombine(RankAPI.rank(userId: userId)) + + public func fetchRankingList() -> AnyPublisher<[RankingEntity], Error> { + requestObjectInCombine(RankAPI.rank) + } + + public func fetchRankDetail(userName: String) -> AnyPublisher { + requestObjectInCombine(RankAPI.rankDetail(userName: userName)) } - public func editSentence(userId: Int, sentence: String) -> AnyPublisher { - requestObjectInCombine(RankAPI.editSentence(userId: userId, sentence: sentence)) + public func editSentence(sentence: String) -> AnyPublisher { + requestObjectInCombine(RankAPI.editSentence(sentence: sentence)) } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/StampService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/StampService.swift index 93bf1afc8..3d10ca04f 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/StampService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/StampService.swift @@ -15,31 +15,31 @@ import Moya public typealias DefaultStampService = BaseService public protocol StampService { - func fetchStampListDetail(userId: Int, missionId: Int) -> AnyPublisher - func postStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher - func putStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher + func fetchStampListDetail(missionId: Int) -> AnyPublisher + func postStamp(missionId: Int, requestModel: [Any]) -> AnyPublisher + func putStamp(missionId: Int, requestModel: [Any]) -> AnyPublisher func deleteStamp(stampId: Int) -> AnyPublisher - func resetStamp(userId: Int) -> AnyPublisher + func resetStamp() -> AnyPublisher } extension DefaultStampService: StampService { - public func fetchStampListDetail(userId: Int, missionId: Int) -> AnyPublisher { - requestObjectInCombine(StampAPI.fetchStampListDetail(userId: userId, missionId: missionId)) + public func fetchStampListDetail(missionId: Int) -> AnyPublisher { + requestObjectInCombine(StampAPI.fetchStampListDetail(missionId: missionId)) } - public func postStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher { - requestObjectInCombine(StampAPI.postStamp(userId: userId, missionId: missionId, requestModel: requestModel)) + public func postStamp(missionId: Int, requestModel: [Any]) -> AnyPublisher { + requestObjectInCombine(StampAPI.postStamp(missionId: missionId, requestModel: requestModel)) } - public func putStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher { - requestObjectInCombine(StampAPI.putStamp(userId: userId, missionId: missionId, requestModel: requestModel)) + public func putStamp(missionId: Int, requestModel: [Any]) -> AnyPublisher { + requestObjectInCombine(StampAPI.putStamp(missionId: missionId, requestModel: requestModel)) } public func deleteStamp(stampId: Int) -> AnyPublisher { return requestObjectInCombineNoResult(StampAPI.deleteStamp(stampId: stampId)) } - public func resetStamp(userId: Int) -> AnyPublisher { - return requestObjectInCombineNoResult(StampAPI.resetStamp(userId: userId)) + public func resetStamp() -> AnyPublisher { + return requestObjectInCombineNoResult(StampAPI.resetStamp) } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift index 3c7673152..1538f7956 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift @@ -15,9 +15,12 @@ import Moya public typealias DefaultUserService = BaseService public protocol UserService { - + // TODO: - UserEntity 관련 변경사항 적용하기 + func fetchUser() -> AnyPublisher } extension DefaultUserService: UserService { - + public func fetchUser() -> AnyPublisher { + requestObjectInCombine(.fetchUser) + } } diff --git a/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift b/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift index 872c7763a..910f81c13 100644 --- a/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift +++ b/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift @@ -89,7 +89,7 @@ extension DIContainer: Features { // MARK: - StampFeature func makeMissionListVC(sceneType: MissionListSceneType) -> MissionListViewControllable { - let repository = MissionListRepository(service: missionService) + let repository = MissionListRepository(missionService: missionService, rankService: rankService) let useCase = DefaultMissionListUseCase(repository: repository) let viewModel = MissionListViewModel(useCase: useCase, sceneType: sceneType) let missionListVC = MissionListVC() @@ -102,7 +102,7 @@ extension DIContainer: Features { starLevel: StarViewLevel, missionId: Int, missionTitle: String, - otherUserId: Int?) -> ListDetailViewControllable { + isOtherUser: Bool) -> ListDetailViewControllable { let repository = ListDetailRepository(service: stampService) let useCase = DefaultListDetailUseCase(repository: repository) let viewModel = ListDetailViewModel(useCase: useCase, @@ -110,7 +110,7 @@ extension DIContainer: Features { starLevel: starLevel, missionId: missionId, missionTitle: missionTitle, - otherUserId: otherUserId) + isOtherUser: isOtherUser) let listDetailVC = ListDetailVC() listDetailVC.viewModel = viewModel listDetailVC.factory = self From 9652ce845eaf2f302e73d314b09eeb1989fd06e8 Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Tue, 11 Apr 2023 23:31:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Refactor]=20#144=20-=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=ED=95=9C=EB=A7=88?= =?UTF-8?q?=EB=94=94=20=ED=8E=B8=EC=A7=91=20=EB=B3=80=EA=B2=BD=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Enum/MissionListSceneType.swift | 2 +- .../Repository/SettingRepository.swift | 10 +++++----- .../Sources/Repository/SignUpRepository.swift | 4 ++-- .../Sources/MainScene/VC/MainVC.swift | 18 +++++++++++++++++- .../MainScene/Views/MainNavigationBar.swift | 2 +- .../MissionListScene/VC/MissionListVC.swift | 6 +++--- .../Modules/Network/Sources/API/AuthAPI.swift | 18 ++---------------- .../Modules/Network/Sources/API/RankAPI.swift | 11 +---------- .../Modules/Network/Sources/API/UserAPI.swift | 19 ++++++++++++++++++- .../Sources/Entity/EditSentenceEntity.swift | 7 ------- .../Network/Sources/Service/AuthService.swift | 11 ----------- .../Network/Sources/Service/RankService.swift | 5 ----- .../Network/Sources/Service/UserService.swift | 16 ++++++++++++++++ .../Sources/ModuleFactory/DIContainer.swift | 10 +++++----- 14 files changed, 71 insertions(+), 68 deletions(-) diff --git a/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift b/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift index 43913fe1d..03afdb6d1 100644 --- a/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift +++ b/SOPT-iOS/Projects/Core/Sources/Enum/MissionListSceneType.swift @@ -11,7 +11,7 @@ public enum MissionListSceneType { case `default` case ranking(userName: String, sentence: String) - var isRankingView: Bool { + public var isRankingView: Bool { switch self { case .default: return false case .ranking: return true diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift index 6691d0f2c..ba4442f59 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift @@ -16,13 +16,13 @@ public class SettingRepository { private let authService: AuthService private let stampService: StampService - private let rankService: RankService + private let userService: UserService private let cancelBag = CancelBag() - public init(authService: AuthService, stampService: StampService, rankService: RankService) { + public init(authService: AuthService, stampService: StampService, userService: UserService) { self.authService = authService self.stampService = stampService - self.rankService = rankService + self.userService = userService } } @@ -35,7 +35,7 @@ extension SettingRepository: SettingRepositoryInterface { } public func editSentence(sentence: String) -> AnyPublisher { - return rankService.editSentence(sentence: sentence) + return userService.editSentence(sentence: sentence) .handleEvents(receiveOutput: { entity in UserDefaultKeyList.User.sentence = entity.toDomain() }) @@ -45,7 +45,7 @@ extension SettingRepository: SettingRepositoryInterface { } public func editNickname(nickname: String) -> AnyPublisher { - return authService.changeNickname(nickname: nickname) + return userService.changeNickname(nickname: nickname) .map { _ in true } .replaceError(with: false) .eraseToAnyPublisher() diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/SignUpRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/SignUpRepository.swift index df42af7cf..f373f54d0 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/SignUpRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/SignUpRepository.swift @@ -14,10 +14,10 @@ import Network public class SignUpRepository { - private let networkService: AuthService + private let networkService: UserService private let cancelBag = CancelBag() - public init(service: AuthService) { + public init(service: UserService) { self.networkService = service } } diff --git a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift index 2b4a9e0cc..0c820478f 100644 --- a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift +++ b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/VC/MainVC.swift @@ -17,13 +17,14 @@ import Then import MainFeatureInterface import StampFeatureInterface +import SettingFeatureInterface public class MainVC: UIViewController, MainViewControllable { // MARK: - Properties public var viewModel: MainViewModel! - public var factory: StampFeatureViewBuildable! + public var factory: (StampFeatureViewBuildable & SettingFeatureViewBuildable)! private var cancelBag = CancelBag() // MARK: - UI Components @@ -45,6 +46,7 @@ public class MainVC: UIViewController, MainViewControllable { public override func viewDidLoad() { super.viewDidLoad() self.bindViewModels() + self.bindViews() self.setUI() self.setLayout() self.setDelegate() @@ -82,6 +84,15 @@ extension MainVC { let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag) } + private func bindViews() { + // FIXME: - 디버깅을 위한 임시 바인딩 + naviBar.myPageButton.publisher(for: .touchUpInside) + .withUnretained(self) + .sink { owner, _ in + owner.pushSettingFeature() + }.store(in: self.cancelBag) + } + private func setDelegate() { self.collectionView.delegate = self self.collectionView.dataSource = self @@ -104,6 +115,11 @@ extension MainVC { let vc = factory.makeMissionListVC(sceneType: .default).viewController navigationController?.pushViewController(vc, animated: true) } + + private func pushSettingFeature() { + let vc = factory.makeSettingVC().viewController + navigationController?.pushViewController(vc, animated: true) + } } // MARK: - UICollectionViewDelegate diff --git a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/Views/MainNavigationBar.swift b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/Views/MainNavigationBar.swift index 8ee21099d..e7d4f5f83 100644 --- a/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/Views/MainNavigationBar.swift +++ b/SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/Views/MainNavigationBar.swift @@ -24,7 +24,7 @@ final class MainNavigationBar: UIView { $0.setImage(DSKitAsset.Assets.btnNotice.image, for: .normal) } - private let myPageButton = UIButton(type: .custom).then { + public let myPageButton = UIButton(type: .custom).then { $0.setImage(DSKitAsset.Assets.btnMypage.image, for: .normal) $0.layer.cornerRadius = 22 $0.backgroundColor = DSKitAsset.Colors.black60.color diff --git a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift index 6042ba4d7..62c9cc002 100644 --- a/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift +++ b/SOPT-iOS/Projects/Features/StampFeature/Sources/MissionListScene/VC/MissionListVC.swift @@ -354,13 +354,13 @@ extension MissionListVC: UICollectionViewDelegate { guard let tappedCell = collectionView.cellForItem(at: indexPath) as? MissionListCVC, let model = tappedCell.model, let starLevel = StarViewLevel.init(rawValue: model.level)else { return } - let sceneType = model.toListDetailSceneType() + let detailSceneType = model.toListDetailSceneType() - let detailVC = factory.makeListDetailVC(sceneType: sceneType, + let detailVC = factory.makeListDetailVC(sceneType: detailSceneType, starLevel: starLevel, missionId: model.id, missionTitle: model.title, - isOtherUser: true).viewController + isOtherUser: sceneType.isRankingView).viewController self.navigationController?.pushViewController(detailVC, animated: true) default: return diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift index 21d88f9d4..8844963ac 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/AuthAPI.swift @@ -12,8 +12,6 @@ import Alamofire import Moya public enum AuthAPI { - case getNicknameAvailable(nickname: String) - case changeNickname(nickname: String) case withdrawal case signIn(token: String) } @@ -25,7 +23,7 @@ extension AuthAPI: BaseAPI { // MARK: - Header public var headers: [String: String]? { switch self { - case .changeNickname, .withdrawal: + case .withdrawal: return HeaderType.jsonWithToken.value default: return HeaderType.json.value } @@ -34,10 +32,6 @@ extension AuthAPI: BaseAPI { // MARK: - Path public var path: String { switch self { - case .getNicknameAvailable: - return "" - case .changeNickname: - return "nickname" case .withdrawal: return "withdraw" case .signIn: @@ -48,10 +42,6 @@ extension AuthAPI: BaseAPI { // MARK: - Method public var method: Moya.Method { switch self { - case .getNicknameAvailable: - return .get - case .changeNickname: - return .patch case .withdrawal: return .delete case .signIn: @@ -63,8 +53,6 @@ extension AuthAPI: BaseAPI { private var bodyParameters: Parameters? { var params: Parameters = [:] switch self { - case .changeNickname(let nickname): - params["nickname"] = nickname case .signIn(let token): params["code"] = token default: @@ -82,9 +70,7 @@ extension AuthAPI: BaseAPI { public var task: Task { switch self { - case .getNicknameAvailable(let nickname): - return .requestParameters(parameters: ["nickname": nickname], encoding: URLEncoding.queryString) - case .changeNickname, .signIn: + case .signIn: return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) default: return .requestPlain diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift index 82d3e4c57..d6ae47634 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/RankAPI.swift @@ -14,7 +14,6 @@ import Moya public enum RankAPI { case rank case rankDetail(userName: String) - case editSentence(sentence: String) } extension RankAPI: BaseAPI { @@ -24,7 +23,7 @@ extension RankAPI: BaseAPI { // MARK: - Header public var headers: [String: String]? { switch self { - case .rank, .editSentence, .rankDetail: + case .rank, .rankDetail: return HeaderType.jsonWithToken.value default: return HeaderType.json.value } @@ -37,16 +36,12 @@ extension RankAPI: BaseAPI { return "" case .rankDetail: return "/detail" - case .editSentence: - return "/profileMessage" } } // MARK: - Method public var method: Moya.Method { switch self { - case .editSentence: - return .post default: return .get } } @@ -57,8 +52,6 @@ extension RankAPI: BaseAPI { switch self { case .rankDetail(let userName): params["nickname"] = userName - case .editSentence(let sentence): - params["profileMessage"] = sentence default: break } return params @@ -77,8 +70,6 @@ extension RankAPI: BaseAPI { switch self { case .rankDetail: return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) - case .editSentence: - return .requestParameters(parameters: self.bodyParameters ?? [:], encoding: parameterEncoding) default: return .requestPlain } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift b/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift index 16de6ec43..f3bb9a13a 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/API/UserAPI.swift @@ -13,6 +13,9 @@ import Moya public enum UserAPI { case fetchUser + case editSentence(sentence: String) + case getNicknameAvailable(nickname: String) + case changeNickname(nickname: String) } extension UserAPI: BaseAPI { @@ -24,14 +27,22 @@ extension UserAPI: BaseAPI { switch self { case .fetchUser: return "" + case .editSentence: + return "profile-message" + case .changeNickname: + return "nickname" + case .getNicknameAvailable(let nickname): + return "nickname/\(nickname)" } } // MARK: - Method public var method: Moya.Method { switch self { - case .fetchUser: + case .fetchUser, .getNicknameAvailable: return .get + case .editSentence, .changeNickname: + return .patch } } @@ -39,6 +50,10 @@ extension UserAPI: BaseAPI { private var bodyParameters: Parameters? { var params: Parameters = [:] switch self { + case .changeNickname(let nickname): + params["nickname"] = nickname + case .editSentence(let sentence): + params["profileMessage"] = sentence default: break } return params @@ -53,6 +68,8 @@ extension UserAPI: BaseAPI { public var task: Task { switch self { + case .changeNickname, .editSentence: + return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) default: return .requestPlain } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/EditSentenceEntity.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/EditSentenceEntity.swift index 884fd781b..7e21b09db 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Entity/EditSentenceEntity.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Entity/EditSentenceEntity.swift @@ -10,12 +10,5 @@ import Foundation // MARK: - EditSentenceEntity public struct EditSentenceEntity: Codable { - let createdAt: String? - let updatedAt: String - let id: Int - let nickname, email, password: String - let clientToken: String? public let profileMessage: String - let points: Int? - let osType: String? } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift index 7c0f84f64..458588983 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/AuthService.swift @@ -15,22 +15,11 @@ import Moya public typealias DefaultAuthService = BaseService public protocol AuthService { - func getNicknameAvailable(nickname: String) -> AnyPublisher - func changeNickname(nickname: String) -> AnyPublisher func withdrawal() -> AnyPublisher func signIn(token: String) -> AnyPublisher } extension DefaultAuthService: AuthService { - - public func getNicknameAvailable(nickname: String) -> AnyPublisher { - return requestObjectInCombineNoResult(.getNicknameAvailable(nickname: nickname)) - } - - public func changeNickname(nickname: String) -> AnyPublisher { - return requestObjectInCombineNoResult(.changeNickname(nickname: nickname)) - } - public func withdrawal() -> AnyPublisher { return requestObjectInCombineNoResult(.withdrawal) } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift index 606fcd51f..119e53e59 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/RankService.swift @@ -17,7 +17,6 @@ public typealias DefaultRankService = BaseService public protocol RankService { func fetchRankingList() -> AnyPublisher<[RankingEntity], Error> func fetchRankDetail(userName: String) -> AnyPublisher - func editSentence(sentence: String) -> AnyPublisher } extension DefaultRankService: RankService { @@ -29,8 +28,4 @@ extension DefaultRankService: RankService { public func fetchRankDetail(userName: String) -> AnyPublisher { requestObjectInCombine(RankAPI.rankDetail(userName: userName)) } - - public func editSentence(sentence: String) -> AnyPublisher { - requestObjectInCombine(RankAPI.editSentence(sentence: sentence)) - } } diff --git a/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift b/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift index 1538f7956..ab88d8127 100644 --- a/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift +++ b/SOPT-iOS/Projects/Modules/Network/Sources/Service/UserService.swift @@ -17,10 +17,26 @@ public typealias DefaultUserService = BaseService public protocol UserService { // TODO: - UserEntity 관련 변경사항 적용하기 func fetchUser() -> AnyPublisher + + func editSentence(sentence: String) -> AnyPublisher + func getNicknameAvailable(nickname: String) -> AnyPublisher + func changeNickname(nickname: String) -> AnyPublisher } extension DefaultUserService: UserService { public func fetchUser() -> AnyPublisher { requestObjectInCombine(.fetchUser) } + + public func editSentence(sentence: String) -> AnyPublisher { + requestObjectInCombine(.editSentence(sentence: sentence)) + } + + public func getNicknameAvailable(nickname: String) -> AnyPublisher { + requestObjectInCombineNoResult(.getNicknameAvailable(nickname: nickname)) + } + + public func changeNickname(nickname: String) -> AnyPublisher { + requestObjectInCombineNoResult(.changeNickname(nickname: nickname)) + } } diff --git a/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift b/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift index 910f81c13..29215aa7d 100644 --- a/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift +++ b/SOPT-iOS/Projects/SOPT-iOS/Sources/ModuleFactory/DIContainer.swift @@ -161,7 +161,7 @@ extension DIContainer: Features { // MARK: - SettingFeature func makeSettingVC() -> SettingViewControllable { - let repository = SettingRepository(authService: authService, stampService: stampService, rankService: rankService) + let repository = SettingRepository(authService: authService, stampService: stampService, userService: userService) let useCase = DefaultSettingUseCase(repository: repository) let viewModel = SettingViewModel(useCase: useCase) let settingVC = SettingVC() @@ -171,10 +171,10 @@ extension DIContainer: Features { } func makeNicknameEditVC() -> NicknameEditViewControllable { - let settingRepository = SettingRepository(authService: authService, stampService: stampService, rankService: rankService) + let settingRepository = SettingRepository(authService: authService, stampService: stampService, userService: userService) let settingUseCase = DefaultSettingUseCase(repository: settingRepository) - let signUpRepository = SignUpRepository(service: self.authService) + let signUpRepository = SignUpRepository(service: userService) let signUpUseCase = DefaultSignUpUseCase(repository: signUpRepository) let viewModel = NicknameEditViewModel(nicknameUseCase: signUpUseCase, editPostUseCase: settingUseCase) @@ -185,7 +185,7 @@ extension DIContainer: Features { } func makeSentenceEditVC() -> SentenceEditViewControllable { - let repository = SettingRepository(authService: authService, stampService: stampService, rankService: rankService) + let repository = SettingRepository(authService: authService, stampService: stampService, userService: userService) let useCase = DefaultSentenceEditUseCase(repository: repository) let viewModel = SentenceEditViewModel(useCase: useCase) let sentenceEditVC = SentenceEditVC() @@ -206,7 +206,7 @@ extension DIContainer: Features { func makeWithdrawalVC() -> WithdrawalViewControllable { let withdrawalVC = WithdrawalVC() - let repository = SettingRepository(authService: authService, stampService: stampService, rankService: rankService) + let repository = SettingRepository(authService: authService, stampService: stampService, userService: userService) let useCase = DefaultSettingUseCase(repository: repository) let viewModel = WithdrawalViewModel(useCase: useCase) withdrawalVC.viewModel = viewModel