Skip to content

Commit

Permalink
♻️ 리뷰사항 반영2
Browse files Browse the repository at this point in the history
유경님 리뷰사항 반영
  • Loading branch information
chopmozzi committed Dec 10, 2023
1 parent 48d2a7a commit af9768d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class PlaybackCell: UICollectionViewCell {
resetObserver()
}

func setPlaybackContents(post: PlaybackModels.DisplayPost) {
func setPlaybackContents(post: PlaybackModels.DisplayedPost) {
boardID = post.board.boardID
playbackView.descriptionView.titleLabel.text = post.board.title
playbackView.descriptionView.setText(post.board.description ?? "")
Expand Down
42 changes: 18 additions & 24 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
typealias Models = PlaybackModels

var worker: PlaybackWorkerProtocol?
var userWorker: UserWorkerProtocol?
var presenter: PlaybackPresentationLogic?

var parentView: Models.ParentView?
Expand Down Expand Up @@ -230,29 +229,24 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
return await withTaskGroup(of: Models.PlaybackVideo.self) { group -> [Models.PlaybackVideo] in
for post in posts {
guard let videoURL: URL = post.board.videoURL else { continue }
if let thumbnailImageURL = post.board.thumbnailImageURL {
group.addTask {
var profileImageData: Data?
let thumbnailImageData = await self.userWorker?.fetchImageData(with: thumbnailImageURL)
if let profileImageURL = post.member.profileImageURL {
profileImageData = await self.userWorker?.fetchImageData(with: profileImageURL)
}
let location: String? = await self.worker?.transLocation(latitude: post.board.latitude, longitude: post.board.longitude)
return Models.PlaybackVideo(
displayPost: Models.DisplayPost(
member: Models.Member(
memberID: post.member.identifier,
username: post.member.username,
profileImageData: profileImageData),
board: Models.Board(
boardID: post.board.identifier,
title: post.board.title,
description: post.board.description,
thumbnailImageData: thumbnailImageData,
videoURL: videoURL,
location: location),
tags: post.tag))
}
group.addTask {
async let profileImageData = self.worker?.fetchImageData(with: post.member.profileImageURL)
async let thumbnailImageData: Data? = self.worker?.fetchImageData(with: post.board.thumbnailImageURL)
async let location: String? = self.worker?.transLocation(latitude: post.board.latitude, longitude: post.board.longitude)
return Models.PlaybackVideo(
displayPost: Models.DisplayedPost(
member: Models.Member(
memberID: post.member.identifier,
username: post.member.username,
profileImageData: await profileImageData),
board: Models.Board(
boardID: post.board.identifier,
title: post.board.title,
description: post.board.description,
thumbnailImageData: await thumbnailImageData,
videoURL: videoURL,
location: await location),
tags: post.tag))
}
}
var result = [Models.PlaybackVideo]()
Expand Down
4 changes: 2 additions & 2 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum PlaybackModels {
// MARK: - Properties Type
struct PlaybackVideo: Hashable {
var id: UUID = UUID()
let displayPost: DisplayPost
let displayPost: DisplayedPost
}

enum ParentView {
Expand All @@ -21,7 +21,7 @@ enum PlaybackModels {
case other
}

struct DisplayPost: Hashable {
struct DisplayedPost: Hashable {
let member: PlaybackModels.Member
let board: PlaybackModels.Board
let tags: [String]
Expand Down
17 changes: 14 additions & 3 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protocol PlaybackWorkerProtocol {
func deletePlaybackVideo(boardID: Int) async -> Bool
func makeInfiniteScroll(posts: [Post]) -> [Post]
func transLocation(latitude: Double, longitude: Double) async -> String?
func fetchImageData(with url: URL?) async -> Data?
}

final class PlaybackWorker: PlaybackWorkerProtocol {
Expand Down Expand Up @@ -57,14 +58,24 @@ final class PlaybackWorker: PlaybackWorkerProtocol {
func transLocation(latitude: Double, longitude: Double) async -> String? {
let findLocation: CLLocation = CLLocation(latitude: latitude, longitude: longitude)
let geoCoder: CLGeocoder = CLGeocoder()
let identifier = Locale.current.identifier == "en_KR" ? "ko_kr" : Locale.current.identifier
let local: Locale = Locale(identifier: identifier)
let localeIdentifier = Locale.preferredLanguages.first != nil ? Locale.preferredLanguages[0] : Locale.current.identifier
let locale = Locale(identifier: localeIdentifier)
do {
let place = try await geoCoder.reverseGeocodeLocation(findLocation, preferredLocale: local)
let place = try await geoCoder.reverseGeocodeLocation(findLocation, preferredLocale: locale)
return place.last?.administrativeArea
} catch {
os_log(.error, "convert location error: %@", error.localizedDescription)
return nil
}
}

func fetchImageData(with url: URL?) async -> Data? {
guard let url else { return nil }
do {
return try await provider.request(url: url)
} catch {
os_log(.error, log: .data, "Error: %s", error.localizedDescription)
return nil
}
}
}
23 changes: 23 additions & 0 deletions iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
return nil
}
}

func fetchImageData(with url: URL?) async -> Data? {
guard let url else { return nil }
do {
guard let imageURL = Bundle.main.url(forResource: "sample", withExtension: "jpeg") else {
return nil
}
let mockData = try? Data(contentsOf: imageURL)
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: nil,
headerFields: nil)
return (response, mockData, nil)
}

let data = try await provider.request(url: url)
return data
} catch {
os_log(.error, log: .data, "%@", error.localizedDescription)
return nil
}
}
}

0 comments on commit af9768d

Please sign in to comment.