Skip to content

Commit

Permalink
Merge pull request #574 from wakmusic/561-develop-wakmuRecommendList
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: (#561) ์™๋ฎค ์ถ”์ฒœ ํ”Œ๋ ˆ์ด๋ฆฌ์ŠคํŠธ ํ™”๋ฉด์„ ๋งŒ๋“ค์–ด์š”.
  • Loading branch information
yongbeomkwak authored Jun 10, 2024
2 parents a0130f5 + 8ea0ee6 commit fe2272f
Show file tree
Hide file tree
Showing 28 changed files with 506 additions and 418 deletions.
4 changes: 2 additions & 2 deletions Projects/Domains/BaseDomain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ let project = Project.module(
.interface(
module: .domain(.BaseDomain),
dependencies: [
.Project.Module.ThirdPartyLib
.Project.Module.ThirdPartyLib,
.Project.Module.ErrorModule,
]
),
.implements(
module: .domain(.BaseDomain),
dependencies: [
.Project.Module.Utility,
.Project.Module.ErrorModule,
.Project.Module.KeychainModule,
.domain(target: .BaseDomain, type: .interface)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public protocol RemotePlayListDataSource {
func fetchPlaylistSongs(id: String) -> Single<[SongEntity]>
func updatePlaylist(key: String, songs: [String]) -> Completable
func addSongIntoPlayList(key: String, songs: [String]) -> Single<AddSongEntity>
func removeSongs(key: String, songs: [String]) -> Single<BaseEntity>
func removeSongs(key: String, songs: [String]) -> Completable
func uploadImage(key: String, model: UploadImageType) -> Single<BaseImageEntity>
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
//
// AddSongEntity.swift
// DomainModule
//
// Created by yongbeomkwak on 2023/03/14.
// Copyright ยฉ 2023 yongbeomkwak. All rights reserved.
//

import Foundation

public struct AddSongEntity: Equatable {
public init(
added_songs_length: Int,
addedSongCount: Int,
duplicated: Bool
) {
self.added_songs_length = added_songs_length
self.addedSongCount = addedSongCount
self.duplicated = duplicated
}

public let added_songs_length: Int
public let addedSongCount: Int
public let duplicated: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct RecommendPlayListEntity: Equatable {
public struct RecommendPlayListEntity: Hashable, Equatable {
public init(
key: String,
title: String,
Expand All @@ -26,4 +26,13 @@ public struct RecommendPlayListEntity: Equatable {
public let key, title, image: String
public let `private`: Bool
public let count: Int
private let id = UUID()

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

public static func == (_ lhs: Self, _ rhs: Self) -> Bool {
lhs.id == rhs.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public protocol PlayListRepository {
func fetchPlaylistSongs(id: String) -> Single<[SongEntity]>
func updatePlayList(key: String, songs: [String]) -> Completable
func addSongIntoPlayList(key: String, songs: [String]) -> Single<AddSongEntity>
func removeSongs(key: String, songs: [String]) -> Single<BaseEntity>
func removeSongs(key: String, songs: [String]) -> Completable
func uploadImage(key: String, model: UploadImageType) -> Single<BaseImageEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Foundation
import RxSwift

public protocol RemoveSongsUseCase {
func execute(key: String, songs: [String]) -> Single<BaseEntity>
func execute(key: String, songs: [String]) -> Completable
}
5 changes: 4 additions & 1 deletion Projects/Domains/PlayListDomain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ let project = Project.module(
.tests(
module: .domain(.PlayListDomain),
dependencies: [.domain(target: .PlayListDomain)]
)
),
.testing(module: .domain(.PlayListDomain), dependencies: [
.domain(target: .PlayListDomain, type: .interface)
])
]
)
13 changes: 4 additions & 9 deletions Projects/Domains/PlayListDomain/Sources/API/PlayListAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ extension PlayListAPI: WMAPI {
return "/create"

case let .fetchPlaylistSongs(key: key), let .addSongIntoPlayList(key: key, _), let .updatePlaylist(key: key, _),
let .removeSongs(
key: key,
_
):
let .removeSongs(key: key, _):
return "/\(key)/songs"

case let .uploadImage(key: key, _):
Expand Down Expand Up @@ -117,19 +114,17 @@ extension PlayListAPI: WMAPI {
switch model {
case let .default(imageName: data):
datas.append(MultipartFormData(
provider: .data("default".data(using: .utf8)!),
name: "type",
fileName: "ใ……"
provider: .data("default".data(using: .utf8)!), name: "type"
))

datas.append(MultipartFormData(provider: .data(data.data(using: .utf8)!), name: "imageName"))

case let .custom(imageName: data):
datas.append(MultipartFormData(provider: .data("custom".data(using: .utf8)!), name: "type"))
datas.append(MultipartFormData(
provider: .data(data),
name: "imageFile",
fileName: "image.jpeg",
mimeType: "image/jpeg, image/jpg, image/png"
fileName: "image.jpeg"
))
}
return .uploadMultipart(datas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ public final class RemotePlayListDataSourceImpl: BaseRemoteDataSource<PlayListAP
.map { $0.toDomain() }
}

public func removeSongs(key: String, songs: [String]) -> Single<BaseEntity> {
public func removeSongs(key: String, songs: [String]) -> Completable {
request(.removeSongs(key: key, songs: songs))
.map(BaseResponseDTO.self)
.map { $0.toDomain() }
.asCompletable()
}

public func uploadImage(key: String, model: UploadImageType) -> Single<BaseImageEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class PlayListRepositoryImpl: PlayListRepository {
remotePlayListDataSource.addSongIntoPlayList(key: key, songs: songs)
}

public func removeSongs(key: String, songs: [String]) -> RxSwift.Single<BaseEntity> {
public func removeSongs(key: String, songs: [String]) -> Completable {
remotePlayListDataSource.removeSongs(key: key, songs: songs)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct AddSongResponseDTO: Decodable {
public extension AddSongResponseDTO {
func toDomain() -> AddSongEntity {
AddSongEntity(
added_songs_length: addedSongCount,
addedSongCount: addedSongCount,
duplicated: isDuplicatedSongsExist
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct RemoveSongsUseCaseImpl: RemoveSongsUseCase {
self.playListRepository = playListRepository
}

public func execute(key: String, songs: [String]) -> Single<BaseEntity> {
public func execute(key: String, songs: [String]) -> Completable {
return playListRepository.removeSongs(key: key, songs: songs)
}
}
141 changes: 141 additions & 0 deletions Projects/Domains/PlayListDomain/Testing/FetchPlayListUseCaseStub.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import PlayListDomainInterface
import RxSwift

final class FetchPlayListUseCaseStub: FetchRecommendPlayListUseCase {
var fetchData = [
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "best",
title: "๋ฒ ์ŠคํŠธ",
image: "https://cdn.wakmusic.xyz/playlist/best_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "carol",
title: "์บ๋กค",
image: "https://cdn.wakmusic.xyz/playlist/carol_1.png",
private: false,
count: 0
),
RecommendPlayListEntity(
key: "competition",
title: "๊ฒฝ์Ÿ",
image: "https://cdn.wakmusic.xyz/playlist/competition_1.png",
private: false,
count: 0
)
]

func execute() -> Single<[RecommendPlayListEntity]> {
return Single.create { [fetchData] single in

single(.success(fetchData))
return Disposables.create()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public final class ContainSongsViewModel: ViewModelType {
if entity.duplicated {
return BaseEntity(
status: 200,
description: "\(entity.added_songs_length)๊ณก์ด ๋‚ด ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ฒผ์Šต๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ณก์€ ์ œ์™ธ๋ฉ๋‹ˆ๋‹ค."
description: "\(entity.addedSongCount)๊ณก์ด ๋‚ด ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ฒผ์Šต๋‹ˆ๋‹ค. ์ค‘๋ณต ๊ณก์€ ์ œ์™ธ๋ฉ๋‹ˆ๋‹ค."
)
} else {
return BaseEntity(status: 200, description: "\(entity.added_songs_length)๊ณก์ด ๋‚ด ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ฒผ์Šต๋‹ˆ๋‹ค.")
return BaseEntity(status: 200, description: "\(entity.addedSongCount)๊ณก์ด ๋‚ด ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ฒผ์Šต๋‹ˆ๋‹ค.")
}
}
.bind(to: output.showToastMessage)
Expand Down
Loading

0 comments on commit fe2272f

Please sign in to comment.