Skip to content

Commit

Permalink
Merge pull request #541 from wakmusic/507-update-domain-song
Browse files Browse the repository at this point in the history
🔀 :: (#507) v3.0 api 변경점 적용 - Song Domain
  • Loading branch information
KangTaeHoon authored May 15, 2024
2 parents 154da0c + e8d62b2 commit 7719a76
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 160 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 @@ -5,8 +5,8 @@ import Utility
public struct SingleChartRankingResponseDTO: Decodable, Equatable {
let songID, title: String
let artists: [String]
let date: Int
let last, increase, views: Int?
let increase, views, date: Int
let last: Int?

public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.songID == rhs.songID
Expand All @@ -26,9 +26,9 @@ public extension SingleChartRankingResponseDTO {
id: songID,
title: title,
artist: artists.joined(separator: ", "),
views: views ?? 0,
views: views,
last: last ?? 0,
increase: increase ?? 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 @@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SongCreditsEntity.swift
// SongsDomain
//
// Created by KTH on 5/14/24.
// Copyright © 2024 yongbeomkwak. All rights reserved.
//

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]
) {
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
}

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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import RxSwift

public protocol SongsRepository {
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]>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FetchSongCreditsUseCase.swift
// SongsDomain
//
// Created by KTH on 5/14/24.
// Copyright © 2024 yongbeomkwak. All rights reserved.
//

import Foundation
import RxSwift

public protocol FetchSongCreditsUseCase {
func execute(id: String) -> Single<SongCreditsEntity>
}
18 changes: 6 additions & 12 deletions Projects/Domains/SongsDomain/Sources/API/SongsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Moya
import SongsDomainInterface

public enum SongsAPI {
case fetchSearchSong(keyword: String)
case fetchLyrics(id: String)
case fetchCredits(id: String)
case fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int)
}

Expand All @@ -17,10 +17,10 @@ extension SongsAPI: WMAPI {

public var urlPath: String {
switch self {
case .fetchSearchSong:
return "/search/all"
case let .fetchLyrics(id: id):
return "/lyrics/\(id)"
case let .fetchLyrics(id):
return "/\(id)/lyrics"
case let .fetchCredits(id):
return "/\(id)/credits"
case let .fetchNewSongs(type, _, _):
return "/new/\(type.apiKey)"
}
Expand All @@ -32,13 +32,7 @@ extension SongsAPI: WMAPI {

public var task: Moya.Task {
switch self {
case let .fetchSearchSong(keyword):
return .requestParameters(parameters: [
"sort": "popular", // 기본 인기순으로
"keyword": keyword
], encoding: URLEncoding.queryString)

case .fetchLyrics:
case .fetchLyrics, .fetchCredits:
return .requestPlain

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

public final class RemoteSongsDataSourceImpl: BaseRemoteDataSource<SongsAPI>, RemoteSongsDataSource {
public func fetchSearchSong(keyword: String) -> Single<SearchResultEntity> {
request(.fetchSearchSong(keyword: keyword))
.map(SearchResultResponseDTO.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> {
request(.fetchCredits(id: id))
.map(SongCreditsResponseDTO.self)
.map { $0.toDomain() }
}

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

public func fetchSearchSong(keyword: String) -> Single<SearchResultEntity> {
remoteSongsDataSource.fetchSearchSong(keyword: keyword)
}

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

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

public func fetchNewSongs(type: NewSongGroupType, page: Int, limit: Int) -> Single<[NewSongsEntity]> {
remoteSongsDataSource.fetchNewSongs(type: type, page: page, limit: limit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ import Foundation
import SongsDomainInterface

public struct LyricsResponseDTO: Decodable {
public let identifier, text, styles: String
public let start, end: Double
let text: String
}

public extension LyricsResponseDTO {
func toDomain() -> LyricsEntity {
LyricsEntity(
identifier: identifier,
start: start,
end: end,
text: text,
styles: styles
)
return LyricsEntity(text: text)
}
}

This file was deleted.

Loading

0 comments on commit 7719a76

Please sign in to comment.