Skip to content

Commit

Permalink
Merge pull request sopt-makers#148 from L-j-h-c/feature/sopt-makers#144
Browse files Browse the repository at this point in the history
…-userIDDelete

[Refactor] sopt-makers#144 - UserID -> AccessToken 이전 작업 & API 변경사항 반영
  • Loading branch information
L-j-h-c authored Apr 11, 2023
2 parents d1cafe6 + bd68746 commit 58a9a85
Show file tree
Hide file tree
Showing 47 changed files with 303 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
@frozen
public enum MissionListSceneType {
case `default`
case ranking(userName: String, sentence: String, userId: Int)
case ranking(userName: String, sentence: String)

var isRankingView: Bool {
public var isRankingView: Bool {
switch self {
case .default: return false
case .ranking: return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public struct UserDefaultKeyList {
public struct Auth {
@UserDefaultWrapper<String>(key: "deviceToken") public static var deviceToken
@UserDefaultWrapper<String>(key: "endpointArnForSNS") public static var endpointArnForSNS
@UserDefaultWrapper<Int>(key: "userId") public static var userId
@UserDefaultWrapper<String>(key: "appAccessToken") public static var appAccessToken
@UserDefaultWrapper<String>(key: "appRefreshToken") public static var appRefreshToken
@UserDefaultWrapper<String>(key: "playgroundToken") public static var playgroundToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -24,21 +23,20 @@ public class ListDetailRepository {
}

extension ListDetailRepository: ListDetailRepositoryInterface {
public func fetchListDetail(missionId: Int, userId: Int?) -> Driver<ListDetailModel> {
let targetUserId = userId ?? (self.userId)
return stampService.fetchStampListDetail(userId: targetUserId, missionId: missionId)
public func fetchListDetail(missionId: Int) -> Driver<ListDetailModel> {
return stampService.fetchStampListDetail(missionId: missionId)
.map { $0.toDomain() }
.asDriver()
}

public func postStamp(missionId: Int, stampData: [Any]) -> AnyPublisher<ListDetailModel, Error> {
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<Int> {
return stampService.putStamp(userId: userId, missionId: missionId, requestModel: stampData)
return stampService.putStamp(missionId: missionId, requestModel: stampData)
.map { $0.toDomain() }
.asDriver()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
})
Expand Down
19 changes: 10 additions & 9 deletions SOPT-iOS/Projects/Data/Sources/Repository/SettingRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@ 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
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
}
}

extension SettingRepository: SettingRepositoryInterface {

public func resetStamp() -> Driver<Bool> {
stampService.resetStamp(userId: userId)
stampService.resetStamp()
.map { $0 == 200 }
.asDriver()
}

public func editSentence(sentence: String) -> AnyPublisher<Bool, Never> {
return rankService.editSentence(userId: userId, sentence: sentence)
return userService.editSentence(sentence: sentence)
.handleEvents(receiveOutput: { entity in
UserDefaultKeyList.User.sentence = entity.toDomain()
})
Expand All @@ -46,17 +45,19 @@ extension SettingRepository: SettingRepositoryInterface {
}

public func editNickname(nickname: String) -> AnyPublisher<Bool, Never> {
return authService.changeNickname(userId: userId, nickname: nickname)
return userService.changeNickname(nickname: nickname)
.map { _ in true }
.replaceError(with: false)
.eraseToAnyPublisher()
}

public func withdrawal() -> AnyPublisher<Bool, Never> {
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
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
33 changes: 33 additions & 0 deletions SOPT-iOS/Projects/Data/Sources/Transform/RankDetailTransform.swift
Original file line number Diff line number Diff line change
@@ -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
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions SOPT-iOS/Projects/Domain/Sources/Model/RankingModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 0 additions & 19 deletions SOPT-iOS/Projects/Domain/Sources/Model/SignInModel.swift

This file was deleted.

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

public protocol ListDetailRepositoryInterface {
func fetchListDetail(missionId: Int, userId: Int?) -> Driver<ListDetailModel>
func fetchListDetail(missionId: Int) -> Driver<ListDetailModel>
func postStamp(missionId: Int, stampData: [Any]) -> AnyPublisher<ListDetailModel, Error>
func putStamp(missionId: Int, stampData: [Any]) -> Driver<Int>
func deleteStamp(stampId: Int) -> Driver<Bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import Combine

// TODO: - User 유형 설정 방식 생각하기

public protocol SignInRepositoryInterface {
func requestSignIn(token: String) -> AnyPublisher<Bool, Never>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class SignInVC: UIViewController, SignInViewControllable {
public override func viewDidLoad() {
super.viewDidLoad()
self.bindViewModels()
self.bindViews()
self.setUI()
self.setLayout()
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Loading

0 comments on commit 58a9a85

Please sign in to comment.