Skip to content

Commit

Permalink
[#140] 북마크 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
ubeeni committed Feb 18, 2024
1 parent 1ab7a4c commit 986d63a
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 257 deletions.
26 changes: 26 additions & 0 deletions Spon-us.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@
100D38B82B4EF54100498977 /* CategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100D38B72B4EF54100498977 /* CategoryView.swift */; };
100D38BA2B4EF54C00498977 /* MyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100D38B92B4EF54C00498977 /* MyView.swift */; };
1031EC7C2B68B9F20016655B /* AnnouncementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1031EC7B2B68B9F20016655B /* AnnouncementView.swift */; };
105A46CD2B826DC70039FD70 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 105A46CC2B826DC70039FD70 /* GoogleService-Info.plist */; };
106720022B5835FA00493354 /* SendOfferView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 106720012B5835FA00493354 /* SendOfferView.swift */; };
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D6E682B7A8273005B6261 /* OrganizationModel.swift */; };
107D6E6B2B7A83AB005B6261 /* MyOrganizationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D6E6A2B7A83AB005B6261 /* MyOrganizationViewModel.swift */; };
109ED8682B80C61A00304695 /* SponusAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 109ED8672B80C61A00304695 /* SponusAPI.swift */; };
109F9E282B6E692B006B7D63 /* MyTermsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 109F9E272B6E692B006B7D63 /* MyTermsView.swift */; };
109F9E2A2B6E7536006B7D63 /* CouponView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 109F9E292B6E7536006B7D63 /* CouponView.swift */; };
10BC6B432B828D7A007D1D9A /* SavedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BC6B422B828D7A007D1D9A /* SavedModel.swift */; };
10BC6B452B828EB8007D1D9A /* SavedViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BC6B442B828EB8007D1D9A /* SavedViewModel.swift */; };
10BC6B472B829EAF007D1D9A /* SavedListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BC6B462B829EAF007D1D9A /* SavedListModel.swift */; };
10BC6B492B829F7A007D1D9A /* SavedListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BC6B482B829F7A007D1D9A /* SavedListViewModel.swift */; };
10C8AC612B5C340D00B40547 /* SendOfferPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10C8AC602B5C340D00B40547 /* SendOfferPostView.swift */; };
10EBD80D2B6F783F0082CD8E /* HonorInfoEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10EBD80C2B6F783F0082CD8E /* HonorInfoEditView.swift */; };
10EBD8112B6FD6D60082CD8E /* ProfileEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10EBD8102B6FD6D60082CD8E /* ProfileEditView.swift */; };
Expand Down Expand Up @@ -175,12 +180,17 @@
100D38B92B4EF54C00498977 /* MyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyView.swift; sourceTree = "<group>"; };
1031EC7B2B68B9F20016655B /* AnnouncementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementView.swift; sourceTree = "<group>"; };
10584CBF2B81EE84007F7A3F /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; name = "GoogleService-Info.plist"; path = "/Desktop/GoogleService-Info.plist"; sourceTree = "<absolute>"; };
105A46CC2B826DC70039FD70 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Desktop/GoogleService-Info.plist"; sourceTree = "<group>"; };
106720012B5835FA00493354 /* SendOfferView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendOfferView.swift; sourceTree = "<group>"; };
107D6E682B7A8273005B6261 /* OrganizationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrganizationModel.swift; sourceTree = "<group>"; };
107D6E6A2B7A83AB005B6261 /* MyOrganizationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyOrganizationViewModel.swift; sourceTree = "<group>"; };
109ED8672B80C61A00304695 /* SponusAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SponusAPI.swift; sourceTree = "<group>"; };
109F9E272B6E692B006B7D63 /* MyTermsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyTermsView.swift; sourceTree = "<group>"; };
109F9E292B6E7536006B7D63 /* CouponView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponView.swift; sourceTree = "<group>"; };
10BC6B422B828D7A007D1D9A /* SavedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedModel.swift; sourceTree = "<group>"; };
10BC6B442B828EB8007D1D9A /* SavedViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedViewModel.swift; sourceTree = "<group>"; };
10BC6B462B829EAF007D1D9A /* SavedListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedListModel.swift; sourceTree = "<group>"; };
10BC6B482B829F7A007D1D9A /* SavedListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SavedListViewModel.swift; sourceTree = "<group>"; };
10C8AC602B5C340D00B40547 /* SendOfferPostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendOfferPostView.swift; sourceTree = "<group>"; };
10C8AC642B5EA69B00B40547 /* ChargerInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChargerInfoView.swift; sourceTree = "<group>"; };
10EBD80C2B6F783F0082CD8E /* HonorInfoEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HonorInfoEditView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -334,6 +344,7 @@
100A1E362B734DA500AAC1E8 /* Onboarding */,
DF498F282B7CDD8200ADE078 /* Portfolio */,
806AF8712B7B84F2008F7F62 /* Announcement */,
10BC6B412B828D3B007D1D9A /* Saved */,
806AF8682B79D985008F7F62 /* Category */,
10025B422B7C139300DCCC5A /* ReceivedOffer */,
10025B352B7B7B8700DCCC5A /* SendOffer */,
Expand Down Expand Up @@ -445,6 +456,17 @@
path = MyPage;
sourceTree = "<group>";
};
10BC6B412B828D3B007D1D9A /* Saved */ = {
isa = PBXGroup;
children = (
10BC6B422B828D7A007D1D9A /* SavedModel.swift */,
10BC6B442B828EB8007D1D9A /* SavedViewModel.swift */,
10BC6B462B829EAF007D1D9A /* SavedListModel.swift */,
10BC6B482B829F7A007D1D9A /* SavedListViewModel.swift */,
);
path = Saved;
sourceTree = "<group>";
};
10C8AC5F2B5C33D900B40547 /* SendOffer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -809,11 +831,13 @@
8042C3A02B820A50003DE096 /* NotificationModel.swift in Sources */,
80FA31692B5EB9490076453B /* NewPostView.swift in Sources */,
100D38B82B4EF54100498977 /* CategoryView.swift in Sources */,
10BC6B472B829EAF007D1D9A /* SavedListModel.swift in Sources */,
3BD26D062B62342C0035FE80 /* ChargerInfoView.swift in Sources */,
3BFC8D1B2B54D46D000D6006 /* MultiImagePicker.swift in Sources */,
3B36F0A62B6FEC2F0000ACFB /* Order.swift in Sources */,
10EBD8112B6FD6D60082CD8E /* ProfileEditView.swift in Sources */,
3BA7C09A2B82BA1E00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift in Sources */,
10BC6B452B828EB8007D1D9A /* SavedViewModel.swift in Sources */,
3B81BCB62B622EEA0067E9CB /* Extension.swift in Sources */,
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */,
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */,
Expand Down Expand Up @@ -846,6 +870,7 @@
106720022B5835FA00493354 /* SendOfferView.swift in Sources */,
3B81BCB22B622EBF0067E9CB /* StoreKitManager.swift in Sources */,
DF5AB15B2B827BAB0061F421 /* ReportViewModel.swift in Sources */,
10BC6B492B829F7A007D1D9A /* SavedListViewModel.swift in Sources */,
10C8AC612B5C340D00B40547 /* SendOfferPostView.swift in Sources */,
807BF83F2B51BCD400A659B9 /* SearchView.swift in Sources */,
806AF86A2B79DBD0008F7F62 /* CategoryModel.swift in Sources */,
Expand Down Expand Up @@ -873,6 +898,7 @@
DF498F252B791EB400ADE078 /* LoginViewModel.swift in Sources */,
DF90A5B42B664EE700BC54D0 /* ThirdPartyView.swift in Sources */,
109F9E2A2B6E7536006B7D63 /* CouponView.swift in Sources */,
10BC6B432B828D7A007D1D9A /* SavedModel.swift in Sources */,
10025B462B7C154800DCCC5A /* ReceivedViewModel.swift in Sources */,
DF692B1A2B7E970F00BF9B75 /* EditAnnouncementView.swift in Sources */,
80B41FFE2B77CCA40021DD90 /* NotificationView.swift in Sources */,
Expand Down

This file was deleted.

33 changes: 33 additions & 0 deletions Spon-us/Model/Saved/SavedListModel.swift
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
}
46 changes: 46 additions & 0 deletions Spon-us/Model/Saved/SavedListViewModel.swift
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)")
}
}
}
}

Loading

0 comments on commit 986d63a

Please sign in to comment.