Skip to content

Commit

Permalink
feat/#213 진웅오빠꺼 pull 받음!
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybei committed Jul 18, 2024
2 parents 1b3a2ee + b66b122 commit ace4460
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 103 deletions.
42 changes: 22 additions & 20 deletions KkuMulKum/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,26 @@ extension AppDelegate: MessagingDelegate, UNUserNotificationCenterDelegate {
}

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")

if let token = fcmToken {
UserDefaults.standard.set(token, forKey: "FCMToken")
}
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken

// APNS 토큰이 설정된 후 FCM 토큰 요청
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM Token: \(token)")
UserDefaults.standard.set(token, forKey: "FCMToken")
}
}
}
print("Firebase registration token: \(String(describing: fcmToken))")

if let token = fcmToken {
let keychainAccessible: KeychainAccessible = DefaultKeychainAccessible()
_ = keychainAccessible.saveToken("FCMToken", token)
NotificationCenter.default.post(name: Notification.Name("FCMTokenReceived"), object: nil)
}
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken

Messaging.messaging().token { [weak self] token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM Token: \(token)")
let keychainAccessible: KeychainAccessible = DefaultKeychainAccessible()
_ = keychainAccessible.saveToken("FCMToken", token)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MeetingMembersModel: ResponseModelType {

struct Member: Codable {
let memberID: Int
let name: String
let name: String?
let profileImageURL: String?

enum CodingKeys: String, CodingKey {
Expand Down
11 changes: 10 additions & 1 deletion KkuMulKum/Network/DTO/Model/Promises/MeetingPromisesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ struct MeetingPromisesModel: ResponseModelType {
}

struct MeetingPromise: Codable {
let id: Int
let promiseID: Int
let name: String
let dDay: Int
let date: String
let time: String
let placeName: String

enum CodingKeys: String, CodingKey {
case promiseID = "promiseId"
case name
case dDay
case date
case time
case placeName
}
}
23 changes: 23 additions & 0 deletions KkuMulKum/Network/Service/HomeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,27 @@ final class HomeService {
init(provider: MoyaProvider<HomeTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])) {
self.provider = provider
}

func request<T: Decodable>(
with request: HomeTargetType
) 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)
}
}
}
}
}
23 changes: 23 additions & 0 deletions KkuMulKum/Network/Service/MeetingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,27 @@ final class MeetingService {
init(provider: MoyaProvider<MeetingTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])) {
self.provider = provider
}

func request<T: Decodable>(
with request: MeetingTargetType
) 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)
}
}
}
}
}
27 changes: 25 additions & 2 deletions KkuMulKum/Network/Service/PromiseService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@ import Moya
final class PromiseService {
let provider: MoyaProvider<PromiseTargetType>

init(provider: MoyaProvider<PromiseTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])
) {
init(provider: MoyaProvider<PromiseTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])) {
self.provider = provider
}

func request<T: Decodable>(
with request: PromiseTargetType
) 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)
}
}
}
}

}
26 changes: 24 additions & 2 deletions KkuMulKum/Network/Service/UtilService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,30 @@ import Moya
final class UtilService {
let provider: MoyaProvider<UtilTargetType>

init(provider: MoyaProvider<UtilTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])
) {
init(provider: MoyaProvider<UtilTargetType> = MoyaProvider(plugins: [MoyaLoggingPlugin()])) {
self.provider = provider
}

func request<T: Decodable>(
with request: UtilTargetType
) 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)
}
}
}
}
}
7 changes: 5 additions & 2 deletions KkuMulKum/Network/TargetType/MeetingTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum MeetingTargetType {
case fetchMeetingList
case fetchMeetingInfo(meetingID: Int)
case fetchMeetingMember(meetingID: Int)
case fetchMeetingPromiseList(meetingID: Int)
}

extension MeetingTargetType: TargetType {
Expand All @@ -39,14 +40,16 @@ extension MeetingTargetType: TargetType {
return "/api/v1/meetings/\(meetingID)"
case .fetchMeetingMember(meetingID: let meetingID):
return "/api/v1/meetings/\(meetingID)/members"
case .fetchMeetingPromiseList(let meetingID):
return "/api/v1/meetings/\(meetingID)/promises"
}
}

