Skip to content

Commit

Permalink
[IDLE-000] 지원자 프로필에 캐싱적용
Browse files Browse the repository at this point in the history
KingFisher는 더이상 필요하지 않아 삭제했습니다.
  • Loading branch information
J0onYEong committed Sep 22, 2024
1 parent 8fc69ef commit 688ad87
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public extension ModuleDependency {
public static let RxMoya: TargetDependency = .external(name: "RxMoya")
public static let FSCalendar: TargetDependency = .external(name: "FSCalendar")
public static let NaverMapSDKForSPM: TargetDependency = .external(name: "Junios.NMapSDKForSPM")
public static let KingFisher: TargetDependency = .external(name: "Kingfisher")
public static let FirebaseRemoteConfig: TargetDependency = .external(name: "FirebaseRemoteConfig")
public static let FirebaseCrashlytics: TargetDependency = .external(name: "FirebaseCrashlytics")
public static let FirebaseAnalytics: TargetDependency = .external(name: "FirebaseAnalytics")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct DataAssembly: Assembly {
container.register(CacheRepository.self) { _ in
return DefaultCacheRepository()
}
.inObjectScope(.container)

// MARK: 로컬에 저장된 유저정보 레포지토리
container.register(UserInfoLocalRepository.self) { resolver in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class DefaultCacheRepository: CacheRepository {
// 접근시간 업데이트
self?.updateLastReadTime(cacheInfoKey: cacheInfoKey)

// 메모리 캐시에 올리기
self?.imageMemoryCache.setObject(image, forKey: memoryKey)

observer(.success(image))

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ public struct PostApplicantDTO: Codable {

public func toVO() -> PostApplicantVO {

var profileUrl: URL?
if let profileImageUrl {
profileUrl = URL(string: profileImageUrl)
var imageInfo: ImageDownLoadInfo? = nil

if let url = profileImageUrl, let expString = url.split(separator: ".").last {

let imageFormat = expString.uppercased()

if let format = ImageFormat(rawValue: imageFormat) {

imageInfo = .init(
imageURL: URL(string: url)!,
imageFormat: format
)
}
}

return .init(
workerId: carerId,
profileUrl: profileUrl,
imageInfo: imageInfo,
isJobFinding: jobSearchStatus == "YES",

// MARK: 센터가 즐겨찾기하는 요양보호사 추후 개발예정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public struct PostApplicantVO {
public let workerId: String

// For Render
public let profileUrl: URL?
public let imageInfo: ImageDownLoadInfo?
public let isJobFinding: Bool
public let isStared: Bool
public let name: String
public let age: Int
public let gender: Gender
public let expYear: Int?

public init(workerId: String, profileUrl: URL?, isJobFinding: Bool, isStared: Bool, name: String, age: Int, gender: Gender, expYear: Int?) {
public init(workerId: String, imageInfo: ImageDownLoadInfo?, isJobFinding: Bool, isStared: Bool, name: String, age: Int, gender: Gender, expYear: Int?) {
self.workerId = workerId
self.profileUrl = profileUrl
self.imageInfo = imageInfo
self.isJobFinding = isJobFinding
self.isStared = isStared
self.name = name
Expand All @@ -36,7 +36,7 @@ public struct PostApplicantVO {

public static let mock: PostApplicantVO = .init(
workerId: "testworkerId",
profileUrl: URL(string: "https://dummyimage.com/600x400/00ffbf/0011ff&text=worker+profile"),
imageInfo: nil,
isJobFinding: false,
isStared: false,
name: "홍길동",
Expand Down
1 change: 0 additions & 1 deletion project/Projects/Presentation/DSKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ let proejct = Project(
D.ThirdParty.RxSwift,
D.ThirdParty.RxCocoa,
D.ThirdParty.FSCalendar,
D.ThirdParty.KingFisher,
],
settings: .settings(
configurations: IdleConfiguration.presentationConfigurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import PresentationCore
import RxCocoa
import RxSwift
import Entity
import Kingfisher
import Entity

public struct ApplicantCardRO {

public let profileUrl: URL?
public let isJobFinding: Bool
// public let isStared: Bool
public let name: String
Expand All @@ -24,15 +22,13 @@ public struct ApplicantCardRO {
public let expText: String

public init(
profileUrl: URL?,
isJobFinding: Bool,
// isStared: Bool,
name: String,
ageText: String,
genderText: String,
expText: String
) {
self.profileUrl = profileUrl
self.isJobFinding = isJobFinding
// self.isStared = isStared
self.name = name
Expand All @@ -42,7 +38,6 @@ public struct ApplicantCardRO {
}

public static let mock: ApplicantCardRO = .init(
profileUrl: URL(string: "https://dummyimage.com/600x400/00ffbf/0011ff&text=worker+profile"),
isJobFinding: false,
// isStared: false,
name: "홍길동",
Expand All @@ -53,7 +48,6 @@ public struct ApplicantCardRO {

public static func create(vo: PostApplicantVO) -> ApplicantCardRO {
.init(
profileUrl: vo.profileUrl,
isJobFinding: vo.isJobFinding,
// isStared: vo.isStared,
name: vo.name,
Expand All @@ -73,6 +67,7 @@ public protocol ApplicantCardViewModelable {

// Output
var renderObject: Driver<ApplicantCardRO>? { get }
var displayingImage: Driver<UIImage>? { get }
}

public class ApplicantCard: UIView {
Expand Down Expand Up @@ -258,11 +253,6 @@ public class ApplicantCard: UIView {

public func bind(ro: ApplicantCardRO) {

if let imageUrl = ro.profileUrl {
workerProfileImage
.setImage(url: imageUrl)
}

workingTag.textString = ro.isJobFinding ? "구직중" : "휴식중"
// starButton.setState(ro.isStared ? .accent : .normal)
nameLabel.textString = ro.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public class ApplicantCardCell: UITableViewCell {
.drive(onNext: { [cardView] ro in
cardView.bind(ro: ro)
}),

viewModel
.displayingImage?
.drive(onNext: { [weak self] image in

guard let self else { return }

UIView.transition(with: contentView, duration: 0.1) {
self.cardView.workerProfileImage.image = image
}
}),

// Input
// cardView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
// Created by choijunios on 8/13/24.
//

import Foundation
import RxSwift
import RxCocoa
import UIKit
import Entity
import DSKit
import PresentationCore
import UseCaseInterface
import BaseFeature
import ConcreteRepository


import RxSwift
import RxCocoa

public protocol CheckApplicantViewModelable: BaseViewModel {
// Input
Expand Down Expand Up @@ -70,6 +73,7 @@ public class CheckApplicantVM: BaseViewModel, CheckApplicantViewModelable {
.map({ screenData in screenData.applicantList })
.asDriver(onErrorDriveWith: .never())


postCardVO = requestScreenDataSuccess
.map({ screenData in screenData.summaryCardVO })
.asDriver(onErrorDriveWith: .never())
Expand All @@ -95,6 +99,7 @@ public class CheckApplicantVM: BaseViewModel, CheckApplicantViewModelable {

// MARK: ApplicantCardVM
public class ApplicantCardVM: ApplicantCardViewModelable {
@Injected var cacheRepository: CacheRepository

// Init
let id: String
Expand All @@ -105,6 +110,9 @@ public class ApplicantCardVM: ApplicantCardViewModelable {
public var staredThisWorker: PublishRelay<Bool> = .init()

public var renderObject: Driver<ApplicantCardRO>?
public var displayingImage: RxCocoa.Driver<UIImage>?

private let imageDownLoadScheduler = ConcurrentDispatchQueueScheduler(qos: .userInitiated)

let disposeBag = DisposeBag()

Expand All @@ -116,7 +124,16 @@ public class ApplicantCardVM: ApplicantCardViewModelable {
let publishRelay: BehaviorRelay<ApplicantCardRO> = .init(value: .mock)
renderObject = publishRelay.asDriver(onErrorJustReturn: .mock)

publishRelay.accept(ApplicantCardRO.create(vo: vo))
if let imageInfo = vo.imageInfo {

displayingImage = cacheRepository
.getImage(imageInfo: imageInfo)
.subscribe(on: imageDownLoadScheduler)
.asDriver(onErrorDriveWith: .never())
}

publishRelay
.accept(ApplicantCardRO.create(vo: vo))

// MARK: 버튼 처리
showProfileButtonClicked
Expand Down
2 changes: 0 additions & 2 deletions project/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ let package = Package(
.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.4"),
// Naver map
.package(url: "https://github.com/J0onYEong/NaverMapSDKForSPM.git", from: "1.0.0"),
// KingFisher
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.12.0"),
// WebpCoder
.package(url: "https://github.com/SDWebImage/SDWebImageWebPCoder.git", from: "0.14.6"),

Expand Down

0 comments on commit 688ad87

Please sign in to comment.