Skip to content

Commit 16ee241

Browse files
authored
Merge pull request #204 from YAPP-Github/feat/#202
feat: 프로필 수정 API 추가
2 parents 1635b6f + 5aa1db8 commit 16ee241

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

Projects/Domain/Onboarding/Interface/Sources/OnboardingClient.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public struct OnboardingClient: Sendable {
2626

2727
public var registerProfile: @Sendable (_ nickname: String) async throws -> Void
2828

29+
public var updateProfile: @Sendable (_ nickname: String) async throws -> Void
30+
2931
public var setAnniversary: @Sendable (_ date: Date) async throws -> Void
3032

3133
public var fetchStatus: @Sendable () async throws -> OnboardingStatus
@@ -34,12 +36,14 @@ public struct OnboardingClient: Sendable {
3436
fetchInviteCode: @escaping @Sendable () async throws -> String,
3537
connectCouple: @escaping @Sendable (_ inviteCode: String) async throws -> Void,
3638
registerProfile: @escaping @Sendable (_ nickname: String) async throws -> Void,
39+
updateProfile: @escaping @Sendable (_ nickname: String) async throws -> Void,
3740
setAnniversary: @escaping @Sendable (_ date: Date) async throws -> Void,
3841
fetchStatus: @escaping @Sendable () async throws -> OnboardingStatus
3942
) {
4043
self.fetchInviteCode = fetchInviteCode
4144
self.connectCouple = connectCouple
4245
self.registerProfile = registerProfile
46+
self.updateProfile = updateProfile
4347
self.setAnniversary = setAnniversary
4448
self.fetchStatus = fetchStatus
4549
}
@@ -53,6 +57,7 @@ extension OnboardingClient: TestDependencyKey {
5357
fetchInviteCode: { "ABC123" },
5458
connectCouple: { _ in },
5559
registerProfile: { _ in },
60+
updateProfile: { _ in },
5661
setAnniversary: { _ in },
5762
fetchStatus: { .coupleConnection }
5863
)
@@ -71,6 +76,10 @@ extension OnboardingClient: TestDependencyKey {
7176
assertionFailure("OnboardingClient.registerProfile이 구현되지 않았습니다.")
7277
throw OnboardingError.unknown
7378
},
79+
updateProfile: { _ in
80+
assertionFailure("OnboardingClient.updateProfile이 구현되지 않았습니다.")
81+
throw OnboardingError.unknown
82+
},
7483
setAnniversary: { _ in
7584
assertionFailure("OnboardingClient.setAnniversary가 구현되지 않았습니다.")
7685
throw OnboardingError.unknown

Projects/Domain/Onboarding/Sources/OnboardingClient+Live.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ extension OnboardingClient: @retroactive DependencyKey {
5050
throw OnboardingError.unknown
5151
}
5252
},
53+
updateProfile: { nickname in
54+
@Dependency(\.networkClient) var networkClient
55+
56+
do {
57+
let _: EmptyResponse = try await networkClient.request(
58+
endpoint: OnboardingEndpoint.updateProfile(nickname: nickname)
59+
)
60+
} catch let error as NetworkError {
61+
throw OnboardingErrorMapper.map(error, context: .profile)
62+
} catch {
63+
throw OnboardingError.unknown
64+
}
65+
},
5366
setAnniversary: { date in
5467
@Dependency(\.networkClient) var networkClient
5568

Projects/Domain/Onboarding/Sources/OnboardingEndpoint.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ enum OnboardingEndpoint: Endpoint {
1717
/// 프로필 등록
1818
case registerProfile(nickname: String)
1919

20+
/// 프로필 수정
21+
case updateProfile(nickname: String)
22+
2023
/// 기념일 설정
2124
case setAnniversary(date: String)
2225

@@ -39,7 +42,7 @@ enum OnboardingEndpoint: Endpoint {
3942
case .connectCouple:
4043
return "/api/v1/onboarding/couple-connection"
4144

42-
case .registerProfile:
45+
case .registerProfile, .updateProfile:
4346
return "/api/v1/onboarding/profile"
4447

4548
case .setAnniversary:
@@ -57,6 +60,9 @@ enum OnboardingEndpoint: Endpoint {
5760

5861
case .connectCouple, .registerProfile, .setAnniversary:
5962
return .post
63+
64+
case .updateProfile:
65+
return .patch
6066
}
6167
}
6268

@@ -76,7 +82,7 @@ enum OnboardingEndpoint: Endpoint {
7682
case .connectCouple(let inviteCode):
7783
return CoupleConnectionRequest(inviteCode: inviteCode)
7884

79-
case .registerProfile(let nickname):
85+
case .registerProfile(let nickname), .updateProfile(let nickname):
8086
return ProfileRequest(nickname: nickname)
8187

8288
case .setAnniversary(let date):

Projects/Feature/Settings/Sources/Settings/SettingsReducer+Impl.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,16 @@ private func handleNicknameEditingEnded(
393393
return .none
394394
}
395395

396+
let nickname = state.nickname
396397
state.isLoading = true
397398
return .run { send in
398-
try? await Task.sleep(for: .milliseconds(500))
399-
await send(.updateNicknameResponse(.success(())))
399+
@Dependency(\.onboardingClient) var onboardingClient
400+
401+
do {
402+
try await onboardingClient.updateProfile(nickname)
403+
await send(.updateNicknameResponse(.success(())))
404+
} catch {
405+
await send(.updateNicknameResponse(.failure(error)))
406+
}
400407
}
401408
}

0 commit comments

Comments
 (0)