Skip to content

Commit

Permalink
πŸ›#298: λ“œλžμœ λ„λ¬Έκ΅¬ 둜직 μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
wendoei committed Dec 14, 2024
1 parent f47fcb4 commit 5e7c2e2
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 48 deletions.
8 changes: 8 additions & 0 deletions StreetDrop/StreetDrop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
F4AA84DD2C1F10FF00CADB1A /* NoticeDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA84DC2C1F10FF00CADB1A /* NoticeDetailViewModel.swift */; };
F4AA84DF2C1F3B0200CADB1A /* Array+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA84DE2C1F3B0200CADB1A /* Array+Extension.swift */; };
F4AA84E12C1F732800CADB1A /* DateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA84E02C1F732800CADB1A /* DateManager.swift */; };
F4AEE56A2D0E169100B65191 /* DefaultFetchingSearchPlaceholderUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AEE5692D0E140C00B65191 /* DefaultFetchingSearchPlaceholderUseCase.swift */; };
F4AEE56C2D0E1C7200B65191 /* FetchingSearchPlaceholderUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AEE56B2D0E1C6600B65191 /* FetchingSearchPlaceholderUseCase.swift */; };
F4BDF78F2C1DC57500CC6EE6 /* SettingHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4BDF78E2C1DC57500CC6EE6 /* SettingHeaderView.swift */; };
F4C996A12C1E15CD00FF7B9A /* NoticeListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4C996A02C1E15CC00FF7B9A /* NoticeListViewController.swift */; };
F4C996A32C1E1B3400FF7B9A /* NoticeListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4C996A22C1E1B3400FF7B9A /* NoticeListCell.swift */; };
Expand Down Expand Up @@ -537,6 +539,8 @@
F4AA84DC2C1F10FF00CADB1A /* NoticeDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeDetailViewModel.swift; sourceTree = "<group>"; };
F4AA84DE2C1F3B0200CADB1A /* Array+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Extension.swift"; sourceTree = "<group>"; };
F4AA84E02C1F732800CADB1A /* DateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateManager.swift; sourceTree = "<group>"; };
F4AEE5692D0E140C00B65191 /* DefaultFetchingSearchPlaceholderUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultFetchingSearchPlaceholderUseCase.swift; sourceTree = "<group>"; };
F4AEE56B2D0E1C6600B65191 /* FetchingSearchPlaceholderUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchingSearchPlaceholderUseCase.swift; sourceTree = "<group>"; };
F4BDF78E2C1DC57500CC6EE6 /* SettingHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingHeaderView.swift; sourceTree = "<group>"; };
F4C996A02C1E15CC00FF7B9A /* NoticeListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeListViewController.swift; sourceTree = "<group>"; };
F4C996A22C1E1B3400FF7B9A /* NoticeListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeListCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -824,6 +828,8 @@
082F171D2AB7465A00174D98 /* UseCase */ = {
isa = PBXGroup;
children = (
F4AEE56B2D0E1C6600B65191 /* FetchingSearchPlaceholderUseCase.swift */,
F4AEE5692D0E140C00B65191 /* DefaultFetchingSearchPlaceholderUseCase.swift */,
082F17192AB7454200174D98 /* EditCommentUseCase.swift */,
082F171B2AB7455400174D98 /* DefaultEditCommentUseCase.swift */,
C419722D2ABD9D6F00211222 /* MyInfoUseCase.swift */,
Expand Down Expand Up @@ -1863,6 +1869,7 @@
C41972512ABED0FE00211222 /* MyInfoRepository.swift in Sources */,
C41972382ABDB49400211222 /* FetchingMusicCountUseCase.swift in Sources */,
41396D872A4EFA2900B69341 /* MyInfoResponseDTO.swift in Sources */,
F4AEE56A2D0E169100B65191 /* DefaultFetchingSearchPlaceholderUseCase.swift in Sources */,
412D668C2A1E173A00BA4A1B /* AlbumCollectionViewCell.swift in Sources */,
6A3AFB582B8DB399003BD144 /* GADUnitID.swift in Sources */,
41396DA92A51B8F700B69341 /* EditInfo.swift in Sources */,
Expand Down Expand Up @@ -1979,6 +1986,7 @@
414345252A35B9C3003FEE2A /* DefaultLikeMusicRepository.swift in Sources */,
1816ED412A685704005009FC /* NicknameEditViewModel.swift in Sources */,
6A26BF322B33D1E40007B6B7 /* FetchingSingleMusicUseCase.swift in Sources */,
F4AEE56C2D0E1C7200B65191 /* FetchingSearchPlaceholderUseCase.swift in Sources */,
04FB1F262A0215BC0064B3C8 /* MainViewModel.swift in Sources */,
18D671EF2A35A1CB003B1A71 /* MusicWithinAreaResponseDTO.swift in Sources */,
41BCFD452A38C099001D3E5F /* Alertable.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ protocol MyInfoStorage {
func saveLauchedBefore(_ launchedBefore: Bool)
func fetchLastSeenNoticeId() -> Int?
func saveLastSeenNoticeId(_ noticeId: Int)
func fetchLastLaunchDate() -> Date?
func saveLastLaunchDate(_ lastLaunchDate: Date)
func savePromptOfTheDay(_ prompt: String)
func fetchPromptOfTheDay() -> String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ extension UserDefaultsMyInfoStorage: MyInfoStorage {
func saveLastSeenNoticeId(_ noticeId: Int) {
userDefaults.set(noticeId, forKey: UserDefaultKey.lastSeenNoticeId)
}
func fetchLastLaunchDate() -> Date? {
userDefaults.object(forKey: UserDefaultKey.lastLaunchDate) as? Date

func savePromptOfTheDay(_ prompt: String) {
userDefaults.set(prompt, forKey: UserDefaultKey.promptOfTheDay)
}
func saveLastLaunchDate(_ lastLaunchDate: Date) {
userDefaults.set(lastLaunchDate, forKey: UserDefaultKey.lastLaunchDate)

func fetchPromptOfTheDay() -> String? {
userDefaults.string(forKey: UserDefaultKey.promptOfTheDay)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ final class DefaultMyInfoRepository: MyInfoRepository {
return Double(dto.distance)
}
}

func checkFirstLaunchToday() -> Bool {
let lastLaunchDate = myInfoStorage.fetchLastLaunchDate()
myInfoStorage.saveLastLaunchDate(Date())

if let lastLaunchDate {
return !Calendar.current.isDateInToday(lastLaunchDate)
} else {
return true
}

func savePromptOfTheDay(_ prompt: String) {
myInfoStorage.savePromptOfTheDay(prompt)
}

func fetchPromptOfTheDay() -> String? {
myInfoStorage.fetchPromptOfTheDay()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ protocol MyInfoRepository {
func fetchMyMusicAppFromStorage() -> String?
func checkLaunchedBefore() -> Bool
func fetchUserCircleRadius() -> Single<Double>
func checkFirstLaunchToday() -> Bool
func savePromptOfTheDay(_ prompt: String)
func fetchPromptOfTheDay() -> String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DefaultFetchingSearchPlaceholderUseCase.swift
// StreetDrop
//
// Created by jihye kim on 14/12/2024.
//

import Foundation

import RxSwift

final class DefaultFetchingSearchPlaceholderUseCase: FetchingSearchPlaceholderUseCase {
private let myInfoRepository: MyInfoRepository

init(
myInfoRepository: MyInfoRepository = DefaultMyInfoRepository(
networkManager: .init(),
myInfoStorage: UserDefaultsMyInfoStorage()
)
) {
self.myInfoRepository = myInfoRepository
}

func fetchPromptOfTheDay() -> String? {
myInfoRepository.fetchPromptOfTheDay()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ final class DefaultMyInfoUseCase: MyInfoUseCase {
func checkLaunchedBefore() -> Bool {
return myInfoRepository.checkLaunchedBefore()
}
func checkFirstLaunchToday() -> Bool {
return myInfoRepository.checkFirstLaunchToday()

func savePromptOfTheDay(_ prompt: String) {
myInfoRepository.savePromptOfTheDay(prompt)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// FetchingSearchPlaceholderUseCase.swift
// StreetDrop
//
// Created by jihye kim on 14/12/2024.
//

import Foundation

protocol FetchingSearchPlaceholderUseCase {
func fetchPromptOfTheDay() -> String?
}
2 changes: 1 addition & 1 deletion StreetDrop/StreetDrop/Domain/UseCase/MyInfoUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ protocol MyInfoUseCase {
func fetchMyInfo() -> Single<MyInfo>
func saveMyInfo(_ myInfo: MyInfo) -> Single<Void>
func checkLaunchedBefore() -> Bool
func checkFirstLaunchToday() -> Bool
func savePromptOfTheDay(_ prompt: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ private extension MainViewController {
self.presentDial(currentIndex: currentIndex)
}
.disposed(by: disposeBag)

output.showFirstComment
.bind(with: self) { owner, prompt in
owner.bubbleCommentView.isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,15 @@ private extension MainViewModel {
switch result {
case .success(let prompt):
guard let prompt else { return }
self?.showPromptIfFirstLaunchedToday(prompt: prompt, output: output)
self?.myInfoUseCase.savePromptOfTheDay(prompt)
self?.output.showFirstComment.accept(prompt)
case .failure(let error):
print(error)
}
}
.disposed(by: disposedBag)
}

func showPromptIfFirstLaunchedToday(prompt: String, output: Output) {
let isFirstLaunchToday = myInfoUseCase.checkFirstLaunchToday()
if isFirstLaunchToday {
output.showFirstComment.accept(prompt)
}
}

func checkUniversialLinkRemained(output: Output) {
let itemID = UserDefaults.standard.integer(forKey: UserDefaultKey.sharedMusicItemID)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol SearchingMusicViewModel: ViewModel {
final class DefaultSearchingMusicViewModel: SearchingMusicViewModel {
private let model: SearchMusicUsecase
private let recommendMusicUseCase: RecommendMusicUsecase
private let searchPlaceholderUseCase: FetchingSearchPlaceholderUseCase
let location: CLLocation
var address: String = ""
private let disposeBag: DisposeBag = DisposeBag()
Expand Down Expand Up @@ -48,10 +49,12 @@ final class DefaultSearchingMusicViewModel: SearchingMusicViewModel {
init(
model: SearchMusicUsecase = DefaultSearchingMusicUsecase(),
recommendMusicUseCase: RecommendMusicUsecase = DefaultRecommendMusicUsecase(),
searchPlaceholderUseCase: FetchingSearchPlaceholderUseCase = DefaultFetchingSearchPlaceholderUseCase(),
location: CLLocation
) {
self.model = model
self.recommendMusicUseCase = recommendMusicUseCase
self.searchPlaceholderUseCase = searchPlaceholderUseCase
self.location = location
}

Expand All @@ -60,7 +63,8 @@ final class DefaultSearchingMusicViewModel: SearchingMusicViewModel {

input.viewDidLoadEvent
.subscribe(onNext: { [weak self] in
self?.model.getRecentSearches()
guard let self else { return }
self.model.getRecentSearches()
.subscribe { result in
switch result {
case .success(let queries):
Expand All @@ -70,24 +74,19 @@ final class DefaultSearchingMusicViewModel: SearchingMusicViewModel {
}
}
.disposed(by: disposedBag)
self?.fetchCurrentLocationVillageName()
self?.recommendMusicUseCase.getPromptOfTheDay()
.subscribe { [weak self] result in
guard let self else { return }
switch result {
case .success(let prompt):
output.promptOfTheDay.accept(prompt ?? self.defaultPrompt)
case .failure(_):
output.promptOfTheDay.accept(self.defaultPrompt)
}
}
.disposed(by: disposedBag)
self?.recommendMusicUseCase.getRecommendSections()
self.fetchCurrentLocationVillageName()

let prompt = self.searchPlaceholderUseCase.fetchPromptOfTheDay()
output.promptOfTheDay.accept(prompt ?? self.defaultPrompt)

self.recommendMusicUseCase.getRecommendSections()
.subscribe { result in
switch result {
case .success(let recommendSections):
output.recommendSections.accept(recommendSections)
output.recommendSectionModels.accept(recommendSections.compactMap { $0.sectionModel })
output.recommendSectionModels.accept(
recommendSections.compactMap { $0.sectionModel }
)
case .failure(_):
output.recommendSections.accept([])
output.recommendSectionModels.accept([])
Expand Down
2 changes: 1 addition & 1 deletion StreetDrop/StreetDrop/Util/Constant/UserDefaultKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ enum UserDefaultKey {
static let launchedBefore = "launchedBefore"
static let sharedMusicItemID = "sharedMusicItemID"
static let lastSeenNoticeId = "lastSeenNoticeId"
static let lastLaunchDate = "lastLaunchDate"
static let promptOfTheDay = "promptOfTheDay"
}

0 comments on commit 5e7c2e2

Please sign in to comment.