-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[refactor] 내 모임 리스트 QA 반영
- Loading branch information
Showing
11 changed files
with
231 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// MeetingListService.swift | ||
// KkuMulKum | ||
// | ||
// Created by 예삐 on 8/26/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
final class MeetingListService { | ||
let provider: MoyaProvider<MeetingListTargetType> | ||
|
||
init(provider: MoyaProvider<MeetingListTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])) { | ||
self.provider = provider | ||
} | ||
|
||
func request<T: ResponseModelType>( | ||
with request: MeetingListTargetType | ||
) async throws -> ResponseBodyDTO<T>? { | ||
return try await withCheckedThrowingContinuation { continuation in | ||
provider.request(request) { result in | ||
switch result { | ||
case .success(let response): | ||
do { | ||
let decodedData = try JSONDecoder().decode( | ||
ResponseBodyDTO<T>.self, | ||
from: response.data | ||
) | ||
continuation.resume(returning: decodedData) | ||
} catch { | ||
continuation.resume(throwing: error) | ||
} | ||
case .failure(let error): | ||
continuation.resume(throwing: error) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension MeetingListService: MeetingListServiceProtocol { | ||
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? { | ||
return try await request(with: .fetchLoginUser) | ||
} | ||
|
||
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? { | ||
return try await request(with: .fetchMeetingList) | ||
} | ||
} | ||
|
||
final class MockMeetingListService: MeetingListServiceProtocol { | ||
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? { | ||
let mockData = ResponseBodyDTO<LoginUserModel>( | ||
success: true, | ||
data: LoginUserModel( | ||
userID: 1, | ||
name: "꾸물리안", | ||
level: 4, | ||
promiseCount: 8, | ||
tardyCount: 2, | ||
tardySum: 72, | ||
profileImageURL: "" | ||
), | ||
error: nil | ||
) | ||
return mockData | ||
} | ||
|
||
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? { | ||
let mockData = ResponseBodyDTO<MeetingListModel>( | ||
success: true, | ||
data: MeetingListModel( | ||
count: 6, | ||
meetings: [ | ||
Meeting(meetingID: 1, name: "꾸물이들", memberCount: 14), | ||
Meeting(meetingID: 2, name: "아요레디", memberCount: 28), | ||
Meeting(meetingID: 3, name: "안드가자", memberCount: 26), | ||
Meeting(meetingID: 4, name: "난이서버", memberCount: 30), | ||
Meeting(meetingID: 5, name: "캔디팟", memberCount: 24), | ||
Meeting(meetingID: 6, name: "열기팟", memberCount: 24) | ||
] | ||
), | ||
error: nil | ||
) | ||
return mockData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// MeetingListTargetType.swift | ||
// KkuMulKum | ||
// | ||
// Created by 예삐 on 8/26/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
enum MeetingListTargetType { | ||
case fetchLoginUser | ||
case fetchMeetingList | ||
} | ||
|
||
extension MeetingListTargetType: TargetType { | ||
var baseURL: URL { | ||
guard let privacyInfo = Bundle.main.privacyInfo, | ||
let urlString = privacyInfo["BASE_URL"] as? String, | ||
let url = URL(string: urlString) else { | ||
fatalError("Invalid BASE_URL in PrivacyInfo.plist") | ||
} | ||
return url | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .fetchLoginUser: | ||
return "/api/v1/users/me" | ||
case .fetchMeetingList: | ||
return "/api/v1/meetings" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
return .get | ||
} | ||
|
||
var task: Task { | ||
return .requestPlain | ||
} | ||
|
||
var headers: [String : String]? { | ||
guard let token = DefaultKeychainService.shared.accessToken else { | ||
return ["Content-Type" : "application/json"] | ||
} | ||
|
||
return [ | ||
"Content-Type" : "application/json", | ||
"Authorization" : "Bearer \(token)" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
KkuMulKum/Source/MeetingList/ServiceProtocol/MeetingListServiceProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// MeetingListServiceProtocol.swift | ||
// KkuMulKum | ||
// | ||
// Created by 예삐 on 8/26/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
protocol MeetingListServiceProtocol { | ||
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? | ||
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? | ||
} |
41 changes: 0 additions & 41 deletions
41
KkuMulKum/Source/MeetingList/ServiceType/MeetingListServiceType.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.