Skip to content

Commit

Permalink
Merge pull request #599 from wakmusic/598-update-songs-domain
Browse files Browse the repository at this point in the history
🔀 :: (#598) SongsDomain api 추가 변경사항 반영
  • Loading branch information
KangTaeHoon authored Jun 15, 2024
2 parents f334786 + d0d40ed commit b6b1998
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 158 deletions.
6 changes: 6 additions & 0 deletions Projects/App/Sources/Application/AppComponent+Songs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public extension AppComponent {
}
}

var fetchSongUseCase: any FetchSongUseCase {
shared {
FetchSongUseCaseImpl(songsRepository: songsRepository)
}
}

var fetchLyricsUseCase: any FetchLyricsUseCase {
shared {
FetchLyricsUseCaseImpl(songsRepository: songsRepository)
Expand Down
191 changes: 96 additions & 95 deletions Projects/App/Sources/Application/NeedleGenerated.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation
import RxSwift

public protocol RemoteSongsDataSource {
func fetchSong(id: String) -> Single<SongEntity>
func fetchLyrics(id: String) -> Single<[LyricsEntity]>
func fetchSongCredits(id: String) -> Single<SongCreditsEntity>
func fetchSongCredits(id: String) -> Single<[SongCreditsEntity]>
func fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int) -> Single<[NewSongsEntity]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,13 @@ import Foundation

public struct SongCreditsEntity {
public init(
vocal: [String],
featuring: [String],
original: String,
producing: [String],
lyrics: [String],
relyrics: [String],
compose: [String],
arrange: [String],
mixing: [String],
mastering: [String],
session: [String],
chorus: [String],
vocalGuide: [String],
trainer: [String]
type: String,
names: [String]
) {
self.vocal = vocal
self.featuring = featuring
self.original = original
self.producing = producing
self.lyrics = lyrics
self.relyrics = relyrics
self.compose = compose
self.arrange = arrange
self.mixing = mixing
self.mastering = mastering
self.session = session
self.chorus = chorus
self.vocalGuide = vocalGuide
self.trainer = trainer
self.type = type
self.names = names
}

public let vocal, featuring: [String]
public let original: String
public let producing, lyrics, relyrics, compose: [String]
public let arrange, mixing, mastering, session: [String]
public let chorus, vocalGuide, trainer: [String]
public let type: String
public let names: [String]
}
16 changes: 15 additions & 1 deletion Projects/Domains/SongsDomain/Interface/Entity/SongEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public struct SongEntity: Hashable, Equatable {
views: Int,
last: Int,
date: String,
isSelected: Bool = false
isSelected: Bool = false,
karaokeNumber: SongEntity.KaraokeNumber = .init(TJ: nil, KY: nil)
) {
self.id = id
self.title = title
Expand All @@ -21,13 +22,15 @@ public struct SongEntity: Hashable, Equatable {
self.last = last
self.date = date
self.isSelected = isSelected
self.karaokeNumber = karaokeNumber
}

public let id, title, artist, remix: String
public let reaction: String
public let views, last: Int
public let date: String
public var isSelected: Bool
public let karaokeNumber: SongEntity.KaraokeNumber

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
Expand All @@ -37,3 +40,14 @@ public struct SongEntity: Hashable, Equatable {
lhs.id == rhs.id
}
}

public extension SongEntity {
struct KaraokeNumber {
public init (TJ: Int?, KY: Int?) {
self.TJ = TJ
self.KY = KY
}

public let TJ, KY: Int?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation
import RxSwift

public protocol SongsRepository {
func fetchSong(id: String) -> Single<SongEntity>
func fetchLyrics(id: String) -> Single<[LyricsEntity]>
func fetchSongCredits(id: String) -> Single<SongCreditsEntity>
func fetchSongCredits(id: String) -> Single<[SongCreditsEntity]>
func fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int) -> Single<[NewSongsEntity]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import Foundation
import RxSwift

public protocol FetchSongCreditsUseCase {
func execute(id: String) -> Single<SongCreditsEntity>
func execute(id: String) -> Single<[SongCreditsEntity]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation
import RxSwift

public protocol FetchSongUseCase {
func execute(id: String) -> Single<SongEntity>
}
5 changes: 4 additions & 1 deletion Projects/Domains/SongsDomain/Sources/API/SongsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Moya
import SongsDomainInterface

public enum SongsAPI {
case fetchSong(id: String)
case fetchLyrics(id: String)
case fetchCredits(id: String)
case fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int)
Expand All @@ -17,6 +18,8 @@ extension SongsAPI: WMAPI {

public var urlPath: String {
switch self {
case let .fetchSong(id):
return "/\(id)"
case let .fetchLyrics(id):
return "/\(id)/lyrics"
case let .fetchCredits(id):
Expand All @@ -32,7 +35,7 @@ extension SongsAPI: WMAPI {

public var task: Moya.Task {
switch self {
case .fetchLyrics, .fetchCredits:
case .fetchSong, .fetchLyrics, .fetchCredits:
return .requestPlain

case let .fetchNewSongs(_, page, limit):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import RxSwift
import SongsDomainInterface

public final class RemoteSongsDataSourceImpl: BaseRemoteDataSource<SongsAPI>, RemoteSongsDataSource {
public func fetchSong(id: String) -> Single<SongEntity> {
request(.fetchSong(id: id))
.map(SingleSongResponseDTO.self)
.map { $0.toDomain() }
}

public func fetchLyrics(id: String) -> Single<[LyricsEntity]> {
request(.fetchLyrics(id: id))
.map([LyricsResponseDTO].self)
.map { $0.map { $0.toDomain() }}
}

public func fetchSongCredits(id: String) -> Single<SongCreditsEntity> {
public func fetchSongCredits(id: String) -> Single<[SongCreditsEntity]> {
request(.fetchCredits(id: id))
.map(SongCreditsResponseDTO.self)
.map { $0.toDomain() }
.map([SongCreditsResponseDTO].self)
.map { $0.map { $0.toDomain() }}
}

public func fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int) -> Single<[NewSongsEntity]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ public final class SongsRepositoryImpl: SongsRepository {
self.remoteSongsDataSource = remoteSongsDataSource
}

public func fetchSong(id: String) -> Single<SongEntity> {
remoteSongsDataSource.fetchSong(id: id)
}

public func fetchLyrics(id: String) -> Single<[LyricsEntity]> {
remoteSongsDataSource.fetchLyrics(id: id)
}

public func fetchSongCredits(id: String) -> Single<SongCreditsEntity> {
public func fetchSongCredits(id: String) -> Single<[SongCreditsEntity]> {
remoteSongsDataSource.fetchSongCredits(id: id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ public struct SingleSongResponseDTO: Decodable {
public let songID, title: String
public let artists: [String]
public let date, views, likes: Int
public let karaokeNumber: SingleSongResponseDTO.KaraokeNumber

enum CodingKeys: String, CodingKey {
case title, artists, date, views, likes
case songID = "videoId"
case karaokeNumber
}
}

public extension SingleSongResponseDTO {
struct KaraokeNumber: Decodable {
public let TJ, KY: Int?
}
}

Expand All @@ -31,7 +39,8 @@ public extension SingleSongResponseDTO {
reaction: "",
views: views,
last: 0,
date: date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd")
date: date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd"),
karaokeNumber: .init(TJ: karaokeNumber.TJ, KY: karaokeNumber.KY)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,15 @@ import Foundation
import SongsDomainInterface

public struct SongCreditsResponseDTO: Decodable {
let vocal, featuring: [String]
let original: String
let producing, lyrics, relyrics, compose: [String]
let arrange, mixing, mastering, session: [String]
let chorus, vocalGuide, trainer: [String]
let type: String
let names: [String]
}

public extension SongCreditsResponseDTO {
func toDomain() -> SongCreditsEntity {
return SongCreditsEntity(
vocal: vocal,
featuring: featuring,
original: original,
producing: producing,
lyrics: lyrics,
relyrics: relyrics,
compose: compose,
arrange: arrange,
mixing: mixing,
mastering: mastering,
session: session,
chorus: chorus,
vocalGuide: vocalGuide,
trainer: trainer
type: type,
names: names
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct FetchSongCreditsUseCaseImpl: FetchSongCreditsUseCase {
self.songsRepository = songsRepository
}

public func execute(id: String) -> RxSwift.Single<SongCreditsEntity> {
public func execute(id: String) -> Single<[SongCreditsEntity]> {
songsRepository.fetchSongCredits(id: id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import RxSwift
import SongsDomainInterface

public struct FetchSongUseCaseImpl: FetchSongUseCase {
private let songsRepository: any SongsRepository

public init(
songsRepository: SongsRepository
) {
self.songsRepository = songsRepository
}

public func execute(id: String) -> Single<SongEntity> {
songsRepository.fetchSong(id: id)
}
}

0 comments on commit b6b1998

Please sign in to comment.