Skip to content

Commit 76c7805

Browse files
committed
✨ :: [#30] My Info ViewModel 추가
1 parent 5ef614e commit 76c7805

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Projects/App/Sources/Feature/PostCreateFeature/Sources/PostViewModel.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public final class PostViewModel: ObservableObject {
88
private let emojiProvider = MoyaProvider<EmojiAPI>(
99
plugins: [NetworkLoggerPlugin(configuration: .init(logOptions: .verbose))]
1010
)
11+
private let userProvider = MoyaProvider<UserAPI>()
1112
private var title: String = ""
1213
private var accessToken: String = "Bearer eyJhbGciOiJIUzM4NCJ9.eyJzdWIiOiIyIiwiaWF0IjoxNzM0NjYyNTg4LCJleHAiOjE3NDQ2NjI1ODh9.FG4FVQ4oikC4HNy5h7gq0QyCIjVZtceIOKwAMnkULAt4y0lX5gGIF1s2Mdj9qr1H"
1314
private var userList: [Int] = []
@@ -24,6 +25,7 @@ public final class PostViewModel: ObservableObject {
2425
@Published var myPostList: [MyPostListResponse] = []
2526
@Published var myReactionPostList: [MyReactionPostListResponse] = []
2627
@Published var popularityPostList: [PopularityResponse] = []
28+
@Published public var myInfo: MyInfoResponse?
2729
private var imageUploadResponse: ImageUploadResponse?
2830

2931

@@ -202,18 +204,13 @@ public final class PostViewModel: ObservableObject {
202204
}
203205

204206
public func myInfo(completion: @escaping (Bool) -> Void) {
205-
authProvider.request(.popularityUserList(authorization: accessToken)) { result in
207+
userProvider.request(.userInfoInput(authorization: accessToken)) { result in
206208
switch result {
207209
case let .success(response):
208210
do {
209211
print("성공: 유저 리스트 불러오기")
210212

211-
self.popularityUserList = try JSONDecoder().decode([PopularityRankingUserListResponse].self, from: response.data)
212-
213-
print("불러온 유저 리스트:")
214-
for (index, user) in self.popularityUserList.enumerated() {
215-
print("[\(index)] \(user)")
216-
}
213+
self.myInfo = try JSONDecoder().decode(MyInfoResponse.self, from: response.data)
217214

218215
completion(true)
219216
} catch {

Projects/Domain/Sources/Response/Post/MyInfoResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
public struct MyInfoResponsed: Identifiable, Codable {
3+
public struct MyInfoResponse: Identifiable, Codable {
44
public let id: Int
55
public let name: String
66
public let grade: Int

0 commit comments

Comments
 (0)