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

πŸ”€ :: (#812) CreditDomain κ΅¬ν˜„ #907

Merged
merged 1 commit into from
Jul 30, 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
16 changes: 15 additions & 1 deletion Projects/App/Sources/Application/AppComponent+Credit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ import SongCreditFeature
import SongCreditFeatureInterface

public extension AppComponent {
var remoteCreditDataSource: any RemoteCreditDataSource {
shared {
RemoteCreditDataSourceImpl(keychain: keychain)
}
}

var creditRepository: any CreditRepository {
shared {
CreditRepositoryImpl(remoteCreditDataSource: remoteCreditDataSource)
}
}

var fetchCreditSongListUseCase: any FetchCreditSongListUseCase {
FetchCreditSongListUseCaseImpl()
shared {
FetchCreditSongListUseCaseImpl(creditRepository: creditRepository)
}
}

var songCreditFactory: any SongCreditFactory {
Expand Down
4 changes: 4 additions & 0 deletions Projects/Domains/BaseDomain/Sources/WMAPI/SecretURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ public func WMDOMAIN_TEAM() -> String {
public func WMDOMAIN_PRICE() -> String {
return config(key: "WMDOMAIN_PRICE")
}

public func WMDOMAIN_CREDIT() -> String {
return config(key: "WMDOMAIN_CREDIT")
}
3 changes: 3 additions & 0 deletions Projects/Domains/BaseDomain/Sources/WMAPI/WMAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum WMDomain: String {
case notification
case team
case price
case credit
}

extension WMDomain {
Expand Down Expand Up @@ -100,6 +101,8 @@ extension WMDomain {
return WMDOMAIN_TEAM()
case .price:
return WMDOMAIN_PRICE()
case .credit:
return WMDOMAIN_CREDIT()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public enum CreditSongOrderType: String {
case latest
case popular
case oldest
}
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]>
}
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]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import Foundation
import RxSwift
import SongsDomainInterface

public enum CreditSongOrderType: String {
case latest
case popular
case oldest
}

public protocol FetchCreditSongListUseCase {
func execute(
name: String,
Expand Down
66 changes: 66 additions & 0 deletions Projects/Domains/CreditDomain/Sources/API/CreditAPI.swift
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
]
}
}
}
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() }
}
}
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)
}
}
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() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import RxSwift
import SongsDomainInterface

public final class FetchCreditSongListUseCaseImpl: FetchCreditSongListUseCase {
public init() {}
private let creditRepository: any CreditRepository

public init(
creditRepository: any CreditRepository
) {
self.creditRepository = creditRepository
}

public func execute(
name: String,
order: CreditSongOrderType,
page: Int,
limit: Int
) -> Single<[SongEntity]> {
#warning("κ΅¬ν˜„")
return .never()
creditRepository.fetchCreditSongList(name: name, order: order, page: page, limit: limit)
}
}
Loading