var method: Moya.Method {
switch self {
case .createMeeting, .joinMeeting:
return .post
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember:
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchMeetingPromiseList:
return .get
}
}
Expand All @@ -57,7 +60,7 @@ extension MeetingTargetType: TargetType {
return .requestJSONEncodable(request)
case .joinMeeting(request: let request):
return .requestJSONEncodable(request)
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember:
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchMeetingPromiseList:
return .requestPlain
}
}
Expand Down
14 changes: 6 additions & 8 deletions KkuMulKum/Network/TargetType/PromiseTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum PromiseTargetType {
case updatePreparationStatus(promiseID: Int)
case updateDepartureStatus(promiseID: Int)
case updateArrivalStatus(promiseID: Int)
case fetchmeetingPromiseList(meetingID: Int, request: PromiseInfoModel)
case fetchMeetingPromiseList(meetingID: Int)
case addPromise(meetingID: Int, request: AddPromiseRequestModel)
case fetchPromiseInfo(promiseID: Int)
case fetchMyReadyStatus(promiseID: Int)
Expand Down Expand Up @@ -47,10 +47,10 @@ extension PromiseTargetType: TargetType {
return "/api/v1/promises/\(promiseID)/departure"
case .updateArrivalStatus(let promiseID):
return "/api/v1/promises/\(promiseID)/arrival"
case .fetchmeetingPromiseList(let meetingID, _):
return "/api/v1/promises/\(meetingID)/promises"
case .fetchMeetingPromiseList(let meetingID):
return "/api/v1/meetings/\(meetingID)/promises"
case .addPromise(let meetingID, _):
return "/api/v1/promises/\(meetingID)/promises"
return "/api/v1/meetings/\(meetingID)/promises"
case .fetchPromiseInfo(let promiseID):
return "/api/v1/promises/\(promiseID)"
case .fetchMyReadyStatus(let promiseID):
Expand All @@ -68,7 +68,7 @@ extension PromiseTargetType: TargetType {

var method: Moya.Method {
switch self {
case .fetchTodayNextPromise, .fetchUpcomingPromiseList, .fetchmeetingPromiseList,
case .fetchTodayNextPromise, .fetchUpcomingPromiseList, .fetchMeetingPromiseList,
.fetchPromiseInfo, .fetchMyReadyStatus, .fetchPromiseParticipantList,
.fetchTardyInfo:
return .get
Expand All @@ -85,10 +85,8 @@ extension PromiseTargetType: TargetType {
case .fetchTodayNextPromise, .fetchUpcomingPromiseList, .updatePreparationStatus,
.updateDepartureStatus, .updateArrivalStatus, .fetchPromiseInfo,
.fetchMyReadyStatus, .fetchPromiseParticipantList, .updateMyPromiseReadyStatus,
.fetchTardyInfo, .updatePromiseCompletion:
.fetchTardyInfo, .updatePromiseCompletion, .fetchMeetingPromiseList:
return .requestPlain
case .fetchmeetingPromiseList(_, let request):
return .requestJSONEncodable(request)
case .addPromise(_, let request):
return .requestJSONEncodable(request)
}
Expand Down
2 changes: 1 addition & 1 deletion KkuMulKum/Source/AddPromise/Cell/SelectMemberCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension SelectMemberCell {
func configure(with member: Member) {
self.member = member

nameLabel.setText(member.name, style: .body06, color: .gray6)
nameLabel.setText(member.name ?? " ", style: .body06, color: .gray6)
profileImageView.image = .imgProfile.withRenderingMode(.alwaysOriginal)
guard let imageURL = URL(string: member.profileImageURL ?? "") else { return }
profileImageView.kf.setImage(with: imageURL)
Expand Down
12 changes: 6 additions & 6 deletions KkuMulKum/Source/Core/Auth/AuthInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AuthInterceptor: RequestInterceptor {
}

guard let refreshToken = authService.getRefreshToken() else {
authService.clearTokens()
_ = authService.clearTokens()
completion(.doNotRetry)
return
}
Expand All @@ -54,23 +54,23 @@ class AuthInterceptor: RequestInterceptor {
if reissueResponse.success, let data = reissueResponse.data {
let newAccessToken = data.accessToken
let newRefreshToken = data.refreshToken
self?.authService.saveAccessToken(newAccessToken)
self?.authService.saveRefreshToken(newRefreshToken)
_ = self?.authService.saveAccessToken(newAccessToken)
_ = self?.authService.saveRefreshToken(newRefreshToken)
print("Token refreshed successfully in interceptor")
completion(.retry)
} else {
print("Token refresh failed in interceptor: \(reissueResponse.error?.message ?? "Unknown error")")
self?.authService.clearTokens()
_ = self?.authService.clearTokens()
completion(.doNotRetry)
}
} catch {
print("Token refresh failed in interceptor: \(error)")
self?.authService.clearTokens()
_ = self?.authService.clearTokens()
completion(.doNotRetry)
}
case .failure(let error):
print("Network error during token refresh in interceptor: \(error)")
self?.authService.clearTokens()
_ = self?.authService.clearTokens()
completion(.doNotRetry)
}
}
Expand Down
2 changes: 1 addition & 1 deletion KkuMulKum/Source/MeetingInfo/Cell/MeetingMemberCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private extension MeetingMemberCell {
let name = member.name
let imageURL = member.profileImageURL

nameLabel.setText(name, style: .caption02, color: .gray6)
nameLabel.setText(name ?? " ", style: .caption02, color: .gray6)
profileImageButton.setImage(
.imgProfile.withRenderingMode(.alwaysOriginal),
for: .normal
Expand Down
Loading

0 comments on commit ace4460

Please sign in to comment.