Skip to content

Commit

Permalink
♻️ :: 좋아요 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
yongbeomkwak committed Dec 9, 2023
1 parent 94b09e6 commit c93b588
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extension PlayerViewModel {
return
}
fetchFavoriteSongsUseCase.execute()
.debug("WWW")
.catchAndReturn([])
.map { $0.contains { $0.song.id == song.id } }
.subscribe(onSuccess: { isLiked in
Expand Down
8 changes: 5 additions & 3 deletions Projects/Services/APIKit/Sources/API/LikeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ extension LikeAPI: WMAPI {
case .fetchLikeNumOfSong(id: let id):
return "/\(id)"
case .addLikeSong(id: let id):
return "/\(id)/addLike"
return "/\(id)"
case .cancelLikeSong(id: let id):
return "/\(id)/removeLike"
return "/\(id)"
}
}

public var method: Moya.Method {
switch self {
case .fetchLikeNumOfSong:
return .get
case .addLikeSong,.cancelLikeSong:
case .addLikeSong:
return .post
case .cancelLikeSong:
return .delete
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FetchLikeResponseDTO.swift
// DataMappingModule
//
// Created by yongbeomkwak on 12/9/23.
// Copyright © 2023 yongbeomkwak. All rights reserved.
//

import Foundation

public struct FetchLikeResponseDTO: Codable {
public let songId: String
public let like: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct LikeRepositoryImpl: LikeRepository {
self.remoteLikeDataSource = remoteLikeDataSource
}

public func fetchLikeNumOfSong(id: String) -> Single<FavoriteSongEntity> {
public func fetchLikeNumOfSong(id: String) -> Single<LikeEntity> {
remoteLikeDataSource.fetchLikeNumOfSong(id: id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct FetchLikeNumOfSongUseCaseImpl: FetchLikeNumOfSongUseCase {
self.likeRepository = likeRepository
}

public func execute(id: String) -> Single<FavoriteSongEntity> {
public func execute(id: String) -> Single<LikeEntity> {
likeRepository.fetchLikeNumOfSong(id: id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DataMappingModule
import ErrorModule

public protocol LikeRepository {
func fetchLikeNumOfSong(id:String) -> Single<FavoriteSongEntity>
func fetchLikeNumOfSong(id:String) -> Single<LikeEntity>
func addLikeSong(id:String) -> Single<LikeEntity>
func cancelLikeSong(id:String) -> Single<LikeEntity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import RxSwift
import DataMappingModule

public protocol FetchLikeNumOfSongUseCase {
func execute(id:String) -> Single<FavoriteSongEntity>
func execute(id:String) -> Single<LikeEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ public extension LikeResponseDTO {
)
}
}

public extension FetchLikeResponseDTO {
func toDomain() -> LikeEntity {
LikeEntity(status: 200, likes: like)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ErrorModule
import DomainModule

public protocol RemoteLikeDataSource {
func fetchLikeNumOfSong(id:String) -> Single<FavoriteSongEntity>
func fetchLikeNumOfSong(id:String) -> Single<LikeEntity>
func addLikeSong(id:String) -> Single<LikeEntity>
func cancelLikeSong(id:String) -> Single<LikeEntity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Foundation

public final class RemoteLikeDataSourceImpl: BaseRemoteDataSource<LikeAPI>, RemoteLikeDataSource {

public func fetchLikeNumOfSong(id: String) -> Single<FavoriteSongEntity> {
public func fetchLikeNumOfSong(id: String) -> Single<LikeEntity> {
request(.fetchLikeNumOfSong(id: id))
.map(FavoriteSongsResponseDTO.self)
.map(FetchLikeResponseDTO.self)
.map({$0.toDomain()})
}

Expand Down

0 comments on commit c93b588

Please sign in to comment.