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

merge :: 급식 없는 날 처리 #154

Merged
merged 1 commit into from
Dec 27, 2022
Merged
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
4 changes: 4 additions & 0 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion Projects/Features/HomeFeature/Sources/HomeComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import SwiftUI

public protocol HomeDependency: Dependency {
var fetchMealListUseCase: any FetchMealListUseCase { get }
var fetchWhetherNewNoticeUseCase: any FetchWhetherNewNoticeUseCase { get }
}

public final class HomeComponent: Component<HomeDependency> {
public func makeView() -> some View {
NavigationView {
HomeView(
viewModel: .init(
fetchMealListUseCase: dependency.fetchMealListUseCase
fetchMealListUseCase: dependency.fetchMealListUseCase,
fetchWhetherNewNoticeUseCase: dependency.fetchWhetherNewNoticeUseCase
)
)
}
Expand Down
4 changes: 4 additions & 0 deletions Projects/Features/HomeFeature/Sources/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions Projects/Features/HomeFeature/Sources/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions Projects/Modules/Utility/Sources/DateUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion Projects/Services/APIKit/Sources/NoticeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down