Skip to content

Commit

Permalink
[#139] 받은제안 api연결시도중
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiddich-Dev committed Feb 18, 2024
1 parent 11e39cd commit 1af2896
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Spon-us.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
3B81BCBA2B622F280067E9CB /* MyNoticeDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B81BCB92B622F280067E9CB /* MyNoticeDetailView.swift */; };
3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */ = {isa = PBXBuildFile; fileRef = 3B81BCBD2B62312C0067E9CB /* Product.storekit */; };
3B81BCC02B6231680067E9CB /* ProductList.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B81BCBF2B6231680067E9CB /* ProductList.plist */; };
3BA7C0902B827EC600654B62 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */; };
3BA7C0922B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */; };
3BD26D062B62342C0035FE80 /* ChargerInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10C8AC642B5EA69B00B40547 /* ChargerInfoView.swift */; };
3BFC8D152B54AA55000D6006 /* EditPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BFC8D142B54AA55000D6006 /* EditPostView.swift */; };
3BFC8D1B2B54D46D000D6006 /* MultiImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BFC8D1A2B54D46D000D6006 /* MultiImagePicker.swift */; };
Expand Down Expand Up @@ -123,7 +125,6 @@
DF498F2E2B7DF4F600ADE078 /* LogoutModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */; };
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */; };
DF5AB1542B8228CC0061F421 /* MakeReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5AB1532B8228CC0061F421 /* MakeReportViewModel.swift */; };
DF5AB1572B8266D90061F421 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */; };
DF5AB1592B826ABB0061F421 /* CompanyPostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5AB1582B826ABB0061F421 /* CompanyPostView.swift */; };
DF5B7E922B7FA430001C009C /* PortfolioOfferViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */; };
DF5B7E942B808DF1001C009C /* EditAnnouncementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */; };
Expand Down Expand Up @@ -199,6 +200,8 @@
3B81BCB92B622F280067E9CB /* MyNoticeDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyNoticeDetailView.swift; sourceTree = "<group>"; };
3B81BCBD2B62312C0067E9CB /* Product.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = Product.storekit; sourceTree = "<group>"; };
3B81BCBF2B6231680067E9CB /* ProductList.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ProductList.plist; sourceTree = "<group>"; };
3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceivedOfferMyAnnouncementsViewModel.swift; sourceTree = "<group>"; };
3BFC8D142B54AA55000D6006 /* EditPostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditPostView.swift; sourceTree = "<group>"; };
3BFC8D1A2B54D46D000D6006 /* MultiImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiImagePicker.swift; sourceTree = "<group>"; };
3BFC8D1E2B5597C9000D6006 /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -229,7 +232,6 @@
DF498F2D2B7DF4F500ADE078 /* LogoutModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutModel.swift; sourceTree = "<group>"; };
DF498F2F2B7DF50200ADE078 /* LogoutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutViewModel.swift; sourceTree = "<group>"; };
DF5AB1532B8228CC0061F421 /* MakeReportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeReportViewModel.swift; sourceTree = "<group>"; };
DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
DF5AB1582B826ABB0061F421 /* CompanyPostView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompanyPostView.swift; sourceTree = "<group>"; };
DF5B7E912B7FA430001C009C /* PortfolioOfferViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortfolioOfferViewModel.swift; sourceTree = "<group>"; };
DF5B7E932B808DF0001C009C /* EditAnnouncementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAnnouncementViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -317,6 +319,7 @@
isa = PBXGroup;
children = (
10025B452B7C154800DCCC5A /* ReceivedViewModel.swift */,
3BA7C0912B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift */,
);
path = ReceivedOffer;
sourceTree = "<group>";
Expand Down Expand Up @@ -373,7 +376,7 @@
100D387F2B44826500498977 /* Spon-us */ = {
isa = PBXGroup;
children = (
DF5AB1562B8266D90061F421 /* GoogleService-Info.plist */,
3BA7C08F2B827EC600654B62 /* GoogleService-Info.plist */,
80B41FFF2B77F0DF0021DD90 /* Spon-us.entitlements */,
100D389F2B44833F00498977 /* Info.plist */,
3B36F09F2B6FEBCB0000ACFB /* PortOne */,
Expand Down Expand Up @@ -767,7 +770,7 @@
files = (
3B81BCC02B6231680067E9CB /* ProductList.plist in Resources */,
100D389C2B44833500498977 /* SUIT-Medium.otf in Resources */,
DF5AB1572B8266D90061F421 /* GoogleService-Info.plist in Resources */,
3BA7C0902B827EC600654B62 /* GoogleService-Info.plist in Resources */,
3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */,
100D38A32B44834700498977 /* Preview Assets.xcassets in Resources */,
100D389E2B44833500498977 /* Pretendard-SemiBold.otf in Resources */,
Expand Down Expand Up @@ -809,6 +812,7 @@
10EBD8112B6FD6D60082CD8E /* ProfileEditView.swift in Sources */,
3B81BCB62B622EEA0067E9CB /* Extension.swift in Sources */,
107D6E692B7A8273005B6261 /* OrganizationModel.swift in Sources */,
3BA7C0922B827EDE00654B62 /* ReceivedOfferMyAnnouncementsViewModel.swift in Sources */,
DF498F302B7DF50200ADE078 /* LogoutViewModel.swift in Sources */,
8042C38D2B807957003DE096 /* SearchOrganizationModel.swift in Sources */,
100D38B32B4EF15600498977 /* HomeView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// File.swift
// Spon-us
//
// Created by 황인성 on 2/19/24.
//

import Foundation
import Combine
import Moya
import Alamofire

class ReceivedOfferMyAnnouncementsViewModel: ObservableObject {

var subscription = Set<AnyCancellable>()

@Published var myAnnouncementsContents: [MyAnnouncementsContent] = []

let headers: HTTPHeaders = ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]

let url = "http://3.38.233.66:8080/api/v1/announcements/me"

let provider = MoyaProvider<SponusAPI>(session: Session(interceptor: AuthInterceptor.shared))


func fetchReceivedOfferMyAnnouncements(){
print(#fileID, #function, #line, "")
AF.request(url, method: .get, headers: headers)
.publishDecodable(type: MyAnnouncementsModel.self)
.compactMap{ $0.value }
.map{ $0.content }
.sink(receiveCompletion: { completion in
print("데이터스트림 완료 ")
}, receiveValue: { receivedValue in
print(receivedValue)
print("받은 값 : \(receivedValue.count)")
self.myAnnouncementsContents = receivedValue
}).store(in: &subscription)
}

// func fetchReceivedOfferMyAnnouncements(){
//
// provider.request(.getReceivedOfferMyAnnouncements) { result in
// switch result {
// case .success(let response):
// print(response.statusCode)
// // if response.data.isEmpty {
// // renewToken()
// // }
// print(response.data)
// if let jsonString = String(data: response.data, encoding: .utf8) {
// print("서버 응답 JSON 데이터: \(jsonString)")
// }
// do {
// let myAnnouncements = try JSONDecoder().decode(MyAnnouncementsModel.self, from: response.data)
// DispatchQueue.main.async {
// self.myAnnouncementsContents = myAnnouncements.content
// self.myAnnouncementsContents.sort {$0.updatedAt > $1.updatedAt}
// print(self.myAnnouncementsContents)
// }
// } catch {
// print("JSON 디코딩 오류: \(error)")
// }
// case .failure(let error):
// print(error)
// }
// }
// }

}
11 changes: 11 additions & 0 deletions Spon-us/SponusAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum SponusAPI {
case getNotification
case postReport(title: String, content: String, proposeID: Int, images: [UIImage], attatchments: [URL])
case patchProposeReportId(proposeId: Int, reportId: Int)
case getReceivedOfferMyAnnouncements
}

extension SponusAPI: TargetType {
Expand Down Expand Up @@ -101,6 +102,8 @@ extension SponusAPI: TargetType {
return "/api/v1/reports"
case .patchProposeReportId(let proposeId, _):
return "/api/v1/proposes/\(proposeId)"
case .getReceivedOfferMyAnnouncements:
return "/api/v1/announcements/me"
}
}

Expand Down Expand Up @@ -158,6 +161,8 @@ extension SponusAPI: TargetType {
return .post
case .patchProposeReportId:
return .patch
case .getReceivedOfferMyAnnouncements:
return .get
}
}

Expand Down Expand Up @@ -246,6 +251,8 @@ extension SponusAPI: TargetType {
return Data()
case .patchProposeReportId:
return Data()
case .getReceivedOfferMyAnnouncements:
return Data()
}
}

Expand Down Expand Up @@ -402,6 +409,8 @@ extension SponusAPI: TargetType {
multipartData.append(MultipartFormData(provider: .data(requestData), name: "request"))
}
return .uploadMultipart(multipartData)
case .getReceivedOfferMyAnnouncements:
return .requestPlain
}
}

Expand Down Expand Up @@ -464,6 +473,8 @@ extension SponusAPI: TargetType {
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
case .patchProposeReportId:
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
case .getReceivedOfferMyAnnouncements:
return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"]
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Spon-us/View/ReceivedOffer/MyNoticeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI
struct MyNoticeListView: View {
@Binding var rootIsActive: Bool

@StateObject var receivedOfferMyAnnouncementsViewModel = ReceivedOfferMyAnnouncementsViewModel()

var body: some View {

// NavigationView {
Expand Down Expand Up @@ -54,6 +56,9 @@ struct MyNoticeListView: View {
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: CustomBackButton())
.onAppear {
receivedOfferMyAnnouncementsViewModel.fetchReceivedOfferMyAnnouncements()
}
// }
.toolbar(.hidden, for: .tabBar)
}
Expand Down

0 comments on commit 1af2896

Please sign in to comment.