Skip to content

Commit

Permalink
feat #144: GetDailysUseCase 셍성 & 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
minsangKang committed Jul 7, 2024
1 parent 0a65a67 commit d4e899f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 23 deletions.
12 changes: 12 additions & 0 deletions Project_Timer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
870F90E52AEFFA9300854DDB /* SignupPasswordModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870F90E42AEFFA9300854DDB /* SignupPasswordModel.swift */; };
870F90E72AEFFF1A00854DDB /* SignupPasswordRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870F90E62AEFFF1A00854DDB /* SignupPasswordRoute.swift */; };
871616912C39956E00C4EF25 /* CheckUsernameRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871616902C39956E00C4EF25 /* CheckUsernameRequest.swift */; };
871616962C3A149000C4EF25 /* GetDailysUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871616952C3A149000C4EF25 /* GetDailysUseCase.swift */; };
87163DC82ACAF2E8008D4072 /* NetworkError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87163DC72ACAF2E8008D4072 /* NetworkError.swift */; };
87163DCA2ACAF89B008D4072 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87163DC92ACAF89B008D4072 /* NetworkResult.swift */; };
87168D99299A819F003ED502 /* UserDefaults+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875C98C82871BFCF008F7ADD /* UserDefaults+Extension.swift */; };
Expand Down Expand Up @@ -527,6 +528,7 @@
870F90E42AEFFA9300854DDB /* SignupPasswordModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignupPasswordModel.swift; sourceTree = "<group>"; };
870F90E62AEFFF1A00854DDB /* SignupPasswordRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignupPasswordRoute.swift; sourceTree = "<group>"; };
871616902C39956E00C4EF25 /* CheckUsernameRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckUsernameRequest.swift; sourceTree = "<group>"; };
871616952C3A149000C4EF25 /* GetDailysUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetDailysUseCase.swift; sourceTree = "<group>"; };
87163DC72ACAF2E8008D4072 /* NetworkError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = "<group>"; };
87163DC92ACAF89B008D4072 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
87199F432882BC430017D01A /* StandardDailyGraphView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardDailyGraphView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -993,6 +995,14 @@
path = Password;
sourceTree = "<group>";
};
871616922C3A146400C4EF25 /* Dailys */ = {
isa = PBXGroup;
children = (
871616952C3A149000C4EF25 /* GetDailysUseCase.swift */,
);
path = Dailys;
sourceTree = "<group>";
};
87199F422882BC0C0017D01A /* Graph */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1978,6 +1988,7 @@
children = (
872210532C300922003B97AD /* Firebase */,
877BDCDF2C390BAE00A50231 /* Auth */,
871616922C3A146400C4EF25 /* Dailys */,
);
path = UseCase;
sourceTree = "<group>";
Expand Down Expand Up @@ -2386,6 +2397,7 @@
043706272869D58C00A5D3AA /* TimerTimeLabelView.swift in Sources */,
874F9C312ABFF81300675A86 /* EmailSigninButton.swift in Sources */,
870800692B2C68EF00830B39 /* AuthUseCaseInterface.swift in Sources */,
871616962C3A149000C4EF25 /* GetDailysUseCase.swift in Sources */,
878DA8252B0C78D8001E924E /* SignupNicknameRoute.swift in Sources */,
870F90E52AEFFA9300854DDB /* SignupPasswordModel.swift in Sources */,
87D4DCD42BA5A53F00BB5AAB /* ResetPasswordEmailModel.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion Project_Timer/Data/API/DailysAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ extension DailysAPI: TargetType {

var path: String {
switch self {
case .postDailys, .getDailys:
case .postDailys:
return "/dailys/upload"
case .getDailys:
return "/dailys"
case .postRecordTime, .getRecordTime:
return "/recordTime"
case .getSyncLog:
Expand Down
8 changes: 2 additions & 6 deletions Project_Timer/Data/Repository/DailysRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ final class DailysRepository {

func getDailys() -> AnyPublisher<[Daily], NetworkError> {
return self.api.request(.getDailys)
.tryMap { response in
guard let dtos = try? JSONDecoder.dateFormatted.decode([DailyResponse].self, from: response.data) else {
throw NetworkError.DECODEERROR
}
return dtos.map { $0.toDomain() }
}
.map([DailyResponse].self)
.map { $0.map { $0.toDomain() } }
.catchDecodeError()
}
}
4 changes: 3 additions & 1 deletion Project_Timer/Data/TTProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ extension Publisher where Output == Response, Failure == NetworkError {
func map<D: Decodable>(_ type: D.Type) -> AnyPublisher<D, NetworkError> {
return self.tryMap { response in
do {
let decodedData = try JSONDecoder().decode(D.self, from: response.data)
let jsonDecoder = JSONDecoder()
jsonDecoder.dateDecodingStrategy = .iso8601
let decodedData = try jsonDecoder.decode(D.self, from: response.data)
return decodedData
} catch {
throw NetworkError.DECODEERROR
Expand Down
22 changes: 22 additions & 0 deletions Project_Timer/Domain/UseCase/Dailys/GetDailysUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// GetDailysUseCase.swift
// Project_Timer
//
// Created by Kang Minsang on 2024/07/07.
// Copyright © 2024 FDEE. All rights reserved.
//

import Foundation
import Combine

final class GetDailysUseCase {
let repository: DailysRepository

init(repository: DailysRepository) {
self.repository = repository
}

func execute() -> AnyPublisher<[Daily], NetworkError> {
return self.repository.getDailys()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import Combine
import Moya

final class SyncDailysVC: UIViewController {
static let identifier = "SyncDailysVC"
Expand Down Expand Up @@ -125,10 +126,16 @@ extension SyncDailysVC {
let syncLogUseCase = SyncLogUseCase(repository: SyncLogRepository_lagacy())
let targetDailys = self.syncDeviceStatusView.configureDailys()

// TODO: DI 수정
let api = TTProvider<DailysAPI>(session: Session(interceptor: NetworkInterceptor.shared))
let repository = DailysRepository(api: api)
let getDailysUseCase = GetDailysUseCase(repository: repository)

self.viewModel = SyncDailysVM(
dailysUseCase: dailysUseCase,
recordTimesUseCase: recordTimesUseCase,
syncLogUseCase: syncLogUseCase,
getDailysUseCase: getDailysUseCase,
targetDailys: targetDailys)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class SyncDailysVM {
private let dailysUseCase: DailysUseCaseInterface
private let recordTimesUseCase: RecordTimesUseCaseInterface
private let syncLogUseCase: SyncLogUseCaseInterface
private let getDailysUseCase: GetDailysUseCase
private var targetDailys: [Daily]
@Published private(set) var syncLog: SyncLog?
@Published private(set) var alert: (title: String, text: String)?
Expand All @@ -25,10 +26,12 @@ final class SyncDailysVM {
init(dailysUseCase: DailysUseCaseInterface,
recordTimesUseCase: RecordTimesUseCaseInterface,
syncLogUseCase: SyncLogUseCaseInterface,
getDailysUseCase: GetDailysUseCase,
targetDailys: [Daily]) {
self.dailysUseCase = dailysUseCase
self.recordTimesUseCase = recordTimesUseCase
self.syncLogUseCase = syncLogUseCase
self.getDailysUseCase = getDailysUseCase
self.targetDailys = targetDailys

self.checkServerURL()
Expand Down Expand Up @@ -126,25 +129,27 @@ extension SyncDailysVM {
private func getDailys() {
self.loadingText = .getDailys
self.loading = true
self.dailysUseCase.getDailys { [weak self] result in
switch result {
case .success(let dailys):
self.getDailysUseCase.execute()
.sink { [weak self] completion in
if case .failure(let networkError) = completion {
print("ERROR", #function, networkError)
self?.loading = false
switch networkError {
case .CLIENTERROR(let message):
if let message = message {
print("[get Dailys ERROR] \(message)")
}
self?.alert = (title: Localized.string(.Server_Error_DownloadError), text: Localized.string(.Server_Error_DecodeError))
default:
self?.alert = networkError.alertMessage
}
}
} receiveValue: { [weak self] dailys in
self?.saveDailys(dailys)
self?.loading = false
self?.checkRecordTimes()
case .failure(let error):
self?.loading = false
switch error {
case .CLIENTERROR(let message):
if let message = message {
print("[get Dailys ERROR] \(message)")
}
self?.alert = (title: Localized.string(.Server_Error_DownloadError), text: Localized.string(.Server_Error_DecodeError))
default:
self?.alert = error.alertMessage
}
}
}
.store(in: &self.cancellables)
}

/// getRecordTime -> getSyncLog 진행
Expand Down

0 comments on commit d4e899f

Please sign in to comment.