Skip to content
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

๐Ÿ”€ :: (#579) LyricDomain - API ๋ณ€๊ฒฝ์‚ฌํ•ญ ๋ฐ˜์˜ (์‹ ๊ทœ) #627

Merged
merged 15 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
a138d9a
โšก๏ธ :: [#579] LyricDomain ์ƒ์„ฑ ๋ฐ ๋กœ์ง ์ž‘์„ฑ
KangTaeHoon Jun 18, 2024
a061d7d
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
KangTaeHoon Jun 18, 2024
d4dc1a0
โšก๏ธ :: [#579] USeCase ์ฃผ์ž…
KangTaeHoon Jun 18, 2024
23df7e7
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
KangTaeHoon Jun 18, 2024
53d3957
โšก๏ธ :: [#579] UseCase ๋กœ์ง์œผ๋กœ ๋ณ€๊ฒฝ
KangTaeHoon Jun 18, 2024
eb42839
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
KangTaeHoon Jun 18, 2024
0ef14ea
โšก๏ธ :: [#579] ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์—…๋ฐ์ดํŠธ ๋กœ์ง ์ถ”๊ฐ€
KangTaeHoon Jun 18, 2024
fe01552
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
KangTaeHoon Jun 18, 2024
fb3fd56
โ™ป๏ธ :: [#579] ์ฝ”๋“œ์ •๋ฆฌ
KangTaeHoon Jun 19, 2024
e6bee64
โ™ป๏ธ :: [#579] ์ฝ”๋“œ์ •๋ฆฌ
KangTaeHoon Jun 19, 2024
777cf59
โšก๏ธ :: [#579] ๊ฐ€์‚ฌ ์—†์„ ๋•Œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
KangTaeHoon Jun 19, 2024
3fe055c
๐ŸŽจ :: ์ฝ”๋“œ Formatting ์ ์šฉ
KangTaeHoon Jun 19, 2024
5acd16c
โ™ป๏ธ :: [#579] ์ฝ”๋“œ ๋ผ์ธ ์ •๋ฆฌ
KangTaeHoon Jun 19, 2024
7f73c73
โšก๏ธ :: [#579] cornerRadius 8 > 32
KangTaeHoon Jun 19, 2024
607676e
โšก๏ธ :: [#579] map์— ์žˆ๋˜ ๋กœ์ง ๋ถ„๋ฆฌ
KangTaeHoon Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading