Skip to content

Commit

Permalink
♻️#294: 마이페이지 UseCase 리펙토링 및 기존 UseCase 네이밍 및 파일구조 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
thoonk committed Jul 16, 2024
1 parent 556ed14 commit 60cb964
Show file tree
Hide file tree
Showing 46 changed files with 381 additions and 70 deletions.
290 changes: 241 additions & 49 deletions StreetDrop/StreetDrop.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DefaultMusicDropUseCase.swift
// DefaultDropMusicUseCase.swift
// StreetDrop
//
// Created by thoonk on 2023/09/17.
Expand All @@ -9,7 +9,7 @@ import Foundation

import RxSwift

final class DefaultMusicDropUseCase: MusicDropUseCase {
final class DefaultDropMusicUseCase: DropMusicUseCase {
private let dropMusicRepository: DropMusicRepository

init(dropMusicRepository: DropMusicRepository = DefaultDropMusicRepository()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MusicDropUseCase.swift
// DropMusicUseCase.swift
// StreetDrop
//
// Created by thoonk on 2023/09/17.
Expand All @@ -9,6 +9,6 @@ import Foundation

import RxSwift

protocol MusicDropUseCase {
protocol DropMusicUseCase {
func drop(droppingInfo: DroppingInfo, content: String) -> Single<Int>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DefaultFetchingMusicWithinArea.swift
// DefaultFetchingMusicWithinAreaUseCase.swift
// StreetDrop
//
// Created by 차요셉 on 2023/09/22.
Expand All @@ -9,7 +9,7 @@ import Foundation

import RxSwift

final class DefaultFetchingMusicWithinArea: FetchingMusicWithinArea {
final class DefaultFetchingMusicWithinAreaUseCase: FetchingMusicWithinAreaUseCase {
private let mainRepository: MainRepository

init(mainRepository: MainRepository = DefaultMainRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import Foundation

import RxSwift

protocol FetchingMusicWithinArea {
protocol FetchingMusicWithinAreaUseCase {
func execute(lat: Double, lon: Double, distance: Double) -> Single<Musics>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// DefaultFetchingMyDropListUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

final class DefaultFetchingMyDropListUseCase {
private let repository: MyPageRepository

init(repository: MyPageRepository = DefaultMyPageRepository()) {
self.repository = repository
}
}

extension DefaultFetchingMyDropListUseCase: FetchingMyDropListUseCase {
func fetchMyDropList() -> Single<TotalMyMusics> {
return repository.fetchMyDropList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FetchingMyDropListUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

protocol FetchingMyDropListUseCase {
func fetchMyDropList() -> Single<TotalMyMusics>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// DefaultFetchingMyLevelUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

final class DefaultFetchingMyLevelUseCase {
private let repository: MyPageRepository

init(repository: MyPageRepository = DefaultMyPageRepository()) {
self.repository = repository
}
}

extension DefaultFetchingMyLevelUseCase: FetchingMyLevelUseCase {
func fetchMyLevel() -> Single<MyLevel> {
return repository.fetchMyLevel()
}

func fetchMyLevelProgress() -> Single<MyLevelProgress> {
return repository.fetchMyLevelProgress()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// FetchingMyLevelUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

protocol FetchingMyLevelUseCase {
func fetchMyLevel() -> Single<MyLevel>
func fetchMyLevelProgress() -> Single<MyLevelProgress>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// DefaultFetchingMyLikeListUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

final class DefaultFetchingMyLikeListUseCase {
private let repository: MyPageRepository

init(repository: MyPageRepository = DefaultMyPageRepository()) {
self.repository = repository
}
}

extension DefaultFetchingMyLikeListUseCase: FetchingMyLikeListUseCase {
func fetchMyLikeList() -> Single<TotalMyMusics> {
return repository.fetchMyLikeList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FetchingMyLikeListUseCase.swift
// StreetDrop
//
// Created by thoonk on 7/16/24.
//

import Foundation

import RxSwift

protocol FetchingMyLikeListUseCase {
func fetchMyLikeList() -> Single<TotalMyMusics>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Foundation

import RxSwift

protocol NoticeUseCase {
protocol FetchingNoticeUseCase {
func fetchNoticeList() -> Single<[NoticeEntity]>
func fetchNoticeDetail(id: Int) -> Single<NoticeDetailEntity>
}

final class DefaultNoticeUseCase: NoticeUseCase {
final class DefaultFetchingNoticeUseCase: FetchingNoticeUseCase {
private let noticeRepository: NoticeRepository

init(noticeRepository: NoticeRepository = DefaultNoticeRepository()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class MainViewModel: ViewModel {
private let myInfoUseCase: MyInfoUseCase
private let fetchingPOIUseCase: FetchingPOIUseCase
private let fetchingMusicCountUseCse: FetchingMusicCountUseCase
private let fetchingMusicWithinArea: FetchingMusicWithinArea
private let fetchingMusicWithinAreaUseCase: FetchingMusicWithinAreaUseCase
private let fetchingPopUpInfomationUseCase: FetchingPopUpInfomationUseCase
private let postingPopUpUserReadingUseCase: PostingPopUpUserReadingUseCase

Expand All @@ -43,7 +43,7 @@ final class MainViewModel: ViewModel {
myInfoUseCase: MyInfoUseCase = DefaultMyInfoUseCase(),
fetchingPOIUseCase: FetchingPOIUseCase = DefaultFetchingPOIUseCase(),
fetchingMusicCountUseCse: FetchingMusicCountUseCase = DefaultFetchingMusicCountUseCase(),
fetchingMusicWithinArea: FetchingMusicWithinArea = DefaultFetchingMusicWithinArea(),
fetchingMusicWithinAreaUseCase: FetchingMusicWithinAreaUseCase = DefaultFetchingMusicWithinAreaUseCase(),
fetchingSingleMusicUseCase: FetchingSingleMusicUseCase = DefaultFetchingSingleMusicUseCase(),
fetchingPopUpInfomationUseCase: FetchingPopUpInfomationUseCase = DefaultFetchingPopUpInfomationUseCase(),
postingPopUpUserReadingUseCase: PostingPopUpUserReadingUseCase = DefaultPostingPopUpUserReadingUseCase()
Expand All @@ -52,7 +52,7 @@ final class MainViewModel: ViewModel {
self.myInfoUseCase = myInfoUseCase
self.fetchingPOIUseCase = fetchingPOIUseCase
self.fetchingMusicCountUseCse = fetchingMusicCountUseCse
self.fetchingMusicWithinArea = fetchingMusicWithinArea
self.fetchingMusicWithinAreaUseCase = fetchingMusicWithinAreaUseCase
self.fetchingPopUpInfomationUseCase = fetchingPopUpInfomationUseCase
self.postingPopUpUserReadingUseCase = postingPopUpUserReadingUseCase
self.locationManager.delegate = self
Expand Down Expand Up @@ -237,7 +237,7 @@ private extension MainViewModel {
}

func fetchMusicWithArea(output: Output, disposedBag: DisposeBag) {
fetchingMusicWithinArea.execute(
fetchingMusicWithinAreaUseCase.execute(
lat: self.location.coordinate.latitude,
lon: self.location.coordinate.longitude,
distance: userCircleRadius
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class MusicDropViewModel: ViewModel {

var state: State = .drop
private let droppingInfo: DroppingInfo
private let musicDropUseCase: MusicDropUseCase
private let dropMusicUseCase: DropMusicUseCase
private let disposeBag: DisposeBag = DisposeBag()

init (
droppingInfo: DroppingInfo,
musicDropUseCase: MusicDropUseCase = DefaultMusicDropUseCase()
dropMusicUseCase: DropMusicUseCase = DefaultDropMusicUseCase()
) {
self.droppingInfo = droppingInfo
self.musicDropUseCase = musicDropUseCase
self.dropMusicUseCase = dropMusicUseCase
}

func convert(input: Input, disposedBag: RxSwift.DisposeBag) -> Output {
Expand Down Expand Up @@ -93,7 +93,7 @@ class MusicDropViewModel: ViewModel {
var comment = ""
input.comment.bind { comment = $0 }.disposed(by: DisposeBag())

self.musicDropUseCase.drop(droppingInfo: self.droppingInfo, content: comment)
self.dropMusicUseCase.drop(droppingInfo: self.droppingInfo, content: comment)
.subscribe(onSuccess: { response in
if !(200...299).contains(response) {
output.isSuccessDrop.accept(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ protocol NoticeDetailViewModel: ViewModel { }

final class DefaultNoticeDetailViewModel: NoticeDetailViewModel {
private let noticeId: Int
private let useCase: NoticeUseCase
private let useCase: FetchingNoticeUseCase
private let dateManager: DateManager

init(
noticeId: Int,
useCase: NoticeUseCase = DefaultNoticeUseCase(),
useCase: FetchingNoticeUseCase = DefaultFetchingNoticeUseCase(),
dateManager: DateManager = DefaultDateManager()
) {
self.noticeId = noticeId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import RxSwift
protocol NoticeListViewModel: ViewModel { }

final class DefaultNoticeListViewModel: NoticeListViewModel {
private let useCase: NoticeUseCase
private let useCase: FetchingNoticeUseCase
private let dateManager: DateManager

init(
useCase: NoticeUseCase = DefaultNoticeUseCase(),
useCase: FetchingNoticeUseCase = DefaultFetchingNoticeUseCase(),
dateManager: DateManager = DefaultDateManager()
) {
self.useCase = useCase
Expand Down

0 comments on commit 60cb964

Please sign in to comment.