-
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
Json 업로드 로직 수정 #161
Milestone
Comments
사진 이미지 파일 이름 get 메서드 작성 필요! |
DrinkUploadViewModel.swift
private func fetchImagesURL<T: RawDrink>(drinkData: [T], imagesURL: inout [URL?]) async {
await withTaskGroup(of: (Int, URL?).self) { group in
for (index, drink) in drinkData.enumerated() {
group.addTask {
do {
// TODO: get image file name
let url = try await self.fireStorageService.fetchImageURL(folder: .drink, fileName: "")
return (index, url)
} catch {
print("error :: fetchImageURL", error.localizedDescription)
return (index, nil)
}
}
}
var result = [(Int, URL?)]()
for await downloadURL in group {
result.append(downloadURL)
}
imagesURL = result.sorted(by: { $0.0 < $1.0 }).map { $0.1 }
}
} private func fetchImagesURL<T: RawDrink>(drinkData: [T]) async -> [URL?] {
await withTaskGroup(of: (Int, URL?).self) { group in
for (index, drink) in drinkData.enumerated() {
group.addTask {
do {
// TODO: get image file name
let url = try await self.fireStorageService.fetchImageURL(folder: .drink, fileName: "")
return (index, url)
} catch {
print("error :: fetchImageURL", error.localizedDescription)
return (index, nil)
}
}
}
var result = [(Int, URL?)]()
for await downloadURL in group {
result.append(downloadURL)
}
return result.sorted(by: { $0.0 < $1.0 }).map { $0.1 }
}
} |
bdrsky2010
added a commit
that referenced
this issue
Mar 18, 2024
DrinkUploadViewModel.swift
private func getDrinkType(drinkJsonType: DrinkJsonType) -> DrinkType {
switch drinkJsonType {
case .beer:
return .beer
case .wine:
return .wine
case .traditional:
return .traditional
case .whiskey:
return .whiskey
}
}
private func fetchImagesURL<T: RawDrink>(drinkJsonType: DrinkJsonType, drinkData: [T]) async -> [URL?] {
let category = getDrinkType(drinkJsonType: drinkJsonType)
return await withTaskGroup(of: (Int, URL?).self) { group in
for (index, drink) in drinkData.enumerated() {
group.addTask {
do {
if let fileName = Formatter.getImageName(category: category, detailedCategory: drink.type) {
let url = try await self.fireStorageService.fetchImageURL(folder: .drink, fileName: "")
return (index, url)
} else {
print("error :: getImageName")
return (index, nil)
}
} catch {
print("error :: fetchImageURL", error.localizedDescription)
return (index, nil)
}
}
}
var result = [(Int, URL?)]()
for await downloadURL in group {
result.append(downloadURL)
}
return result.sorted(by: { $0.0 < $1.0 }).map { $0.1 }
}
} |
작성완료 |
bdrsky2010
added a commit
that referenced
this issue
Mar 18, 2024
private enum DrinkJsonType: CaseIterable {
case beer, wine, traditional, whiskey
var jsonName: String {
switch self {
case .beer:
return "BeerTest"
case .traditional:
return "TraditionalTest"
case .whiskey:
return "WhiskeyTest"
case .wine:
return "WineTest"
}
}
} |
bdrsky2010
added a commit
that referenced
this issue
Mar 21, 2024
[Edit] enum DrinkJsonType case별로 맞지 않은 return 값을 갖고 있어 수정 #161
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DrinkUploadViewModel.swift
The text was updated successfully, but these errors were encountered: