Skip to content

Commit

Permalink
Fix meal
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 7, 2024
1 parent 41dd92b commit 9ff3aed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 5 additions & 11 deletions Graduating-iOS/Data/Network/MealService.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// MealService.swift
// Data
//
// Created by hhhello0507 on 8/28/24.
//

import Foundation
import Combine
import MyMoya
Expand All @@ -13,14 +6,15 @@ import Model
import Shared

public enum MealEndpoint: MyTarget {
case fetchMeals(schoolId: Int)
case fetchMeals
}

extension MealEndpoint {
public var host: String { "meals" }
public var route: Route {
switch self {
case .fetchMeals(let schoolId): .get("\(schoolId)")
case .fetchMeals:
.get()
}
}

Expand All @@ -32,7 +26,7 @@ extension MealEndpoint {
public struct MealService {
public static let shared = Self()

public func fetchMeals(schoolId: Int) -> AnyPublisher<[Meal], APIError> {
runner.deepDive(MealEndpoint.fetchMeals(schoolId: schoolId), res: [Meal].self)
public func fetchMeals() -> AnyPublisher<[Meal], APIError> {
runner.deepDive(MealEndpoint.fetchMeals, res: [Meal].self)
}
}
12 changes: 5 additions & 7 deletions Graduating-iOS/Graduating/Feature/Main/Meal/MealViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ public final class MealViewModel: ObservableObject {

extension MealViewModel {
func fetchMeals(schoolId: Int) {
MealService.shared.fetchMeals(
schoolId: schoolId
)
.resource(\.meals, on: self)
.ignoreError()
.silentSink()
.store(in: &subscriptions)
MealService.shared.fetchMeals()
.resource(\.meals, on: self)
.ignoreError()
.silentSink()
.store(in: &subscriptions)
}
}

0 comments on commit 9ff3aed

Please sign in to comment.