-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
레시피 업로드 Domain, Data 영역을 정의해 보았습니다. #18
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
928c743
Feat: AddRecipeInteractor 정의
GeonH0 ac56a82
Feat: AddRecipeUseCase 정의
GeonH0 13864c0
Feat: NetworkService의 postRequest정의
GeonH0 74c0206
Feat: AddRecipeRepository정의
GeonH0 afd9f0b
Feat: RecipeUploadDTO 정의
GeonH0 d7677a1
Feat: RecipeUploadResponseDTO 정의
GeonH0 838777b
Feat: MultipartFormDataRequest 정의
GeonH0 b1276ad
Feat: RecipePostService 정의
GeonH0 e95db90
Feat: AddRecipeError 정의
GeonH0 58b4cc8
Fix: didLoadRecipe로 네이밍 수정
GeonH0 54cdfca
Fix: final 적용
GeonH0 ed32a83
Fix: 줄바꿈 수정
GeonH0 f527923
Merge branch 'main' into feature/UploadDomainData
GeonH0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,13 @@ | |
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
import RxSwift | ||
|
||
protocol NetworkService { | ||
func getRequest<T: Decodable>(url: URL, responseType: T.Type) -> Single<T> | ||
func postRequest<T: Decodable>(url: URL, parameters: [String: Any], imageDatas: [Data], responseType: T.Type) -> Single<T> | ||
} | ||
|
||
class BaseNetworkService: NetworkService { | ||
|
@@ -39,4 +42,61 @@ class BaseNetworkService: NetworkService { | |
} | ||
} | ||
} | ||
|
||
func postRequest<T: Decodable>( | ||
url: URL, parameters: [String: Any], | ||
imageDatas: [Data], | ||
responseType: T.Type | ||
) | ||
-> Single<T> { | ||
return Single.create { single in | ||
var formDataRequest = MultipartFormDataRequest(url: url) | ||
|
||
for (key, value) in parameters { | ||
formDataRequest.addTextField(named: key, value: String(describing: value)) | ||
} | ||
|
||
for (index, imageData) in imageDatas.enumerated() { | ||
let filename = "image\(index).jpg" | ||
formDataRequest.addDataField( | ||
named: "recipeImgUrls", | ||
data: imageData, | ||
filename: filename, | ||
mimeType: "image/jpeg" | ||
) | ||
} | ||
|
||
formDataRequest.finalize() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for문 내에서 하지 않고 밖에서 하는 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. finalize는 전체 요청이 완성된후 1번만 호출되어야 하기 떄문입니다 |
||
let request = formDataRequest.asURLRequest() | ||
|
||
let task = URLSession.shared.dataTask(with: request) { data, response, error in | ||
if let error = error { | ||
single(.failure(error)) | ||
} else if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200 { | ||
let statusCode = httpResponse.statusCode | ||
let responseString = data.flatMap { String(data: $0, encoding: .utf8) } ?? "No response data" | ||
let error = NSError( | ||
domain: "", | ||
code: statusCode, | ||
userInfo: [NSLocalizedDescriptionKey: "HTTP \(statusCode): \(responseString)"] | ||
) | ||
single(.failure(error)) | ||
} else if let data = data { | ||
do { | ||
let decoder = JSONDecoder() | ||
decoder.dateDecodingStrategy = .iso8601 | ||
let responseObject = try decoder.decode(T.self, from: data) | ||
single(.success(responseObject)) | ||
} catch let decodingError { | ||
single(.failure(decodingError)) | ||
} | ||
} | ||
} | ||
task.resume() | ||
|
||
return Disposables.create { | ||
task.cancel() | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여긴 왜 줄바꿈하셨나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤식으로 줄바꿈 해야할지 몰라서 저런식으로 한건데 저 부분은 50번째 줄로 올리겠습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ed32a83] 수정했습니다