Skip to content

Commit

Permalink
[Feat] #61 - 새로운 네트워크 세팅 기반 API 통신 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
binisnil committed Nov 24, 2024
1 parent 8683356 commit 2b529c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Wable-iOS/Network/Home/HomeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Foundation
import Combine

import CombineMoya
import Moya

final class HomeAPI: BaseAPI {
Expand All @@ -24,4 +26,14 @@ extension HomeAPI {

}
}

func postReply(contentID: Int, requestBody: WriteReplyRequestV3DTO) -> AnyPublisher<EmptyDTO?, WableNetworkError> {
homeProvider.requestPublisher(.postReply(param: contentID, requestBody: requestBody))
.tryMap { [weak self] response -> EmptyDTO? in
return try self?.parseResponse(statusCode: response.statusCode, data: response.data)
}
.mapError { $0 as? WableNetworkError ??
.unknownError($0.localizedDescription) }
.eraseToAnyPublisher()
}
}
10 changes: 9 additions & 1 deletion Wable-iOS/Network/Home/HomeRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Moya
enum HomeRouter {
case getContent(param: Int)
case patchFCMToken(param: UserProfileRequestDTO)
case postReply(param: Int, requestBody: WriteReplyRequestV3DTO)
}

extension HomeRouter: BaseTargetType {
Expand All @@ -21,6 +22,8 @@ extension HomeRouter: BaseTargetType {
return StringLiterals.Endpoint.Home.getContent
case .patchFCMToken:
return StringLiterals.Endpoint.Home.patchUserProfile
case .postReply(let contentID, _ ):
return StringLiterals.Endpoint.Home.postReply(contentID: contentID)
}
}

Expand All @@ -30,6 +33,8 @@ extension HomeRouter: BaseTargetType {
return .get
case .patchFCMToken:
return .patch
case .postReply:
return .post
}
}

Expand All @@ -53,13 +58,16 @@ extension HomeRouter: BaseTargetType {
formData.append(pushAlarmPart)

return .uploadMultipart(formData)

case .postReply(_, let requestBody):
return .requestJSONEncodable(requestBody)

}
}

var headers: [String : String]? {
switch self {
case .getContent:
case .getContent, .postReply:
return APIConstants.hasTokenHeader
case .patchFCMToken:
return APIConstants.multipartHeader
Expand Down

0 comments on commit 2b529c0

Please sign in to comment.