Skip to content

Commit

Permalink
Merge branch 'develop' into 629-connect-recommend-data
Browse files Browse the repository at this point in the history
  • Loading branch information
yongbeomkwak authored Jun 20, 2024
2 parents a363b48 + 6501ae2 commit 4adf8a4
Show file tree
Hide file tree
Showing 29 changed files with 326 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public extension ModulePaths {

public extension ModulePaths {
enum Domain: String, MicroTargetPathConvertable {
case LyricDomain
case SearchDomain
case BaseDomain
case AppDomain
Expand Down
3 changes: 2 additions & 1 deletion Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ let targets: [Target] = [
.domain(target: .SongsDomain),
.domain(target: .PlayListDomain),
.domain(target: .UserDomain),
.domain(target: .SearchDomain)
.domain(target: .SearchDomain),
.domain(target: .LyricDomain)
],
settings: .settings(
base: env.baseSetting,
Expand Down
25 changes: 25 additions & 0 deletions Projects/App/Sources/Application/AppComponent+Lyric.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import LyricDomain
import LyricDomainInterface

// MARK: 변수명 주의
// AppComponent 내 변수 == Dependency 내 변수 이름 같아야함

public extension AppComponent {
var remoteLyricDataSource: any RemoteLyricDataSource {
shared {
RemoteLyricDataSourceImpl(keychain: keychain)
}
}

var lyricRepository: any LyricRepository {
shared {
LyricRepositoryImpl(remoteLyricDataSource: remoteLyricDataSource)
}
}

var fetchDecoratingBackgroundUseCase: any FetchDecoratingBackgroundUseCase {
shared {
FetchDecoratingBackgroundUseCaseImpl(lyricRepository: lyricRepository)
}
}
}
2 changes: 2 additions & 0 deletions Projects/App/Support/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<string>$(WMDOMAIN_IMAGE_RECOMMEND_PLAYLIST_SQUARE)</string>
<key>WMDOMAIN_LIKE</key>
<string>$(WMDOMAIN_LIKE)</string>
<key>WMDOMAIN_LYRIC</key>
<string>$(WMDOMAIN_LYRIC)</string>
<key>WMDOMAIN_NOTICE</key>
<string>$(WMDOMAIN_NOTICE)</string>
<key>WMDOMAIN_PLAYLIST</key>
Expand Down
4 changes: 4 additions & 0 deletions Projects/Domains/BaseDomain/Sources/WMAPI/SecretURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ public func WMDOMAIN_APP() -> String {
public func WMDOMAIN_SEARCH() -> String {
return config(key: "WMDOMAIN_SEARCH")
}

public func WMDOMAIN_LYRIC() -> String {
return config(key: "WMDOMAIN_LYRIC")
}
3 changes: 3 additions & 0 deletions Projects/Domains/BaseDomain/Sources/WMAPI/WMAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum WMDomain: String {
case notice
case app
case search
case lyric
}

extension WMDomain {
Expand Down Expand Up @@ -84,6 +85,8 @@ extension WMDomain {
return WMDOMAIN_APP()
case .search:
return WMDOMAIN_SEARCH()
case .lyric:
return WMDOMAIN_LYRIC()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import RxSwift

public protocol RemoteLyricDataSource {
func fetchDecoratingBackground() -> Single<[DecoratingBackgroundEntity]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public struct DecoratingBackgroundEntity {
public init(
name: String,
image: String
) {
self.name = name
self.image = image
}

public let name, image: String
public var isSelected: Bool = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import RxSwift

public protocol LyricRepository {
func fetchDecoratingBackground() -> Single<[DecoratingBackgroundEntity]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import RxSwift

public protocol FetchDecoratingBackgroundUseCase {
func execute() -> Single<[DecoratingBackgroundEntity]>
}
22 changes: 22 additions & 0 deletions Projects/Domains/LyricDomain/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DependencyPlugin
import ProjectDescription
import ProjectDescriptionHelpers

let project = Project.module(
name: ModulePaths.Domain.LyricDomain.rawValue,
targets: [
.interface(
module: .domain(.LyricDomain),
dependencies: [
.domain(target: .BaseDomain, type: .interface)
]
),
.implements(
module: .domain(.LyricDomain),
dependencies: [
.domain(target: .BaseDomain),
.domain(target: .LyricDomain, type: .interface)
]
)
]
)
53 changes: 53 additions & 0 deletions Projects/Domains/LyricDomain/Sources/API/LyricAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import BaseDomain
import ErrorModule
import Foundation
import LyricDomainInterface
import Moya

public enum LyricAPI {
case fetchDecoratingBackground
}

extension LyricAPI: WMAPI {
public var domain: WMDomain {
return .lyric
}

public var urlPath: String {
switch self {
case .fetchDecoratingBackground:
return "/background"
}
}

public var method: Moya.Method {
switch self {
case .fetchDecoratingBackground:
return .get
}
}

public var task: Moya.Task {
switch self {
case .fetchDecoratingBackground:
return .requestPlain
}
}

public var jwtTokenType: JwtTokenType {
return .none
}

public var errorMap: [Int: WMError] {
switch self {
default:
return [
400: .badRequest,
401: .tokenExpired,
404: .notFound,
429: .tooManyRequest,
500: .internalServerError
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import BaseDomain
import Foundation
import LyricDomainInterface
import RxSwift

public final class RemoteLyricDataSourceImpl: BaseRemoteDataSource<LyricAPI>, RemoteLyricDataSource {
public func fetchDecoratingBackground() -> Single<[DecoratingBackgroundEntity]> {
request(.fetchDecoratingBackground)
.map([DecoratingBackgroundResponseDTO].self)
.map { $0.map { $0.toDomain() } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation
import LyricDomainInterface
import RxSwift

public final class LyricRepositoryImpl: LyricRepository {
private let remoteLyricDataSource: any RemoteLyricDataSource

public init(
remoteLyricDataSource: RemoteLyricDataSource
) {
self.remoteLyricDataSource = remoteLyricDataSource
}

public func fetchDecoratingBackground() -> Single<[DecoratingBackgroundEntity]> {
remoteLyricDataSource.fetchDecoratingBackground()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import LyricDomainInterface

public struct DecoratingBackgroundResponseDTO: Decodable {
let name: String
let image: String

private enum CodingKeys: String, CodingKey {
case name
case image = "imageUrl"
}
}

public extension DecoratingBackgroundResponseDTO {
func toDomain() -> DecoratingBackgroundEntity {
return .init(name: name, image: image)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation
import LyricDomainInterface
import RxSwift

public struct FetchDecoratingBackgroundUseCaseImpl: FetchDecoratingBackgroundUseCase {
private let lyricRepository: any LyricRepository

public init(
lyricRepository: LyricRepository
) {
self.lyricRepository = lyricRepository
}

public func execute() -> Single<[DecoratingBackgroundEntity]> {
lyricRepository.fetchDecoratingBackground()
}
}
3 changes: 2 additions & 1 deletion Projects/Features/LyricHighlightingFeature/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ let project = Project.module(
dependencies: [
.feature(target: .BaseFeature),
.feature(target: .LyricHighlightingFeature, type: .interface),
.domain(target: .SongsDomain, type: .interface)
.domain(target: .SongsDomain, type: .interface),
.domain(target: .LyricDomain, type: .interface)
]
),
.tests(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import Foundation
import LyricDomainInterface
import LyricHighlightingFeatureInterface
import NeedleFoundation

public protocol LyricDecoratingDependency: Dependency {}
public protocol LyricDecoratingDependency: Dependency {
var fetchDecoratingBackgroundUseCase: any FetchDecoratingBackgroundUseCase { get }
}

public final class LyricDecoratingComponent: Component<LyricDecoratingDependency> {
public func makeView(model: LyricHighlightingRequiredModel) -> LyricDecoratingViewController {
let viewModel = LyricDecoratingViewModel(model: model)
let viewModel = LyricDecoratingViewModel(
model: model,
fetchDecoratingBackgroundUseCase: dependency.fetchDecoratingBackgroundUseCase
)
return LyricDecoratingViewController(viewModel: viewModel)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DesignSystem
import Foundation
import Kingfisher
import RxCocoa
import RxSwift
import UIKit
Expand Down Expand Up @@ -62,11 +63,31 @@ extension LyricDecoratingViewController {
})
.disposed(by: disposeBag)

output.updateDecoratingImage
.filter { !$0.isEmpty }
.map { URL(string: $0) }
.compactMap { $0 }
.bind(with: self) { owner, url in
KingfisherManager.shared.retrieveImage(
with: url
) { result in
switch result {
case let .success(value):
owner.decorateImageView.image = value.image

case let .failure(error):
owner.showToast(
text: error.localizedDescription,
font: DesignSystemFontFamily.Pretendard.light.font(size: 14)
)
}
}
}
.disposed(by: disposeBag)

output.dataSource
.skip(1)
.do(onNext: { [decorateImageView, indicator] entities in
decorateImageView.backgroundColor = entities.filter { $0.isSelected }.first?
.imageColor ?? DesignSystemAsset.PrimaryColorV2.point.color
.do(onNext: { [indicator] _ in
indicator.stopAnimating()
})
.bind(to: collectionView.rx.items) { collectionView, index, model in
Expand All @@ -76,7 +97,7 @@ extension LyricDecoratingViewController {
) as? LyricDecoratingCell else {
return UICollectionViewCell()
}
cell.update(model: model, index: index)
cell.update(model: model)
return cell
}
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class LyricDecoratingViewController: UIViewController {

private let decorateContentView = UIView()
let decorateShareContentView = UIView().then {
$0.layer.cornerRadius = 8
$0.layer.cornerRadius = 32
$0.clipsToBounds = true
}

Expand Down Expand Up @@ -166,7 +166,6 @@ extension LyricDecoratingViewController: UICollectionViewDelegateFlowLayout {
private extension LyricDecoratingViewController {
func addSubViews() {
view.addSubviews(navigationBarView, decorateContentView, decorateBottomView, indicator)

navigationBarView.addSubviews(backButton, navigationTitleLabel)

decorateContentView.addSubview(decorateShareContentView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ extension LyricHighlightingViewController {

output.dataSource
.skip(1)
.do(onNext: { [indicator] _ in
.do(onNext: { [indicator, emptyLabel] model in
indicator.stopAnimating()
emptyLabel.isHidden = !model.isEmpty
})
.bind(to: collectionView.rx.items) { collectionView, index, entity in
guard let cell = collectionView.dequeueReusableCell(
Expand Down
Loading

0 comments on commit 4adf8a4

Please sign in to comment.