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

๐Ÿ”€ :: (#544) Chart Domain ๋ณ€๊ฒฝ์  ์ ์šฉ 2nd #545

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions Projects/App/Sources/Application/AppComponent+Chart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,4 @@ public extension AppComponent {
FetchChartRankingUseCaseImpl(chartRepository: chartRepository)
}
}

var fetchChartUpdateTimeUseCase: any FetchChartUpdateTimeUseCase {
shared {
FetchChartUpdateTimeUseCaseImpl(chartRepository: chartRepository)
}
}
}
13 changes: 2 additions & 11 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ private class ChartContentDependency3b8e41cfba060e4d16caProvider: ChartContentDe
var fetchChartRankingUseCase: any FetchChartRankingUseCase {
return appComponent.fetchChartRankingUseCase
}
var fetchChartUpdateTimeUseCase: any FetchChartUpdateTimeUseCase {
return appComponent.fetchChartUpdateTimeUseCase
}
var containSongsFactory: any ContainSongsFactory {
return appComponent.containSongsFactory
}
Expand Down Expand Up @@ -635,9 +632,6 @@ private class NewSongsContentDependency93a05f20fa300c5bbec3Provider: NewSongsCon
var fetchNewSongsUseCase: any FetchNewSongsUseCase {
return appComponent.fetchNewSongsUseCase
}
var fetchChartUpdateTimeUseCase: any FetchChartUpdateTimeUseCase {
return appComponent.fetchChartUpdateTimeUseCase
}
var containSongsFactory: any ContainSongsFactory {
return appComponent.containSongsFactory
}
Expand Down Expand Up @@ -766,6 +760,7 @@ private func factoryec2cede3edc2a626b35de3b0c44298fc1c149afb(_ component: Needle
#else
extension AppComponent: Registration {
public func registerItems() {

localTable["keychain-any Keychain"] = { self.keychain as Any }
localTable["homeComponent-HomeComponent"] = { self.homeComponent as Any }
localTable["newSongsComponent-NewSongsComponent"] = { self.newSongsComponent as Any }
Expand All @@ -775,8 +770,7 @@ extension AppComponent: Registration {
localTable["fetchLyricsUseCase-any FetchLyricsUseCase"] = { self.fetchLyricsUseCase as Any }
localTable["fetchNewSongsUseCase-any FetchNewSongsUseCase"] = { self.fetchNewSongsUseCase as Any }
localTable["signInFactory-any SignInFactory"] = { self.signInFactory as Any }
localTable["storageComponent-StorageComponent"] = { self.storageComponent as Any }
localTable["afterLoginComponent-AfterLoginComponent"] = { self.afterLoginComponent as Any }
localTable["storageFactory-any StorageFactory"] = { self.storageFactory as Any }
localTable["requestComponent-RequestComponent"] = { self.requestComponent as Any }
localTable["localAuthDataSource-any LocalAuthDataSource"] = { self.localAuthDataSource as Any }
localTable["remoteAuthDataSource-any RemoteAuthDataSource"] = { self.remoteAuthDataSource as Any }
Expand Down Expand Up @@ -858,7 +852,6 @@ extension AppComponent: Registration {
localTable["remoteChartDataSource-any RemoteChartDataSource"] = { self.remoteChartDataSource as Any }
localTable["chartRepository-any ChartRepository"] = { self.chartRepository as Any }
localTable["fetchChartRankingUseCase-any FetchChartRankingUseCase"] = { self.fetchChartRankingUseCase as Any }
localTable["fetchChartUpdateTimeUseCase-any FetchChartUpdateTimeUseCase"] = { self.fetchChartUpdateTimeUseCase as Any }
}
}
extension ArtistComponent: Registration {
Expand Down Expand Up @@ -950,7 +943,6 @@ extension ChartComponent: Registration {
extension ChartContentComponent: Registration {
public func registerItems() {
keyPathToName[\ChartContentDependency.fetchChartRankingUseCase] = "fetchChartRankingUseCase-any FetchChartRankingUseCase"
keyPathToName[\ChartContentDependency.fetchChartUpdateTimeUseCase] = "fetchChartUpdateTimeUseCase-any FetchChartUpdateTimeUseCase"
keyPathToName[\ChartContentDependency.containSongsFactory] = "containSongsFactory-any ContainSongsFactory"
}
}
Expand Down Expand Up @@ -1083,7 +1075,6 @@ extension HomeComponent: Registration {
extension NewSongsContentComponent: Registration {
public func registerItems() {
keyPathToName[\NewSongsContentDependency.fetchNewSongsUseCase] = "fetchNewSongsUseCase-any FetchNewSongsUseCase"
keyPathToName[\NewSongsContentDependency.fetchChartUpdateTimeUseCase] = "fetchChartUpdateTimeUseCase-any FetchChartUpdateTimeUseCase"
keyPathToName[\NewSongsContentDependency.containSongsFactory] = "containSongsFactory-any ContainSongsFactory"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import ArtistDomainInterface
import Foundation

public struct ArtistListResponseDTO: Decodable, Equatable {
let id: String
let name: ArtistListResponseDTO.Name
let group: ArtistListResponseDTO.Group
let info: ArtistListResponseDTO.Info
let imageURL: ArtistListResponseDTO.ImageURL
let graduated: Bool

public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.name.id == rhs.name.id
return lhs.id == rhs.id
}

private enum CodingKeys: String, CodingKey {
case id
case name
case group
case info
Expand All @@ -31,12 +33,10 @@ public struct ArtistListResponseDTO: Decodable, Equatable {

public extension ArtistListResponseDTO {
struct Name: Decodable {
let id: String
let krName: String
let enName: String

private enum CodingKeys: String, CodingKey {
case id = "kr"
case krName = "krShort"
case enName = "en"
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public extension ArtistListResponseDTO.Info {
public extension ArtistListResponseDTO {
func toDomain() -> ArtistListEntity {
ArtistListEntity(
id: name.id,
id: id,
krName: name.krName,
enName: name.enName,
groupName: group.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import Foundation
import RxSwift

public protocol RemoteChartDataSource {
func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]>
func fetchChartUpdateTime(type: ChartDateType) -> Single<String>
func fetchChartRanking(type: ChartDateType) -> Single<ChartEntity>
}
22 changes: 22 additions & 0 deletions Projects/Domains/ChartDomain/Interface/Entity/ChartEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ChartEntity.swift
// ChartDomainInterface
//
// Created by KTH on 5/16/24.
// Copyright ยฉ 2024 yongbeomkwak. All rights reserved.
//

import Foundation

public struct ChartEntity {
public init(
updatedAt: String,
songs: [ChartRankingEntity]
) {
self.updatedAt = updatedAt
self.songs = songs
}

public let updatedAt: String
public let songs: [ChartRankingEntity]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import Foundation
import RxSwift

public protocol ChartRepository {
func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]>
func fetchChartUpdateTime(type: ChartDateType) -> Single<String>
func fetchChartRanking(type: ChartDateType) -> Single<ChartEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import Foundation
import RxSwift

public protocol FetchChartRankingUseCase {
func execute(type: ChartDateType) -> Single<[ChartRankingEntity]>
func execute(type: ChartDateType) -> Single<ChartEntity>
}

This file was deleted.

6 changes: 0 additions & 6 deletions Projects/Domains/ChartDomain/Sources/API/ChartAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Moya

public enum ChartAPI {
case fetchChartRanking(type: ChartDateType)
case fetchChartUpdateTime(type: ChartDateType)
}

extension ChartAPI: WMAPI {
Expand All @@ -18,8 +17,6 @@ extension ChartAPI: WMAPI {
switch self {
case let .fetchChartRanking(type):
return "/\(type.rawValue)"
case let .fetchChartUpdateTime(type):
return "/updated/\(type.rawValue)"
}
}

Expand All @@ -31,9 +28,6 @@ extension ChartAPI: WMAPI {
switch self {
case .fetchChartRanking:
return .requestPlain

case .fetchChartUpdateTime:
return .requestPlain
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import Foundation
import RxSwift

public final class RemoteChartDataSourceImpl: BaseRemoteDataSource<ChartAPI>, RemoteChartDataSource {
public func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]> {
public func fetchChartRanking(type: ChartDateType) -> Single<ChartEntity> {
request(.fetchChartRanking(type: type))
.map([SingleChartRankingResponseDTO].self)
.map { $0.map { $0.toDomain(type: type) } }
}

public func fetchChartUpdateTime(type: ChartDateType) -> Single<String> {
request(.fetchChartUpdateTime(type: type))
.map { String(data: $0.data, encoding: .utf8) ?? "" }
.map(SingleChartRankingResponseDTO.self)
.map { $0.toDomain(type: type) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ public final class ChartRepositoryImpl: ChartRepository {
self.remoteChartDataSource = remoteChartDataSource
}

public func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]> {
public func fetchChartRanking(type: ChartDateType) -> Single<ChartEntity> {
remoteChartDataSource.fetchChartRanking(type: type)
}

public func fetchChartUpdateTime(type: ChartDateType) -> Single<String> {
remoteChartDataSource.fetchChartUpdateTime(type: type)
.map {
let convert: TimeInterval = TimeInterval($0) ?? -1
return convert == -1 ?
$0 : Date(timeIntervalSince1970: convert).changeDateFormatForChart() + " ์—…๋ฐ์ดํŠธ"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ import ChartDomainInterface
import Foundation
import Utility

public struct SingleChartRankingResponseDTO: Decodable, Equatable {
let songID, title: String
let artists: [String]
let increase, views, date: Int
let last: Int?
public struct SingleChartRankingResponseDTO: Decodable {
let updatedAt: Double
let songs: [SingleChartRankingResponseDTO.Songs]
}

public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.songID == rhs.songID
}
public extension SingleChartRankingResponseDTO {
struct Songs: Decodable, Equatable {
let songID, title: String
let artists: [String]
let increase, views, date: Int
let last: Int?

public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.songID == rhs.songID
}

enum CodingKeys: String, CodingKey {
case songID = "videoId"
case title, artists, views, date
case last = "previousOrder"
case increase = "viewsIncrement"
enum CodingKeys: String, CodingKey {
case songID = "videoId"
case title, artists, views, date
case last = "previousOrder"
case increase = "viewsIncrement"
}
}
}

public extension SingleChartRankingResponseDTO {
func toDomain(type: ChartDateType) -> ChartRankingEntity {
return ChartRankingEntity(
id: songID,
title: title,
artist: artists.joined(separator: ", "),
views: views,
last: last ?? 0,
increase: increase,
date: date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd")
func toDomain(type: ChartDateType) -> ChartEntity {
return ChartEntity(
updatedAt: Date(timeIntervalSince1970: updatedAt).changeDateFormatForChart() + " ์—…๋ฐ์ดํŠธ",
songs: songs.map {
return ChartRankingEntity(
id: $0.songID,
title: $0.title,
artist: $0.artists.joined(separator: ", "),
views: $0.views,
last: $0.last ?? 0,
increase: $0.increase,
date: $0.date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd")
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct FetchChartRankingUseCaseImpl: FetchChartRankingUseCase {
self.chartRepository = chartRepository
}

public func execute(type: ChartDateType) -> Single<[ChartRankingEntity]> {
public func execute(type: ChartDateType) -> Single<ChartEntity> {
chartRepository.fetchChartRanking(type: type)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import NeedleFoundation

public protocol ChartContentDependency: Dependency {
var fetchChartRankingUseCase: any FetchChartRankingUseCase { get }
var fetchChartUpdateTimeUseCase: any FetchChartUpdateTimeUseCase { get }
var containSongsFactory: any ContainSongsFactory { get }
}

Expand All @@ -15,8 +14,7 @@ public final class ChartContentComponent: Component<ChartContentDependency> {
return ChartContentViewController.viewController(
viewModel: .init(
type: type,
fetchChartRankingUseCase: dependency.fetchChartRankingUseCase,
fetchChartUpdateTimeUseCase: dependency.fetchChartUpdateTimeUseCase
fetchChartRankingUseCase: dependency.fetchChartRankingUseCase
),
containSongsFactory: dependency.containSongsFactory
)
Expand Down
Loading
Loading