Skip to content

Commit 4754ce2

Browse files
committed
fetch rss data to augment meal data
1 parent c6a33f2 commit 4754ce2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Sources/EmealKit/Mensa/MealFeed.swift

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ extension Meal {
1313
func matches(meal: Meal) -> Bool {
1414
return link.contains(String(meal.id))
1515
}
16+
17+
var isSoldOut: Bool {
18+
title.lowercased().contains("ausverkauft")
19+
}
1620
}
1721

1822
public static func rssData(session: URLSession = .shared) async throws -> [RSSMeal] {

Sources/EmealKit/Mensa/MensaAPI.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ extension Meal {
3737
let (data, _) = try await session.data(from: URL.Mensa.meals(canteen: canteen, date: date))
3838
let meals = try JSONDecoder().decode([Meal].self, from: data)
3939
Logger.emealKit.debug("Successfully fetched \(meals.count) meals")
40-
return meals
40+
41+
let feedItems = try await Self.rssData()
42+
return meals.map { meal in
43+
var meal = meal
44+
let matchingItem = feedItems.first { $0.matches(meal: meal) }
45+
if let matchingItem {
46+
Logger.emealKit.debug("Found matching feeditem for \(meal.id)")
47+
meal.isSoldOut = matchingItem.isSoldOut
48+
}
49+
return meal
50+
}
4151
} catch (let error) {
4252
Logger.emealKit.error("Failed to fetch meal data: \(String(describing: error))")
4353
throw .other(error)

0 commit comments

Comments
 (0)