From 651b653302e0641401c10e5dd16520b808276096 Mon Sep 17 00:00:00 2001 From: JinUng41 Date: Tue, 27 Aug 2024 03:30:36 +0900 Subject: [PATCH] =?UTF-8?q?refactor/#334=20API=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 모임 약속은 요청 파라미터 없이 - 내가 속한 약속은 요청 파라미터 필요 --- KkuMulKum/Network/Service/MeetingService.swift | 12 +++++++++--- .../Network/TargetType/MeetingTargetType.swift | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/KkuMulKum/Network/Service/MeetingService.swift b/KkuMulKum/Network/Service/MeetingService.swift index 83ccf526..e9baeaf1 100644 --- a/KkuMulKum/Network/Service/MeetingService.swift +++ b/KkuMulKum/Network/Service/MeetingService.swift @@ -42,6 +42,9 @@ final class MeetingService { } } + +// MARK: - MeetingInfoServiceProtocol + extension MeetingService: MeetingInfoServiceProtocol { func fetchMeetingInfo(with meetingID: Int) async throws -> ResponseBodyDTO? { return try await request(with: .fetchMeetingInfo(meetingID: meetingID)) @@ -53,9 +56,12 @@ extension MeetingService: MeetingInfoServiceProtocol { func fetchMeetingPromiseList( with meetingID: Int, - isParticipant: Bool + isParticipant: Bool? ) async throws -> ResponseBodyDTO? { - return try await request(with: .fetchMeetingPromiseList(meetingID: meetingID, isParticipant: isParticipant)) + guard let isParticipant else { + return try await request(with: .fetchMeetingPromiseList(meetingID: meetingID)) + } + return try await request(with: .fetchParticipatedPromiseList(meetingID: meetingID, isParticipant: isParticipant)) } func exitMeeting(with meetingID: Int) -> Single> { @@ -180,7 +186,7 @@ final class MockMeetingInfoService: MeetingInfoServiceProtocol { func fetchMeetingPromiseList( with meetingID: Int, - isParticipant: Bool + isParticipant: Bool? ) async throws -> ResponseBodyDTO? { let mockData = MeetingPromisesModel( promises: [ diff --git a/KkuMulKum/Network/TargetType/MeetingTargetType.swift b/KkuMulKum/Network/TargetType/MeetingTargetType.swift index 9c676f97..9037e0a6 100644 --- a/KkuMulKum/Network/TargetType/MeetingTargetType.swift +++ b/KkuMulKum/Network/TargetType/MeetingTargetType.swift @@ -15,7 +15,8 @@ enum MeetingTargetType { case fetchMeetingList case fetchMeetingInfo(meetingID: Int) case fetchMeetingMember(meetingID: Int) - case fetchMeetingPromiseList(meetingID: Int, isParticipant: Bool) + case fetchMeetingPromiseList(meetingID: Int) + case fetchParticipatedPromiseList(meetingID: Int, isParticipant: Bool) case exitMeeting(meetingID: Int) } @@ -41,7 +42,7 @@ extension MeetingTargetType: TargetType { return "/api/v1/meetings/\(meetingID)" case .fetchMeetingMember(let meetingID): return "/api/v1/meetings/\(meetingID)/members" - case .fetchMeetingPromiseList(let meetingID, _): + case .fetchMeetingPromiseList(let meetingID), .fetchParticipatedPromiseList(let meetingID, _): return "/api/v1/meetings/\(meetingID)/promises" case .exitMeeting(let meetingID): return "/api/v1/meetings/\(meetingID)" @@ -52,7 +53,7 @@ extension MeetingTargetType: TargetType { switch self { case .createMeeting, .joinMeeting: return .post - case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchMeetingPromiseList: + case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchMeetingPromiseList, .fetchParticipatedPromiseList: return .get case .exitMeeting: return .delete @@ -67,7 +68,12 @@ extension MeetingTargetType: TargetType { return .requestJSONEncodable(request) case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .exitMeeting: return .requestPlain - case .fetchMeetingPromiseList(_, let isParticipant): + case .fetchMeetingPromiseList: + let parameters: [String: Any] = [ + "done": "false" + ] + return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) + case .fetchParticipatedPromiseList(_, let isParticipant): let parameters: [String: Any] = [ "done": "false", "isParticipant": isParticipant