Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 확인했어요 API 구현 (#454) #455

Merged
merged 5 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions NADA-iOS-forRelease/Sources/NetworkService/Update/UpdateAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public final class UpdateAPI {
}
}

func checkUpdateNote(isChecked: Bool, completion: @escaping (NetworkResult<Any>) -> Void) {
updateProvider.request(.checkUpdateNote(isChecked: isChecked)) { result in
switch result {
case .success(let response):
let statusCode = response.statusCode
let data = response.data

let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self)
completion(networkResult)
case .failure(let err):
print(err)
}
}
}

// MARK: - judgeStatus methods

private func judgeStatus<T: Codable>(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult<Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Moya
enum UpdateService {
case updateUserInfoFetch
case updateNoteFetch
case checkUpdateNote(isChecked: Bool)
}

extension UpdateService: TargetType {
Expand All @@ -29,26 +30,33 @@ extension UpdateService: TargetType {
return "/app/update"
case .updateNoteFetch:
return "/app/update/note"
case .checkUpdateNote:
return "/app/update/check"
}
}

var method: Moya.Method {
switch self {
case .updateUserInfoFetch, .updateNoteFetch:
return .get
case .checkUpdateNote:
return .post
}
}

var task: Moya.Task {
switch self {
case .updateUserInfoFetch, .updateNoteFetch:
return .requestPlain
case .checkUpdateNote(let isChecked):
return .requestParameters(parameters: ["checkUpdateNote": isChecked],
encoding: URLEncoding.queryString)
}
}

var headers: [String: String]? {
switch self {
case .updateUserInfoFetch, .updateNoteFetch:
case .updateUserInfoFetch, .updateNoteFetch, .checkUpdateNote:
return Const.Header.bearerHeader()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ extension HomeViewController {
}

private func checkUpdateVersion() {
updateUserInfoFetchWithAPI { [weak self] forceUpdateAgreement in
if !forceUpdateAgreement {
updateUserInfoFetchWithAPI { [weak self] checkUpdateNote in
if !checkUpdateNote {
self?.updateNoteFetchWithAPI { [weak self] updateNote in
if self?.checkUpdateAvailable(updateNote.latestVersion) ?? false {
self?.presentToUpdateVC(with: updateNote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension UpdateViewController {
exit(0)
}
} else {
// TODO: - 확인했어요 API 통신
checkUpdateNoteWithAPI(forceUpdateAgreement)
self.dismiss(animated: true)
}
}
Expand All @@ -110,7 +110,7 @@ extension UpdateViewController {
}

if !updateNote.isForce {
// TODO: - 확인했어요 API 통신
checkUpdateNoteWithAPI(forceUpdateAgreement)
}
}

Expand All @@ -121,6 +121,27 @@ extension UpdateViewController {
}
}

// MARK: - Network

extension UpdateViewController {
private func checkUpdateNoteWithAPI(_ forceUpdateAgreement: Bool) {
UpdateAPI.shared.checkUpdateNote(isChecked: forceUpdateAgreement) { response in
switch response {
case .success:
print("checkUpdateNoteWithAPI - success")
case .requestErr(let message):
print("checkUpdateNoteWithAPI - requestErr: \(message)")
case .pathErr:
print("checkUpdateNoteWithAPI - pathErr")
case .serverErr:
print("checkUpdateNoteWithAPI - serverErr")
case .networkFail:
print("checkUpdateNoteWithAPI - networkFail")
}
}
}
}

// MARK: - Layout

extension UpdateViewController {
Expand Down