-
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
1 parent
3db6c9a
commit b01242e
Showing
6 changed files
with
108 additions
and
228 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,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 | ||
} |
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,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<SponusAPI>() | ||
|
||
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)") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.