ReadKeep/readeck/Domain/UseCase/SaveSettingsUseCase.swift
Ilyas Hallak 930779169b feat: introduce protocol-based UseCase architecture and mock factory
- Add protocols for all UseCases and implement them in their respective classes
- Add DefaultUseCaseFactory and MockUseCaseFactory for dependency injection
- Implement all mock UseCases with dummy data
- Start migration of view models and views to protocol-based UseCase injection (not all migrated yet)
- Refactor previews and some initializers for easier testing
- Move SectionHeader to Components, update server settings UI text
- Add sample article.html for mock content
2025-07-18 00:46:07 +02:00

55 lines
1.7 KiB
Swift

import Foundation
protocol PSaveSettingsUseCase {
func execute(endpoint: String, username: String, password: String) async throws
func execute(endpoint: String, username: String, password: String, hasFinishedSetup: Bool) async throws
func execute(token: String) async throws
func execute(selectedFontFamily: FontFamily, selectedFontSize: FontSize) async throws
}
class SaveSettingsUseCase: PSaveSettingsUseCase {
private let settingsRepository: PSettingsRepository
init(settingsRepository: PSettingsRepository) {
self.settingsRepository = settingsRepository
}
func execute(endpoint: String, username: String, password: String) async throws {
try await settingsRepository.saveSettings(
.init(
endpoint: endpoint,
username: username,
password: password
)
)
}
func execute(endpoint: String, username: String, password: String, hasFinishedSetup: Bool) async throws {
try await settingsRepository.saveSettings(
.init(
endpoint: endpoint,
username: username,
password: password,
hasFinishedSetup: hasFinishedSetup
)
)
}
func execute(token: String) async throws {
try await settingsRepository.saveSettings(
.init(
token: token
)
)
}
func execute(selectedFontFamily: FontFamily, selectedFontSize: FontSize) async throws {
try await settingsRepository.saveSettings(
.init(
fontFamily: selectedFontFamily,
fontSize: selectedFontSize
)
)
}
}