-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
308 additions
and
257 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
212 changes: 0 additions & 212 deletions
212
Spon-us.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
// | ||
// SavedListModel.swift | ||
// Spon-us | ||
// | ||
// Created by yubin on 2/19/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SavedListModel: Codable { | ||
let statusCode: String | ||
let message: String | ||
let content: [SavedListResponse] | ||
} | ||
|
||
struct SavedListResponse: Codable, Hashable { | ||
static func == (lhs: SavedListResponse, rhs: SavedListResponse) -> Bool { | ||
return lhs.id == rhs.id | ||
} | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(id) | ||
} | ||
let id: Int | ||
let writerId: Int | ||
let writerName: String | ||
let title: String | ||
let type: String | ||
let category: String | ||
let mainImage: MainImage | ||
let createdAt: String | ||
let viewCount: Int | ||
let saveCount: Int | ||
} |
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,46 @@ | ||
// | ||
// SavedListViewModel.swift | ||
// Spon-us | ||
// | ||
// Created by yubin on 2/19/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import Moya | ||
|
||
class SavedListViewModel: ObservableObject { | ||
@Published var savedResponse: [SavedListResponse] = [] | ||
private let provider = MoyaProvider<SponusAPI>(session: Session(interceptor: AuthInterceptor.shared)) | ||
|
||
func fetchSaved(sort: String) { | ||
provider.request(.getBookmarked(sort: sort)) { result in | ||
switch result { | ||
case let .success(response): | ||
do { | ||
print(try! response.mapJSON()) | ||
let savedListResponse = try response.map(SavedListModel.self) | ||
self.savedResponse = savedListResponse.content | ||
print("북마크 리스트: \(self.savedResponse.count)") | ||
|
||
} catch { | ||
print("Error parsing response: \(error)") | ||
} | ||
|
||
case let .failure(error): | ||
if let responsee = error.response { | ||
// 실패한 요청의 응답 본문이 있는 경우 | ||
if let responseBody = String(data: responsee.data, encoding: .utf8) { | ||
print("Response body: \(responseBody)") | ||
} else { | ||
print("Failed to decode response body.") | ||
} | ||
} else { | ||
print("No response body.") | ||
} | ||
print("Bookmark Network request failed: \(error)") | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.