-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from gosopt-LionHeart/refactor/129-bookmark
[Refactor] #129 - 북마크 네트워크 레이어 분리
- Loading branch information
Showing
13 changed files
with
154 additions
and
44 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// BookmarkAPI.swift | ||
// LionHeart-iOS | ||
// | ||
// Created by 황찬미 on 2023/09/13. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol BookmarkAPIProtocol { | ||
func getBookmark() async throws -> BookmarkResponse? | ||
func postBookmark(model: BookmarkRequest) async throws -> BookmarkResponse? | ||
} | ||
|
||
final class BookmarkAPI: BookmarkAPIProtocol { | ||
|
||
private let apiService: Requestable | ||
|
||
init(apiService: Requestable) { | ||
self.apiService = apiService | ||
} | ||
|
||
func getBookmark() async throws -> BookmarkResponse? { | ||
let request = try makeGetBookmarkUrlRequest() | ||
return try await apiService.request(request) | ||
} | ||
|
||
func postBookmark(model: BookmarkRequest) async throws -> BookmarkResponse? { | ||
let request = try makePostBookmakrUrlRequest(model: model) | ||
return try await apiService.request(request) | ||
} | ||
} | ||
|
||
|
||
/// url request method | ||
extension BookmarkAPI { | ||
func makeGetBookmarkUrlRequest() throws -> URLRequest { | ||
return try NetworkRequest(path: "/v1/article/bookmarks", httpMethod: .get).makeURLRequest(isLogined: true) | ||
} | ||
|
||
func makePostBookmakrUrlRequest(model: BookmarkRequest) throws -> URLRequest { | ||
let param = model.toDictionary() | ||
let body = try JSONSerialization.data(withJSONObject: param) | ||
|
||
return try NetworkRequest(path: "/v1/article/bookmark", httpMethod: .post, body: body).makeURLRequest(isLogined: true) | ||
} | ||
} |
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
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
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
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
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