Skip to content

Commit

Permalink
fetch rss data to augment meal data
Browse files Browse the repository at this point in the history
  • Loading branch information
kiliankoe committed Nov 13, 2024
1 parent c6a33f2 commit 4754ce2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/EmealKit/Mensa/MealFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extension Meal {
func matches(meal: Meal) -> Bool {
return link.contains(String(meal.id))
}

var isSoldOut: Bool {
title.lowercased().contains("ausverkauft")
}
}

public static func rssData(session: URLSession = .shared) async throws -> [RSSMeal] {
Expand Down
12 changes: 11 additions & 1 deletion Sources/EmealKit/Mensa/MensaAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ extension Meal {
let (data, _) = try await session.data(from: URL.Mensa.meals(canteen: canteen, date: date))
let meals = try JSONDecoder().decode([Meal].self, from: data)
Logger.emealKit.debug("Successfully fetched \(meals.count) meals")
return meals

let feedItems = try await Self.rssData()
return meals.map { meal in
var meal = meal
let matchingItem = feedItems.first { $0.matches(meal: meal) }
if let matchingItem {
Logger.emealKit.debug("Found matching feeditem for \(meal.id)")
meal.isSoldOut = matchingItem.isSoldOut
}
return meal
}
} catch (let error) {
Logger.emealKit.error("Failed to fetch meal data: \(String(describing: error))")
throw .other(error)
Expand Down

0 comments on commit 4754ce2

Please sign in to comment.