Network layer: - Replace static CookbookApi protocol with instance-based CookbookApiProtocol using async/throws instead of tuple returns - Refactor ApiRequest to use URLComponents for proper URL encoding, replace print statements with OSLog, and return typed NetworkError cases - Add structured NetworkError variants (httpError, connectionError, etc.) - Remove global cookbookApi constant in favor of injected dependency on AppState - Delete unused RecipeEditViewModel, RecipeScraper, and Scraper playground Data & model fixes: - Add custom Decodable for RecipeDetail with safe fallbacks for malformed JSON - Make Category Hashable/Equatable use only `name` so NavigationSplitView selection survives category refreshes with updated recipe_count - Return server-assigned ID from uploadRecipe so new recipes get their ID before the post-upload refresh block executes View updates: - Refresh both old and new category recipe lists after upload when category changes, mapping empty recipeCategory to "*" for uncategorized recipes - Raise deployment target to iOS 18, adopt new SwiftUI API conventions - Clean up alerts, onboarding views, and settings Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
68 lines
1.0 KiB
Swift
68 lines
1.0 KiB
Swift
//
|
|
// DataModels.swift
|
|
// Nextcloud Cookbook iOS Client
|
|
//
|
|
// Created by Vincent Meilinger on 15.09.23.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
|
|
struct Category: Codable {
|
|
let name: String
|
|
let recipe_count: Int
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case name, recipe_count
|
|
}
|
|
}
|
|
|
|
extension Category: Identifiable, Hashable {
|
|
var id: String { name }
|
|
|
|
static func == (lhs: Category, rhs: Category) -> Bool {
|
|
lhs.name == rhs.name
|
|
}
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(name)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Login flow
|
|
|
|
struct LoginV2Request: Codable {
|
|
let poll: LoginV2Poll
|
|
let login: String
|
|
}
|
|
|
|
struct LoginV2Poll: Codable {
|
|
let token: String
|
|
let endpoint: String
|
|
}
|
|
|
|
struct LoginV2Response: Codable {
|
|
let server: String
|
|
let loginName: String
|
|
let appPassword: String
|
|
}
|
|
|
|
struct LoginValidation: Codable {
|
|
let ocs: Ocs
|
|
}
|
|
|
|
struct Ocs: Codable {
|
|
let meta: MetaData
|
|
}
|
|
|
|
struct MetaData: Codable {
|
|
let status: String
|
|
let statuscode: Int
|
|
}
|
|
|
|
|
|
|