Skip to content

Commit

Permalink
Merge pull request #540 from wakmusic/512-update-domain-chart
Browse files Browse the repository at this point in the history
🔀 :: (#512) v3.0 api 변경점 적용 - Chart Domain
  • Loading branch information
KangTaeHoon authored May 15, 2024
2 parents 3099fea + 7719a76 commit 9f41d37
Show file tree
Hide file tree
Showing 42 changed files with 236 additions and 249 deletions.
6 changes: 0 additions & 6 deletions Projects/App/Sources/Application/AppComponent+Songs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public extension AppComponent {
}
}

var fetchSearchSongUseCase: any FetchSearchSongUseCase {
shared {
FetchSearchSongUseCaseImpl(songsRepository: songsRepository)
}
}

var fetchLyricsUseCase: any FetchLyricsUseCase {
shared {
FetchLyricsUseCaseImpl(songsRepository: songsRepository)
Expand Down
5 changes: 0 additions & 5 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,6 @@ private class AfterSearchDependency61822c19bc2eb46d7c52Provider: AfterSearchDepe
var afterSearchContentComponent: AfterSearchContentComponent {
return appComponent.afterSearchContentComponent
}
var fetchSearchSongUseCase: any FetchSearchSongUseCase {
return appComponent.fetchSearchSongUseCase
}
var containSongsFactory: any ContainSongsFactory {
return appComponent.containSongsFactory
}
Expand Down Expand Up @@ -794,7 +791,6 @@ extension AppComponent: Registration {
localTable["newSongsContentComponent-NewSongsContentComponent"] = { self.newSongsContentComponent as Any }
localTable["remoteSongsDataSource-any RemoteSongsDataSource"] = { self.remoteSongsDataSource as Any }
localTable["songsRepository-any SongsRepository"] = { self.songsRepository as Any }
localTable["fetchSearchSongUseCase-any FetchSearchSongUseCase"] = { self.fetchSearchSongUseCase as Any }
localTable["fetchLyricsUseCase-any FetchLyricsUseCase"] = { self.fetchLyricsUseCase as Any }
localTable["fetchNewSongsUseCase-any FetchNewSongsUseCase"] = { self.fetchNewSongsUseCase as Any }
localTable["signInFactory-any SignInFactory"] = { self.signInFactory as Any }
Expand Down Expand Up @@ -1120,7 +1116,6 @@ extension NewSongsContentComponent: Registration {
extension AfterSearchComponent: Registration {
public func registerItems() {
keyPathToName[\AfterSearchDependency.afterSearchContentComponent] = "afterSearchContentComponent-AfterSearchContentComponent"
keyPathToName[\AfterSearchDependency.fetchSearchSongUseCase] = "fetchSearchSongUseCase-any FetchSearchSongUseCase"
keyPathToName[\AfterSearchDependency.containSongsFactory] = "containSongsFactory-any ContainSongsFactory"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public struct ArtistListEntity: Equatable {
public init(
ID: String,
id: String,
krName: String,
enName: String,
groupName: String,
Expand All @@ -22,7 +22,7 @@ public struct ArtistListEntity: Equatable {
graduated: Bool,
isHiddenItem: Bool
) {
self.ID = ID
self.id = id
self.krName = krName
self.enName = enName
self.groupName = groupName
Expand All @@ -36,10 +36,10 @@ public struct ArtistListEntity: Equatable {
}

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

public let ID, krName, enName, groupName: String
public let id, krName, enName, groupName: String
public let title, description: String
public let personalColor: String
public let roundImage, squareImage: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct ArtistListResponseDTO: Decodable, Equatable {
let graduated: Bool?

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

private enum CodingKeys: String, CodingKey {
Expand All @@ -31,17 +31,18 @@ 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"
}
}

struct Group: Decodable {
let id: String
let name: String
}

Expand Down Expand Up @@ -70,7 +71,7 @@ public extension ArtistListResponseDTO.Info {
public extension ArtistListResponseDTO {
func toDomain() -> ArtistListEntity {
ArtistListEntity(
ID: group?.id ?? "",
id: name?.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,6 @@ import Foundation
import RxSwift

public protocol RemoteChartDataSource {
func fetchChartRanking(type: ChartDateType, limit: Int) -> Single<[ChartRankingEntity]>
func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]>
func fetchChartUpdateTime(type: ChartDateType) -> Single<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ public struct ChartRankingEntity: Equatable {
id: String,
title: String,
artist: String,
remix: String,
reaction: String,
views: Int,
last: Int,
increase: Int,
Expand All @@ -16,17 +14,14 @@ public struct ChartRankingEntity: Equatable {
self.id = id
self.title = title
self.artist = artist
self.remix = remix
self.reaction = reaction
self.views = views
self.last = last
self.increase = increase
self.date = date
self.isSelected = isSelected
}

public let id, title, artist, remix: String
public let reaction: String
public let id, title, artist: String
public let views, last, increase: Int
public let date: String
public var isSelected: Bool
Expand Down
18 changes: 9 additions & 9 deletions Projects/Domains/ChartDomain/Interface/Enum/ChartDateType.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Foundation

public enum ChartDateType: String {
case monthly
case weekly
case daily
case hourly
case daily
case weekly
case monthly
case total

public var display: String {
switch self {
case .monthly:
return "월간순"
case .weekly:
return "주간순"
case .daily:
return "일간순"
case .hourly:
return "시간순"
case .daily:
return "일간순"
case .weekly:
return "주간순"
case .monthly:
return "월간순"
case .total:
return "누적순"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation
import RxSwift

public protocol ChartRepository {
func fetchChartRanking(type: ChartDateType, limit: Int) -> Single<[ChartRankingEntity]>
func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]>
func fetchChartUpdateTime(type: ChartDateType) -> Single<String>
}
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, limit: Int) -> Single<[ChartRankingEntity]>
func execute(type: ChartDateType) -> Single<[ChartRankingEntity]>
}
13 changes: 5 additions & 8 deletions Projects/Domains/ChartDomain/Sources/API/ChartAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
import Moya

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

Expand All @@ -16,8 +16,8 @@ extension ChartAPI: WMAPI {

public var urlPath: String {
switch self {
case .fetchChartRanking:
return "/"
case let .fetchChartRanking(type):
return "/\(type.rawValue)"
case let .fetchChartUpdateTime(type):
return "/updated/\(type.rawValue)"
}
Expand All @@ -29,11 +29,8 @@ extension ChartAPI: WMAPI {

public var task: Moya.Task {
switch self {
case let .fetchChartRanking(type, limit):
return .requestParameters(parameters: [
"type": type.rawValue,
"limit": limit
], encoding: URLEncoding.queryString)
case .fetchChartRanking:
return .requestPlain

case .fetchChartUpdateTime:
return .requestPlain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Foundation
import RxSwift

public final class RemoteChartDataSourceImpl: BaseRemoteDataSource<ChartAPI>, RemoteChartDataSource {
public func fetchChartRanking(type: ChartDateType, limit: Int) -> Single<[ChartRankingEntity]> {
request(.fetchChartRanking(type: type, limit: limit))
public func fetchChartRanking(type: ChartDateType) -> Single<[ChartRankingEntity]> {
request(.fetchChartRanking(type: type))
.map([SingleChartRankingResponseDTO].self)
.map { $0.map { $0.toDomain(type: type) } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ public final class ChartRepositoryImpl: ChartRepository {
self.remoteChartDataSource = remoteChartDataSource
}

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

public func fetchChartUpdateTime(type: ChartDateType) -> Single<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,31 @@ import Foundation
import Utility

public struct SingleChartRankingResponseDTO: Decodable, Equatable {
public let id, title, artist, remix, reaction: String
public let date, start, end: Int
public let monthly, weekly, daily, hourly, total: SingleChartRankingResponseDTO.ChartInfo?
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.id == rhs.id
return lhs.songID == rhs.songID
}

enum CodingKeys: String, CodingKey {
case id = "songId"
case title, artist, remix, reaction, date, start, end
case monthly, weekly, daily, hourly, total
}
}

public extension SingleChartRankingResponseDTO {
struct ChartInfo: Codable {
public let views, last: Int
public let increase: Int?
case songID = "videoId"
case title, artists, views, date
case last = "previousOrder"
case increase = "viewsIncrement"
}
}

public extension SingleChartRankingResponseDTO {
func toDomain(type: ChartDateType) -> ChartRankingEntity {
var views: Int = 0
var last: Int = 0
var increase: Int = 0
switch type {
case .monthly:
views = monthly?.views ?? 0
last = monthly?.last ?? 0
increase = monthly?.increase ?? 0
case .weekly:
views = weekly?.views ?? 0
last = weekly?.last ?? 0
increase = weekly?.increase ?? 0
case .daily:
views = daily?.views ?? 0
last = daily?.last ?? 0
increase = daily?.increase ?? 0
case .hourly:
views = hourly?.views ?? 0
last = hourly?.last ?? 0
increase = hourly?.increase ?? 0
case .total:
views = total?.views ?? 0
last = total?.last ?? 0
increase = total?.increase ?? 0
}

return ChartRankingEntity(
id: id,
id: songID,
title: title,
artist: artist,
remix: remix,
reaction: reaction,
artist: artists.joined(separator: ", "),
views: views,
last: last,
last: last ?? 0,
increase: increase,
date: date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd")
)
Expand Down
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, limit: Int) -> Single<[ChartRankingEntity]> {
chartRepository.fetchChartRanking(type: type, limit: limit)
public func execute(type: ChartDateType) -> Single<[ChartRankingEntity]> {
chartRepository.fetchChartRanking(type: type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public extension SinglePlayListDetailResponseDTO {
title: title,
songs: (songs ?? []).map { dto in
return SongEntity(
id: dto.id,
id: dto.songID,
title: dto.title,
artist: dto.artist,
remix: dto.remix,
reaction: dto.reaction,
views: dto.total?.views ?? 0,
last: dto.total?.last ?? 0,
artist: dto.artists.joined(separator: ", "),
remix: "",
reaction: "",
views: dto.views,
last: 0,
date: dto.date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd")
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import RxSwift

public protocol RemoteSongsDataSource {
func fetchSearchSong(keyword: String) -> Single<SearchResultEntity>
func fetchLyrics(id: String) -> Single<[LyricsEntity]>
func fetchSongCredits(id: String) -> Single<SongCreditsEntity>
func fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int) -> Single<[NewSongsEntity]>
}
13 changes: 2 additions & 11 deletions Projects/Domains/SongsDomain/Interface/Entity/LyricsEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@ import Foundation

public struct LyricsEntity: Equatable {
public init(
identifier: String,
start: Double,
end: Double,
text: String,
styles: String
text: String
) {
self.identifier = identifier
self.start = start
self.end = end
self.text = text
self.styles = styles
}

public let identifier, text, styles: String
public let start, end: Double
public let text: String
}
Loading

0 comments on commit 9f41d37

Please sign in to comment.