diff --git a/Spon-us.xcodeproj/project.pbxproj b/Spon-us.xcodeproj/project.pbxproj index 9b60ec5..463ffb8 100644 --- a/Spon-us.xcodeproj/project.pbxproj +++ b/Spon-us.xcodeproj/project.pbxproj @@ -72,6 +72,9 @@ 8042C38F2B809BA5003DE096 /* AsyncImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8042C38E2B809BA5003DE096 /* AsyncImageView.swift */; }; 8042C3912B80B9A5003DE096 /* SearchAnnouncementModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8042C3902B80B9A5003DE096 /* SearchAnnouncementModel.swift */; }; 8042C3932B80BDFC003DE096 /* SearchAnnouncementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8042C3922B80BDFC003DE096 /* SearchAnnouncementViewModel.swift */; }; + 8042C39D2B82075A003DE096 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8042C39C2B82075A003DE096 /* GoogleService-Info.plist */; }; + 8042C3A02B820A50003DE096 /* NotificationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8042C39F2B820A50003DE096 /* NotificationModel.swift */; }; + 8042C3A22B820A5B003DE096 /* NotificationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8042C3A12B820A5B003DE096 /* NotificationViewModel.swift */; }; 806AF86A2B79DBD0008F7F62 /* CategoryModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806AF8692B79DBD0008F7F62 /* CategoryModel.swift */; }; 806AF86C2B79EB3F008F7F62 /* CategoryModelData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806AF86B2B79EB3F008F7F62 /* CategoryModelData.swift */; }; 806AF8732B7B8504008F7F62 /* AnnouncementViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806AF8722B7B8504008F7F62 /* AnnouncementViewModel.swift */; }; @@ -205,6 +208,9 @@ 8042C38E2B809BA5003DE096 /* AsyncImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncImageView.swift; sourceTree = ""; }; 8042C3902B80B9A5003DE096 /* SearchAnnouncementModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchAnnouncementModel.swift; sourceTree = ""; }; 8042C3922B80BDFC003DE096 /* SearchAnnouncementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchAnnouncementViewModel.swift; sourceTree = ""; }; + 8042C39C2B82075A003DE096 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../GoogleService-Info.plist"; sourceTree = ""; }; + 8042C39F2B820A50003DE096 /* NotificationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationModel.swift; sourceTree = ""; }; + 8042C3A12B820A5B003DE096 /* NotificationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewModel.swift; sourceTree = ""; }; 806AF8692B79DBD0008F7F62 /* CategoryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryModel.swift; sourceTree = ""; }; 806AF86B2B79EB3F008F7F62 /* CategoryModelData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryModelData.swift; sourceTree = ""; }; 806AF8722B7B8504008F7F62 /* AnnouncementViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementViewModel.swift; sourceTree = ""; }; @@ -317,6 +323,7 @@ 100A1E352B7348DB00AAC1E8 /* Model */ = { isa = PBXGroup; children = ( + 8042C39E2B820A18003DE096 /* Notification */, 8042C3882B80784E003DE096 /* Search */, 100A1E362B734DA500AAC1E8 /* Onboarding */, DF498F282B7CDD8200ADE078 /* Portfolio */, @@ -364,7 +371,7 @@ 100D387F2B44826500498977 /* Spon-us */ = { isa = PBXGroup; children = ( - 10584CBF2B81EE84007F7A3F /* GoogleService-Info.plist */, + 8042C39C2B82075A003DE096 /* GoogleService-Info.plist */, 80B41FFF2B77F0DF0021DD90 /* Spon-us.entitlements */, 100D389F2B44833F00498977 /* Info.plist */, 3B36F09F2B6FEBCB0000ACFB /* PortOne */, @@ -575,6 +582,15 @@ path = Search; sourceTree = ""; }; + 8042C39E2B820A18003DE096 /* Notification */ = { + isa = PBXGroup; + children = ( + 8042C39F2B820A50003DE096 /* NotificationModel.swift */, + 8042C3A12B820A5B003DE096 /* NotificationViewModel.swift */, + ); + path = Notification; + sourceTree = ""; + }; 806AF8682B79D985008F7F62 /* Category */ = { isa = PBXGroup; children = ( @@ -742,6 +758,7 @@ 100D389C2B44833500498977 /* SUIT-Medium.otf in Resources */, 3B81BCBE2B62312C0067E9CB /* Product.storekit in Resources */, 100D38A32B44834700498977 /* Preview Assets.xcassets in Resources */, + 8042C39D2B82075A003DE096 /* GoogleService-Info.plist in Resources */, 100D389E2B44833500498977 /* Pretendard-SemiBold.otf in Resources */, 100D38AD2B44844F00498977 /* Assets.xcassets in Resources */, 10584CC02B81EE84007F7A3F /* GoogleService-Info.plist in Resources */, @@ -758,6 +775,7 @@ buildActionMask = 2147483647; files = ( 107D6E6B2B7A83AB005B6261 /* MyOrganizationViewModel.swift in Sources */, + 8042C3A22B820A5B003DE096 /* NotificationViewModel.swift in Sources */, 100D38BA2B4EF54C00498977 /* MyView.swift in Sources */, 3B81BCB42B622ED00067E9CB /* StoreKitTestView.swift in Sources */, DF90A5B22B664EBF00BC54D0 /* TermsAndConditionsView.swift in Sources */, @@ -772,6 +790,7 @@ 100D389A2B44833500498977 /* FontManager.swift in Sources */, 10025B392B7B804400DCCC5A /* SentViewModel.swift in Sources */, 100D38B62B4EF51E00498977 /* SavedView.swift in Sources */, + 8042C3A02B820A50003DE096 /* NotificationModel.swift in Sources */, 80FA31692B5EB9490076453B /* NewPostView.swift in Sources */, 100D38B82B4EF54100498977 /* CategoryView.swift in Sources */, 3BD26D062B62342C0035FE80 /* ChargerInfoView.swift in Sources */, diff --git a/Spon-us.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Spon-us.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index e20baf3..0000000 --- a/Spon-us.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,212 +0,0 @@ -{ - "pins" : [ - { - "identity" : "abseil-cpp-binary", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/abseil-cpp-binary.git", - "state" : { - "revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c", - "version" : "1.2022062300.0" - } - }, - { - "identity" : "alamofire", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Alamofire/Alamofire.git", - "state" : { - "revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad", - "version" : "5.8.1" - } - }, - { - "identity" : "app-check", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/app-check.git", - "state" : { - "revision" : "3e464dad87dad2d29bb29a97836789bf0f8f67d2", - "version" : "10.18.1" - } - }, - { - "identity" : "bsimagepicker", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mikaoj/BSImagePicker.git", - "state" : { - "revision" : "750f26abd0fafbcc4124adef436251888a7c962a", - "version" : "3.3.1" - } - }, - { - "identity" : "firebase-ios-sdk", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/firebase-ios-sdk.git", - "state" : { - "revision" : "f91c8167141d0279726c6f6d9d4a47c026785cbc", - "version" : "10.21.0" - } - }, - { - "identity" : "googleappmeasurement", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleAppMeasurement.git", - "state" : { - "revision" : "cb8617fab75d181270a1d8f763f26b15c73e2e1e", - "version" : "10.21.0" - } - }, - { - "identity" : "googledatatransport", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleDataTransport.git", - "state" : { - "revision" : "a732a4b47f59e4f725a2ea10f0c77e93a7131117", - "version" : "9.3.0" - } - }, - { - "identity" : "googleutilities", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/GoogleUtilities.git", - "state" : { - "revision" : "bc27fad73504f3d4af235de451f02ee22586ebd3", - "version" : "7.12.1" - } - }, - { - "identity" : "grpc-binary", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/grpc-binary.git", - "state" : { - "revision" : "a673bc2937fbe886dd1f99c401b01b6d977a9c98", - "version" : "1.49.1" - } - }, - { - "identity" : "gtm-session-fetcher", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/gtm-session-fetcher.git", - "state" : { - "revision" : "76135c9f4e1ac85459d5fec61b6f76ac47ab3a4c", - "version" : "3.3.1" - } - }, - { - "identity" : "iamport-ios", - "kind" : "remoteSourceControl", - "location" : "https://github.com/iamport/iamport-ios", - "state" : { - "revision" : "133390ff3debd85a10160b9041f9c8147cea1e32", - "version" : "1.4.1" - } - }, - { - "identity" : "interop-ios-for-google-sdks", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/interop-ios-for-google-sdks.git", - "state" : { - "revision" : "2d12673670417654f08f5f90fdd62926dc3a2648", - "version" : "100.0.0" - } - }, - { - "identity" : "keychain-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/evgenyneu/keychain-swift.git", - "state" : { - "revision" : "265806607b45687a3d646e4c9837c31c90f202e8", - "version" : "21.0.0" - } - }, - { - "identity" : "leveldb", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/leveldb.git", - "state" : { - "revision" : "9d108e9112aa1d65ce508facf804674546116d9c", - "version" : "1.22.3" - } - }, - { - "identity" : "moya", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Moya/Moya.git", - "state" : { - "revision" : "c263811c1f3dbf002be9bd83107f7cdc38992b26", - "version" : "15.0.3" - } - }, - { - "identity" : "nanopb", - "kind" : "remoteSourceControl", - "location" : "https://github.com/firebase/nanopb.git", - "state" : { - "revision" : "819d0a2173aff699fb8c364b6fb906f7cdb1a692", - "version" : "2.30909.0" - } - }, - { - "identity" : "popupview", - "kind" : "remoteSourceControl", - "location" : "https://github.com/exyte/PopupView.git", - "state" : { - "revision" : "4e64eb67d4510c96f82efd9e34b8fa5b9b397791", - "version" : "2.8.3" - } - }, - { - "identity" : "promises", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/promises.git", - "state" : { - "revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e", - "version" : "2.3.1" - } - }, - { - "identity" : "reactiveswift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/ReactiveCocoa/ReactiveSwift.git", - "state" : { - "revision" : "c43bae3dac73fdd3cb906bd5a1914686ca71ed3c", - "version" : "6.7.0" - } - }, - { - "identity" : "rxbus-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/iamport/RxBus-Swift", - "state" : { - "revision" : "24458425acf1da825a8e7587231052cef90c3a6b", - "version" : "1.3.5" - } - }, - { - "identity" : "rxswift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/ReactiveX/RxSwift.git", - "state" : { - "revision" : "9dcaa4b333db437b0fbfaf453fad29069044a8b4", - "version" : "6.6.0" - } - }, - { - "identity" : "swift-protobuf", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-protobuf.git", - "state" : { - "revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8", - "version" : "1.25.2" - } - }, - { - "identity" : "then", - "kind" : "remoteSourceControl", - "location" : "https://github.com/devxoul/Then.git", - "state" : { - "revision" : "e421a7b3440a271834337694e6050133a3958bc7", - "version" : "2.7.0" - } - } - ], - "version" : 2 -} diff --git a/Spon-us/Model/Notification/NotificationModel.swift b/Spon-us/Model/Notification/NotificationModel.swift new file mode 100644 index 0000000..48b2ba0 --- /dev/null +++ b/Spon-us/Model/Notification/NotificationModel.swift @@ -0,0 +1,24 @@ +// +// NotificationModel.swift +// Spon-us +// +// Created by 김수민 on 2/18/24. +// + +import Foundation + +struct NotificationModel: Codable { + let statusCode: String + let message: String + let content: [NotificationContent] +} + +struct NotificationContent: Codable, Identifiable { + let id: Int + let title: String + let body: String + let organizationId: Int? + let announcementId: Int? + let proposeId: Int? + let isRead: Bool +} diff --git a/Spon-us/Model/Notification/NotificationViewModel.swift b/Spon-us/Model/Notification/NotificationViewModel.swift new file mode 100644 index 0000000..b492c5d --- /dev/null +++ b/Spon-us/Model/Notification/NotificationViewModel.swift @@ -0,0 +1,34 @@ +// +// NotificationViewModel.swift +// Spon-us +// +// Created by 김수민 on 2/18/24. +// + +import Foundation +import Moya + +class NotificationViewModel: ObservableObject { + @Published var notificationContents: [NotificationContent] = [] + @Published var isLoading = false + let provider = MoyaProvider() + + func getNotifications(){ + self.isLoading = true + provider.request(.getNotification){result in + switch result { + case .success(let response): + do { + // 성공적으로 데이터를 받아온 경우, JSON 디코딩을 시도합니다. + let searchResults = try JSONDecoder().decode(NotificationModel.self, from: response.data) + self.notificationContents = searchResults.content + } catch let error { + // 디코딩 과정에서 오류가 발생한 경우, 오류를 처리합니다. + print("Error decoding data: \(error)") + } + case .failure(let error): + print("Error decoding data: \(error)") + } + } + } +} diff --git a/Spon-us/SponusAPI.swift b/Spon-us/SponusAPI.swift index 7fa156e..e40fe22 100644 --- a/Spon-us/SponusAPI.swift +++ b/Spon-us/SponusAPI.swift @@ -35,6 +35,8 @@ enum SponusAPI { case searchAnnouncement(keyword: String) case getMyOffer case patchPullUp(announcementID: Int) + //MARK: 알림 + case getNotification } extension SponusAPI: TargetType { @@ -91,6 +93,8 @@ extension SponusAPI: TargetType { return "/api/v1/proposes/received" case .patchPullUp(let announcementID): return "/api/v1/announcements/\(announcementID)/pullUp" + case .getNotification: + return "/api/v1/organizations/notifications" } } @@ -143,6 +147,8 @@ extension SponusAPI: TargetType { return .get case .patchPullUp: return .patch + case .getNotification: + return .get } } @@ -225,6 +231,8 @@ extension SponusAPI: TargetType { return Data() case .patchPullUp: return Data() + case .getNotification: + return Data() } } @@ -346,6 +354,8 @@ extension SponusAPI: TargetType { return .requestPlain case .patchPullUp: return .requestPlain + case .getNotification: + return .requestPlain } } @@ -402,6 +412,8 @@ extension SponusAPI: TargetType { return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"] case .patchPullUp: return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"] + case .getNotification: + return ["Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))"] } } } diff --git a/Spon-us/View/Notification/NotificationView.swift b/Spon-us/View/Notification/NotificationView.swift index 47163a9..fd8f2bf 100644 --- a/Spon-us/View/Notification/NotificationView.swift +++ b/Spon-us/View/Notification/NotificationView.swift @@ -8,12 +8,21 @@ import SwiftUI struct NotificationView: View { + @ObservedObject var viewModel = NotificationViewModel() var body: some View { - VStack(spacing: 16){ - NotificationCell(isRead: false) - NotificationCell(isRead: true) - NotificationCell(isRead: true) - Spacer() + ScrollView(){ + VStack(spacing: 16){ + // NotificationCell(isRead: false) + // NotificationCell(isRead: true) + // NotificationCell(isRead: true) + ForEach(viewModel.notificationContents) { notificationContent in + NotificationCell(notificationContent: notificationContent).frame(height: 95) + } + Spacer() + } + } + .onAppear(){ + viewModel.getNotifications() } .padding(.horizontal, 20).padding(.vertical, 16) .navigationTitle("알림").font(.Body01) @@ -24,7 +33,7 @@ struct NotificationView: View { } struct NotificationCell: View { - let isRead: Bool + var notificationContent: NotificationContent var body: some View { VStack(spacing: 20){ NavigationLink(destination: Text("df"), label : { @@ -32,16 +41,10 @@ struct NotificationCell: View { Image("company_dummy").frame(width: 46, height: 46) .padding(.trailing, 12) VStack(alignment: .leading, spacing: 4){ - Text("제안서 도착").font(.Body06).foregroundColor(isRead == true ? .sponusGrey700 : .sponusPrimary) - Text("무신사 담당자님이\n제안서를 보냈습니다.").multilineTextAlignment(.leading).font(.Body06).foregroundColor(isRead == true ? .sponusGrey700 : .sponusBlack) - HStack(spacing: 0){ - Image("ic_alert").frame(width: 8, height: 8) - .padding(.trailing, 6) - Text("27분 전").font(.English16).foregroundColor(.sponusGrey700) - Spacer() - } + Text("\(notificationContent.title)").font(.Body06).foregroundColor(notificationContent.isRead == true ? .sponusGrey700 : .sponusPrimary) + Text("\(notificationContent.body)").multilineTextAlignment(.leading).font(.Body06).foregroundColor(notificationContent.isRead == true ? .sponusGrey700 : .sponusBlack) Spacer() - }.frame(width: 237, height: 95) + } Spacer() Image("ic_move").rotationEffect(Angle(degrees: 180)) }