Skip to content

Commit

Permalink
refactor/#336 미팅리스트 서비스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybei committed Aug 26, 2024
1 parent 9c0be82 commit 097f815
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 28 deletions.
8 changes: 8 additions & 0 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
A3DD9C412C41BAD000E58A13 /* MeetingListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C3A2C41BAD000E58A13 /* MeetingListViewModel.swift */; };
A3DD9C682C45C78300E58A13 /* HomeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C672C45C78300E58A13 /* HomeService.swift */; };
A3DF8EC72C7C93CD00207BCC /* MeetingListServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DF8EC62C7C93CD00207BCC /* MeetingListServiceProtocol.swift */; };
A3DF8EC92C7C987200207BCC /* MeetingListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DF8EC82C7C987200207BCC /* MeetingListService.swift */; };
A3DF8ECB2C7C98A200207BCC /* MeetingListTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DF8ECA2C7C98A200207BCC /* MeetingListTargetType.swift */; };
A3FB02442C788A790026DE0E /* HomeServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB02432C788A790026DE0E /* HomeServiceProtocol.swift */; };
A3FB184D2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */; };
A3FB184F2C3BF4BC001483E5 /* MakeMeetingsResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */; };
Expand Down Expand Up @@ -308,6 +310,8 @@
A3DD9C3A2C41BAD000E58A13 /* MeetingListViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeetingListViewModel.swift; sourceTree = "<group>"; };
A3DD9C672C45C78300E58A13 /* HomeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeService.swift; sourceTree = "<group>"; };
A3DF8EC62C7C93CD00207BCC /* MeetingListServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingListServiceProtocol.swift; sourceTree = "<group>"; };
A3DF8EC82C7C987200207BCC /* MeetingListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingListService.swift; sourceTree = "<group>"; };
A3DF8ECA2C7C98A200207BCC /* MeetingListTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingListTargetType.swift; sourceTree = "<group>"; };
A3FB02432C788A790026DE0E /* HomeServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeServiceProtocol.swift; sourceTree = "<group>"; };
A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsRequestModel.swift; sourceTree = "<group>"; };
A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsResponseModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -751,6 +755,7 @@
isa = PBXGroup;
children = (
DDD62FFA2C5FA4FE00174B57 /* MeetingService.swift */,
A3DF8EC82C7C987200207BCC /* MeetingListService.swift */,
78BD61332C45B4A7005752FD /* AuthService.swift */,
A3DD9C672C45C78300E58A13 /* HomeService.swift */,
DD3F9DC52C484DEB008E1FF7 /* PromiseService.swift */,
Expand Down Expand Up @@ -1199,6 +1204,7 @@
children = (
789196392C49697F00FF8CDF /* Auth */,
DDE7D2C52C47D2BB005A921F /* MeetingTargetType.swift */,
A3DF8ECA2C7C98A200207BCC /* MeetingListTargetType.swift */,
DDE7D2C92C47EE81005A921F /* PromiseTargetType.swift */,
A39F2B1C2C47F3D0008DA5F5 /* HomeTargetType.swift */,
DD3F9DD32C4858A3008E1FF7 /* UtilTargetType.swift */,
Expand Down Expand Up @@ -1881,6 +1887,7 @@
DE32D1D42C3BFB56006848DF /* UpdateProfileNameModel.swift in Sources */,
A39F2B212C499CE5008DA5F5 /* SetReadyStatusInfoServiceType.swift in Sources */,
DE6D4D132C3F14D80005584B /* MeetingMemberCell.swift in Sources */,
A3DF8ECB2C7C98A200207BCC /* MeetingListTargetType.swift in Sources */,
DD3F9DD82C49C25D008E1FF7 /* PromiseServiceProtocol.swift in Sources */,
784825072C77215B00FE07A0 /* MyPageTermsViewController.swift in Sources */,
DDAF1C932C3D6E3D008A37D3 /* PromiseViewController.swift in Sources */,
Expand Down Expand Up @@ -1945,6 +1952,7 @@
DECB84582C43FBEB0022A003 /* AddPromiseViewController.swift in Sources */,
DDE7D2C62C47D2BB005A921F /* MeetingTargetType.swift in Sources */,
A39F2B1D2C47F3D0008DA5F5 /* HomeTargetType.swift in Sources */,
A3DF8EC92C7C987200207BCC /* MeetingListService.swift in Sources */,
DDFA507F2C4693BD000A62E2 /* ProfileSetupViewModel.swift in Sources */,
A3DD9C3D2C41BAD000E58A13 /* MeetingTableViewCell.swift in Sources */,
DE558C5B2C4595A7008DAC4A /* SelectMemberView.swift in Sources */,
Expand Down
89 changes: 89 additions & 0 deletions KkuMulKum/Network/Service/MeetingListService.swift
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
}
}
27 changes: 0 additions & 27 deletions KkuMulKum/Network/Service/MeetingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ final class MeetingService {
}
}

extension MeetingService: MeetingListServiceProtocol {
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? {
return try await request(with: .fetchMeetingList)
}
}

extension MeetingService: MeetingInfoServiceProtocol {
func fetchMeetingInfo(with meetingID: Int) async throws -> ResponseBodyDTO<MeetingInfoModel>? {
return try await request(with: .fetchMeetingInfo(meetingID: meetingID))
Expand Down Expand Up @@ -88,27 +82,6 @@ extension MeetingService: InviteCodeServiceProtocol {
}
}

final class MockMeetingListService: MeetingListServiceProtocol {
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
}
}


final class MockMeetingInfoService: MeetingInfoServiceProtocol {
func fetchMeetingInfo(with meetingID: Int) -> ResponseBodyDTO<MeetingInfoModel>? {
Expand Down
54 changes: 54 additions & 0 deletions KkuMulKum/Network/TargetType/MeetingListTargetType.swift
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)"
]
}
}
2 changes: 1 addition & 1 deletion KkuMulKum/Source/Core/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class MainTabBarController: UITabBarController {

let meetingListViewController = MeetingListViewController(
viewModel: MeetingListViewModel(
service: MeetingService()
service: MeetingListService()
)).then {
$0.tabBarItem.title = "내 모임"
$0.tabBarItem.image = .iconGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import Foundation
import Moya

protocol MeetingListServiceProtocol {
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>?
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>?
}

0 comments on commit 097f815

Please sign in to comment.