SwiftUI + SwiftData + iCloud, Apple Speech transcription (German), audio recording, summarization service protocol (LLM-ready), localization scaffolding (EN/DE/ES/FR), basic tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
41 lines
978 B
Swift
41 lines
978 B
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
@Observable
|
|
@MainActor
|
|
final class DiaryViewModel {
|
|
var error: Error?
|
|
|
|
private let summarizationService = SummarizationService()
|
|
|
|
var isSummarizing: Bool {
|
|
summarizationService.isSummarizing
|
|
}
|
|
|
|
func generateSummary(for entry: DiaryEntry) async {
|
|
do {
|
|
let summary = try await summarizationService.generateSummary(for: entry)
|
|
entry.summary = summary
|
|
entry.isSummaryGenerated = true
|
|
entry.updatedAt = .now
|
|
} catch {
|
|
self.error = error
|
|
}
|
|
}
|
|
|
|
func deleteEntry(_ entry: DiaryEntry, context: ModelContext) {
|
|
// Delete audio files
|
|
for memo in entry.memos {
|
|
try? FileManager.default.removeItem(at: memo.audioURL)
|
|
}
|
|
context.delete(entry)
|
|
}
|
|
|
|
func deleteMemo(_ memo: VoiceMemo, from entry: DiaryEntry, context: ModelContext) {
|
|
try? FileManager.default.removeItem(at: memo.audioURL)
|
|
entry.memos.removeAll { $0.persistentModelID == memo.persistentModelID }
|
|
context.delete(memo)
|
|
entry.updatedAt = .now
|
|
}
|
|
}
|