Skip to content

Commit 1af2896

Browse files
committed
[#139] 받은제안 api연결시도중
1 parent 11e39cd commit 1af2896

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

Spon-us.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
3B81BCBA2B622F280067E9CB /* MyNoticeDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B81BCB92B622F280067E9CB /* MyNoticeDetailView.swift */; };
6262
3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */ = {isa = PBXBuildFile; fileRef = 3B81BCBD2B62312C0067E9CB /* Product.storekit */; };
6363
3B81BCC02B6231680067E9CB /* ProductList.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B81BCBF2B6231680067E9CB /* ProductList.plist */; };
64+
3BA7C0902B827EC600654B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */; };
65+
3BA7C0922B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */; };
6466
3BD26D062B62342C0035FE80 /* ChargerInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10C8AC642B5EA69B00B40547 /* ChargerInfoView.swift */; };
6567
3BFC8D152B54AA55000D6006 /* EditPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BFC8D142B54AA55000D6006 /* EditPostView.swift */; };
6668
3BFC8D1B2B54D46D000D6006 /* MultiImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BFC8D1A2B54D46D000D6006 /* MultiImagePicker.swift */; };
@@ -123,7 +125,6 @@
123125
DF498F2E2B7DF4F600ADE078 /* LogoutModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */; };
124126
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */; };
125127
DF5AB1542B8228CC0061F421 /* MakeReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5AB1532B8228CC0061F421 /* MakeReportViewModel.swift */; };
126-
DF5AB1572B8266D90061F421 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */; };
127128
DF5AB1592B826ABB0061F421 /* CompanyPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5AB1582B826ABB0061F421 /* CompanyPostView.swift */; };
128129
DF5B7E922B7FA430001C009C /* PortfolioOfferViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */; };
129130
DF5B7E942B808DF1001C009C /* EditAnnouncementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */; };
@@ -199,6 +200,8 @@
199200
3B81BCB92B622F280067E9CB /* MyNoticeDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyNoticeDetailView.swift; sourceTree = "<group>"; };
200201
3B81BCBD2B62312C0067E9CB /* Product.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = Product.storekit; sourceTree = "<group>"; };
201202
3B81BCBF2B6231680067E9CB /* ProductList.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ProductList.plist; sourceTree = "<group>"; };
203+
3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
204+
3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceivedOfferMyAnnouncementsViewModel.swift; sourceTree = "<group>"; };
202205
3BFC8D142B54AA55000D6006 /* EditPostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditPostView.swift; sourceTree = "<group>"; };
203206
3BFC8D1A2B54D46D000D6006 /* MultiImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiImagePicker.swift; sourceTree = "<group>"; };
204207
3BFC8D1E2B5597C9000D6006 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
@@ -229,7 +232,6 @@
229232
DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutModel.swift; sourceTree = "<group>"; };
230233
DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutViewModel.swift; sourceTree = "<group>"; };
231234
DF5AB1532B8228CC0061F421 /* MakeReportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeReportViewModel.swift; sourceTree = "<group>"; };
232-
DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
233235
DF5AB1582B826ABB0061F421 /* CompanyPostView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompanyPostView.swift; sourceTree = "<group>"; };
234236
DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortfolioOfferViewModel.swift; sourceTree = "<group>"; };
235237
DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAnnouncementViewModel.swift; sourceTree = "<group>"; };
@@ -317,6 +319,7 @@
317319
isa = PBXGroup;
318320
children = (
319321
10025B452B7C154800DCCC5A /* ReceivedViewModel.swift */,
322+
3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */,
320323
);
321324
path = ReceivedOffer;
322325
sourceTree = "<group>";
@@ -373,7 +376,7 @@
373376
100D387F2B44826500498977 /* Spon-us */ = {
374377
isa = PBXGroup;
375378
children = (
376-
DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */,
379+
3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */,
377380
80B41FFF2B77F0DF0021DD90 /* Spon-us.entitlements */,
378381
100D389F2B44833F00498977 /* Info.plist */,
379382
3B36F09F2B6FEBCB0000ACFB /* PortOne */,
@@ -767,7 +770,7 @@
767770
files = (
768771
3B81BCC02B6231680067E9CB /* ProductList.plist in Resources */,
769772
100D389C2B44833500498977 /* SUIT-Medium.otf in Resources */,
770-
DF5AB1572B8266D90061F421 /* GoogleService-Info.plist in Resources */,
773+
3BA7C0902B827EC600654B62 /* GoogleService-Info.plist in Resources */,
771774
3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */,
772775
100D38A32B44834700498977 /* Preview Assets.xcassets in Resources */,
773776
100D389E2B44833500498977 /* Pretendard-SemiBold.otf in Resources */,
@@ -809,6 +812,7 @@
809812
10EBD8112B6FD6D60082CD8E /* ProfileEditView.swift in Sources */,
810813
3B81BCB62B622EEA0067E9CB /* Extension.swift in Sources */,
811814
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */,
815+
3BA7C0922B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift in Sources */,
812816
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */,
813817
8042C38D2B807957003DE096 /* SearchOrganizationModel.swift in Sources */,
814818
100D38B32B4EF15600498977 /* HomeView.swift in Sources */,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// File.swift
3+
// Spon-us
4+
//
5+
// Created by 황인성 on 2/19/24.
6+
//
7+
8+
import Foundation
9+
import Combine
10+
import Moya
11+
import Alamofire
12+
13+
class ReceivedOfferMyAnnouncementsViewModel: ObservableObject {
14+
15+
var subscription = Set<AnyCancellable>()
16+
17+
@Published var myAnnouncementsContents: [MyAnnouncementsContent] = []
18+
19+
let headers: HTTPHeaders = ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
20+
21+
let url = "http://3.38.233.66:8080/api/v1/announcements/me"
22+
23+
let provider = MoyaProvider<SponusAPI>(session: Session(interceptor: AuthInterceptor.shared))
24+
25+
26+
func fetchReceivedOfferMyAnnouncements(){
27+
print(#fileID, #function, #line, "")
28+
AF.request(url, method: .get, headers: headers)
29+
.publishDecodable(type: MyAnnouncementsModel.self)
30+
.compactMap{ $0.value }
31+
.map{ $0.content }
32+
.sink(receiveCompletion: { completion in
33+
print("데이터스트림 완료 ")
34+
}, receiveValue: { receivedValue in
35+
print(receivedValue)
36+
print("받은 값 : \(receivedValue.count)")
37+
self.myAnnouncementsContents = receivedValue
38+
}).store(in: &subscription)
39+
}
40+
41+
// func fetchReceivedOfferMyAnnouncements(){
42+
//
43+
// provider.request(.getReceivedOfferMyAnnouncements) { result in
44+
// switch result {
45+
// case .success(let response):
46+
// print(response.statusCode)
47+
// // if response.data.isEmpty {
48+
// // renewToken()
49+
// // }
50+
// print(response.data)
51+
// if let jsonString = String(data: response.data, encoding: .utf8) {
52+
// print("서버 응답 JSON 데이터: \(jsonString)")
53+
// }
54+
// do {
55+
// let myAnnouncements = try JSONDecoder().decode(MyAnnouncementsModel.self, from: response.data)
56+
// DispatchQueue.main.async {
57+
// self.myAnnouncementsContents = myAnnouncements.content
58+
// self.myAnnouncementsContents.sort {$0.updatedAt > $1.updatedAt}
59+
// print(self.myAnnouncementsContents)
60+
// }
61+
// } catch {
62+
// print("JSON 디코딩 오류: \(error)")
63+
// }
64+
// case .failure(let error):
65+
// print(error)
66+
// }
67+
// }
68+
// }
69+
70+
}

Spon-us/SponusAPI.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum SponusAPI {
3939
case getNotification
4040
case postReport(title: String, content: String, proposeID: Int, images: [UIImage], attatchments: [URL])
4141
case patchProposeReportId(proposeId: Int, reportId: Int)
42+
case getReceivedOfferMyAnnouncements
4243
}
4344

4445
extension SponusAPI: TargetType {
@@ -101,6 +102,8 @@ extension SponusAPI: TargetType {
101102
return "/api/v1/reports"
102103
case .patchProposeReportId(let proposeId, _):
103104
return "/api/v1/proposes/\(proposeId)"
105+
case .getReceivedOfferMyAnnouncements:
106+
return "/api/v1/announcements/me"
104107
}
105108
}
106109

@@ -158,6 +161,8 @@ extension SponusAPI: TargetType {
158161
return .post
159162
case .patchProposeReportId:
160163
return .patch
164+
case .getReceivedOfferMyAnnouncements:
165+
return .get
161166
}
162167
}
163168

@@ -246,6 +251,8 @@ extension SponusAPI: TargetType {
246251
return Data()
247252
case .patchProposeReportId:
248253
return Data()
254+
case .getReceivedOfferMyAnnouncements:
255+
return Data()
249256
}
250257
}
251258

@@ -402,6 +409,8 @@ extension SponusAPI: TargetType {
402409
multipartData.append(MultipartFormData(provider: .data(requestData), name: "request"))
403410
}
404411
return .uploadMultipart(multipartData)
412+
case .getReceivedOfferMyAnnouncements:
413+
return .requestPlain
405414
}
406415
}
407416

@@ -464,6 +473,8 @@ extension SponusAPI: TargetType {
464473
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
465474
case .patchProposeReportId:
466475
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
476+
case .getReceivedOfferMyAnnouncements:
477+
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
467478
}
468479
}
469480
}

Spon-us/View/ReceivedOffer/MyNoticeListView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import SwiftUI
1010
struct MyNoticeListView: View {
1111
@Binding var rootIsActive: Bool
1212

13+
@StateObject var receivedOfferMyAnnouncementsViewModel = ReceivedOfferMyAnnouncementsViewModel()
14+
1315
var body: some View {
1416

1517
// NavigationView {
@@ -54,6 +56,9 @@ struct MyNoticeListView: View {
5456
.navigationBarTitleDisplayMode(.inline)
5557
.navigationBarBackButtonHidden(true)
5658
.navigationBarItems(leading: CustomBackButton())
59+
.onAppear {
60+
receivedOfferMyAnnouncementsViewModel.fetchReceivedOfferMyAnnouncements()
61+
}
5762
// }
5863
.toolbar(.hidden, for: .tabBar)
5964
}

0 commit comments

Comments
 (0)