-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Projects/Domains/CreditDomain/Interface/CreditSongOrderType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public enum CreditSongOrderType: String { | ||
case latest | ||
case popular | ||
case oldest | ||
} |
12 changes: 12 additions & 0 deletions
12
Projects/Domains/CreditDomain/Interface/DataSource/RemoteCreditDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import RxSwift | ||
import SongsDomainInterface | ||
|
||
public protocol RemoteCreditDataSource { | ||
func fetchCreditSongList( | ||
name: String, | ||
order: CreditSongOrderType, | ||
page: Int, | ||
limit: Int | ||
) -> Single<[SongEntity]> | ||
} |
12 changes: 12 additions & 0 deletions
12
Projects/Domains/CreditDomain/Interface/Repository/CreditRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import RxSwift | ||
import SongsDomainInterface | ||
|
||
public protocol CreditRepository { | ||
func fetchCreditSongList( | ||
name: String, | ||
order: CreditSongOrderType, | ||
page: Int, | ||
limit: Int | ||
) -> Single<[SongEntity]> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import BaseDomain | ||
import CreditDomainInterface | ||
import ErrorModule | ||
import Foundation | ||
import KeychainModule | ||
import Moya | ||
|
||
public enum CreditAPI { | ||
case fetchCreditSongList( | ||
name: String, | ||
order: CreditSongOrderType, | ||
page: Int, | ||
limit: Int | ||
) | ||
} | ||
|
||
extension CreditAPI: WMAPI { | ||
public var domain: WMDomain { | ||
.credit | ||
} | ||
|
||
public var urlPath: String { | ||
switch self { | ||
case let .fetchCreditSongList(name, _, _, _): | ||
return "/\(name)/songs" | ||
} | ||
} | ||
|
||
public var method: Moya.Method { | ||
switch self { | ||
case .fetchCreditSongList: | ||
return .get | ||
} | ||
} | ||
|
||
public var task: Moya.Task { | ||
switch self { | ||
case let .fetchCreditSongList(name, order, page, limit): | ||
return .requestParameters(parameters: [ | ||
"order": order.rawValue, | ||
"page": page, | ||
"limit": limit | ||
], encoding: URLEncoding.queryString) | ||
} | ||
} | ||
|
||
public var jwtTokenType: JwtTokenType { | ||
switch self { | ||
case .fetchCreditSongList: | ||
return .none | ||
} | ||
} | ||
|
||
public var errorMap: [Int: WMError] { | ||
switch self { | ||
default: | ||
return [ | ||
400: .badRequest, | ||
401: .tokenExpired, | ||
404: .notFound, | ||
429: .tooManyRequest, | ||
500: .internalServerError | ||
] | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Projects/Domains/CreditDomain/Sources/DataSource/RemoteCreditDataSourceImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import BaseDomain | ||
import CreditDomainInterface | ||
import Foundation | ||
import RxSwift | ||
import SongsDomainInterface | ||
|
||
public final class RemoteCreditDataSourceImpl: BaseRemoteDataSource<CreditAPI>, RemoteCreditDataSource { | ||
public func fetchCreditSongList( | ||
name: String, | ||
order: CreditSongOrderType, | ||
page: Int, | ||
limit: Int | ||
) -> Single<[SongEntity]> { | ||
request(.fetchCreditSongList(name: name, order: order, page: page, limit: limit)) | ||
.map([FetchCreditSongListResponseDTO].self) | ||
.map { $0.toDomain() } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Projects/Domains/CreditDomain/Sources/Repository/CreditRepositoryImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import CreditDomainInterface | ||
import ErrorModule | ||
import RxSwift | ||
import SongsDomainInterface | ||
|
||
public final class CreditRepositoryImpl: CreditRepository { | ||
private let remoteCreditDataSource: any RemoteCreditDataSource | ||
|
||
public init( | ||
remoteCreditDataSource: any RemoteCreditDataSource | ||
) { | ||
self.remoteCreditDataSource = remoteCreditDataSource | ||
} | ||
|
||
public func fetchCreditSongList( | ||
name: String, | ||
order: CreditSongOrderType, | ||
page: Int, | ||
limit: Int | ||
) -> Single<[SongEntity]> { | ||
remoteCreditDataSource.fetchCreditSongList(name: name, order: order, page: page, limit: limit) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Projects/Domains/CreditDomain/Sources/ResponseDTO/FetchCreditSongListResponseDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import SongsDomainInterface | ||
import Utility | ||
|
||
struct FetchCreditSongListResponseDTO: Decodable { | ||
let songID, title: String | ||
let artists: [String] | ||
let views, likes: Int | ||
let date: Int | ||
let karaokeNumber: FetchCreditSongListResponseDTO.KaraokeNumber | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case title, artists, date, views, likes | ||
case songID = "videoId" | ||
case karaokeNumber | ||
} | ||
} | ||
|
||
extension FetchCreditSongListResponseDTO { | ||
struct KaraokeNumber: Decodable { | ||
let TJ, KY: Int? | ||
} | ||
} | ||
|
||
extension FetchCreditSongListResponseDTO { | ||
func toDomain() -> SongEntity { | ||
return SongEntity( | ||
id: songID, | ||
title: title, | ||
artist: artists.joined(separator: ", "), | ||
views: views, | ||
date: date.changeDateFormat(origin: "yyMMdd", result: "yyyy.MM.dd"), | ||
likes: likes, | ||
karaokeNumber: .init(TJ: karaokeNumber.TJ, KY: karaokeNumber.KY) | ||
) | ||
} | ||
} | ||
|
||
extension [FetchCreditSongListResponseDTO] { | ||
func toDomain() -> [SongEntity] { | ||
return self.map { $0.toDomain() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters