diff --git a/Projects/App/Sources/Application/NeedleGenerated.swift b/Projects/App/Sources/Application/NeedleGenerated.swift index a9a794b4..7599d4d7 100644 --- a/Projects/App/Sources/Application/NeedleGenerated.swift +++ b/Projects/App/Sources/Application/NeedleGenerated.swift @@ -324,6 +324,9 @@ private class HomeDependency443c4e1871277bd8432aProvider: HomeDependency { var fetchMealListUseCase: any FetchMealListUseCase { return appComponent.fetchMealListUseCase } + var fetchWhetherNewNoticeUseCase: any FetchWhetherNewNoticeUseCase { + return appComponent.fetchWhetherNewNoticeUseCase + } private let appComponent: AppComponent init(appComponent: AppComponent) { self.appComponent = appComponent @@ -629,6 +632,7 @@ extension SigninComponent: Registration { extension HomeComponent: Registration { public func registerItems() { keyPathToName[\HomeDependency.fetchMealListUseCase] = "fetchMealListUseCase-any FetchMealListUseCase" + keyPathToName[\HomeDependency.fetchWhetherNewNoticeUseCase] = "fetchWhetherNewNoticeUseCase-any FetchWhetherNewNoticeUseCase" } } extension ApplyComponent: Registration { diff --git a/Projects/Features/HomeFeature/Sources/Component/MealCarouselView.swift b/Projects/Features/HomeFeature/Sources/Component/MealCarouselView.swift index 0022d082..cec40597 100644 --- a/Projects/Features/HomeFeature/Sources/Component/MealCarouselView.swift +++ b/Projects/Features/HomeFeature/Sources/Component/MealCarouselView.swift @@ -56,9 +56,9 @@ struct MealCarouselView: View { .dmsFont(.body(.body1), color: .GrayScale.gray6) .frame(maxHeight: .infinity) } else { - ForEach(meal.indices, id: \.self) { index in - if index != meal.count - 1 { - Text(meal[index]) + ForEach(meal, id: \.self) { meal in + if !meal.hasSuffix("Kcal") { + Text(meal) .dmsFont(.body(.body1), color: .GrayScale.gray6) .frame(maxHeight: .infinity) } diff --git a/Projects/Features/HomeFeature/Sources/HomeComponent.swift b/Projects/Features/HomeFeature/Sources/HomeComponent.swift index 47a32386..ecf09584 100644 --- a/Projects/Features/HomeFeature/Sources/HomeComponent.swift +++ b/Projects/Features/HomeFeature/Sources/HomeComponent.swift @@ -4,6 +4,7 @@ import SwiftUI public protocol HomeDependency: Dependency { var fetchMealListUseCase: any FetchMealListUseCase { get } + var fetchWhetherNewNoticeUseCase: any FetchWhetherNewNoticeUseCase { get } } public final class HomeComponent: Component { @@ -11,7 +12,8 @@ public final class HomeComponent: Component { NavigationView { HomeView( viewModel: .init( - fetchMealListUseCase: dependency.fetchMealListUseCase + fetchMealListUseCase: dependency.fetchMealListUseCase, + fetchWhetherNewNoticeUseCase: dependency.fetchWhetherNewNoticeUseCase ) ) } diff --git a/Projects/Features/HomeFeature/Sources/HomeView.swift b/Projects/Features/HomeFeature/Sources/HomeView.swift index 4e333c89..d93e73c7 100644 --- a/Projects/Features/HomeFeature/Sources/HomeView.swift +++ b/Projects/Features/HomeFeature/Sources/HomeView.swift @@ -55,7 +55,11 @@ struct HomeView: View { } } } + .onChange(of: viewModel.selectedDate) { newValue in + viewModel.onChangeSelectedDate() + } .onAppear { + viewModel.onAppear() viewModel.fetchMealList() } .onChange(of: isShowingCalendar) { newValue in diff --git a/Projects/Features/HomeFeature/Sources/HomeViewModel.swift b/Projects/Features/HomeFeature/Sources/HomeViewModel.swift index 28023b5b..4a9bbd89 100644 --- a/Projects/Features/HomeFeature/Sources/HomeViewModel.swift +++ b/Projects/Features/HomeFeature/Sources/HomeViewModel.swift @@ -11,7 +11,7 @@ final class HomeViewModel: BaseViewModel { @Published var meals: [String: MealEntity] = [:] @Published var prevMonth = Date().month var selectedDateString: String { - "\(selectedDate.year)/\(selectedDate.month)/\(selectedDate.day) (\(selectedDate.dayOfWeek()))" + "\(selectedDate.customFormat("yyyy/MM/dd")) (\(selectedDate.dayOfWeek()))" } var selectedDateMeal: MealEntity { meals[selectedDate.toSmallDMSDateString()] ?? .init( @@ -23,21 +23,28 @@ final class HomeViewModel: BaseViewModel { } private let fetchMealListUseCase: any FetchMealListUseCase + private let fetchWhetherNewNoticeUseCase: any FetchWhetherNewNoticeUseCase init( - fetchMealListUseCase: any FetchMealListUseCase + fetchMealListUseCase: any FetchMealListUseCase, + fetchWhetherNewNoticeUseCase: any FetchWhetherNewNoticeUseCase ) { self.fetchMealListUseCase = fetchMealListUseCase + self.fetchWhetherNewNoticeUseCase = fetchWhetherNewNoticeUseCase super.init() + } - addCancellable( - $selectedDate.setFailureType(to: DmsError.self).eraseToAnyPublisher() - ) { [weak self] date in - if self?.prevMonth != date.month { - self?.fetchMealList() - } - self?.prevMonth = date.month + func onAppear() { + addCancellable(fetchWhetherNewNoticeUseCase.execute()) { [weak self] isExistNewNotice in + self?.isExistNewNotice = isExistNewNotice + } + } + + func onChangeSelectedDate() { + if self.prevMonth != selectedDate.month { + self.fetchMealList() } + self.prevMonth = selectedDate.month } func fetchMealList() { diff --git a/Projects/Modules/Utility/Sources/DateUtil.swift b/Projects/Modules/Utility/Sources/DateUtil.swift index 107d4538..e4fe1c56 100644 --- a/Projects/Modules/Utility/Sources/DateUtil.swift +++ b/Projects/Modules/Utility/Sources/DateUtil.swift @@ -63,6 +63,13 @@ public extension Date { formatter.locale = Locale(identifier: "ko_kr") return formatter.string(from: self) } + + func customFormat(_ format: String) -> String { + let formatter = DateFormatter() + formatter.dateFormat = format + formatter.locale = Locale(identifier: "ko_kr") + return formatter.string(from: self) + } } public extension Date { diff --git a/Projects/Services/APIKit/Sources/NoticeAPI.swift b/Projects/Services/APIKit/Sources/NoticeAPI.swift index 1f71c275..ec1cdaa8 100644 --- a/Projects/Services/APIKit/Sources/NoticeAPI.swift +++ b/Projects/Services/APIKit/Sources/NoticeAPI.swift @@ -15,7 +15,10 @@ extension NoticeAPI: DmsAPI { public var urlPath: String { switch self { - case .fetchWhetherNewNotice, .fetchNoticeList: + case .fetchWhetherNewNotice: + return "/status" + + case .fetchNoticeList: return "" case let .fetchDetailNotice(id):