-
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
303e249
commit 8facb45
Showing
6 changed files
with
107 additions
and
41 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
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,21 @@ | ||
// | ||
// ChangeBookMarkModel.swift | ||
// Spon-us | ||
// | ||
// Created by 황인성 on 2/18/24. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - ChangeBookMarkModel | ||
struct ChangeBookMarkResponse: Codable { | ||
let statusCode, message: String | ||
let content: ChangeBookMarkResponseDetail | ||
} | ||
|
||
// MARK: - Content | ||
struct ChangeBookMarkResponseDetail: Codable { | ||
let id, organizationID, announcementID: Int | ||
let bookmarked: 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,45 @@ | ||
// | ||
// ChangeBookMarkViewModel.swift | ||
// Spon-us | ||
// | ||
// Created by 황인성 on 2/18/24. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import SwiftUI | ||
import Alamofire | ||
|
||
class ChangeBookMarkViewModel: ObservableObject { | ||
@Published var changeBookmark: ChangeBookMarkResponseDetail? | ||
|
||
private let provider = MoyaProvider<SponusAPI>(session: Session(interceptor: AuthInterceptor.shared)) | ||
|
||
|
||
func fetchBookMark(announcementID: Int) { | ||
// JSON 데이터 생성 | ||
let json: [String: Any] = [ | ||
"announcementId": announcementID | ||
] | ||
|
||
// HTTP 요청에 필요한 헤더 생성 | ||
let headers: HTTPHeaders = [ | ||
"Authorization": "Bearer \(loadAccessToken(userID: UserDefaults.standard.string(forKey: "loginAccount") ?? "loadAccessToken Error"))" | ||
] | ||
|
||
// 요청 보낼 URL | ||
let url = "http://3.38.233.66:8080/api/v1/me/announcements/bookmarked" | ||
|
||
AF.request(url, method: .post, parameters: json, encoding: JSONEncoding.default, headers: headers) | ||
.responseJSON { response in | ||
switch response.result { | ||
case .success(let value): | ||
print("Request succeeded with response: \(value)") | ||
// Process response data | ||
case .failure(let error): | ||
print("Request failed with error: \(error)") | ||
// Error handling | ||
} | ||
} | ||
} | ||
} |
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
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