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

♻️ 마이페이지 리스트뷰 리펙토링 #295

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
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
314 changes: 257 additions & 57 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 @@ -8,7 +8,17 @@
import Foundation
import RxDataSources

struct MyMusic {
struct TotalMyMusics {
let musics: [MyMusics]
let totalCount: Int
}

struct MyMusics {
let date: String
let musics: [MyMusic]
}

struct MyMusic: Hashable {
let id: Int
let userId: Int
var userName: String
Expand All @@ -22,33 +32,33 @@ struct MyMusic {
let createdAt: String
let location: String
let likeCount: Int
}

struct MyMusics {
let date: String
let musics: [MyMusic]
}

struct TotalMyMusics {
let musics: [MyMusics]
let totalCount: Int
}

struct MyMusicsSection {
var date: String
var items: [Item]

init(date: String, items: [MyMusic]) {
self.date = date
self.items = items
private let identifier = UUID()

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

static func == (lhs: MyMusic, rhs: MyMusic) -> Bool {
return lhs.identifier == rhs.identifier
}
}

extension MyMusicsSection: SectionModelType {
typealias Item = MyMusic
struct MyMusicsSectionType: Hashable {
let section: MyMusicsSection
let items: [MyMusic]

init(original: MyMusicsSection, items: [MyMusic]) {
self = original
self.items = items
private let identifier = UUID()

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

static func == (lhs: MyMusicsSectionType, rhs: MyMusicsSectionType) -> Bool {
return lhs.identifier == rhs.identifier
}
}

enum MyMusicsSection: Hashable {
case musics(date: String)
}
53 changes: 0 additions & 53 deletions StreetDrop/StreetDrop/Presentation/MyPage/Model/MyPageModel.swift

This file was deleted.

Loading