feat: full Pulse Mobile implementation - all modules

- Phase 0: project.yml fixes (CODE_SIGN_ENTITLEMENTS confirmed)
- Phase 1: Enhanced models (HabitModels, TaskModels, FinanceModels, SavingsModels, UserModels)
- Phase 1: Enhanced APIService with all endpoints (habits/log/stats, tasks/uncomplete, finance/analytics, savings/*)
- Phase 2: DashboardView rewrite - day progress bar, 4 stat cards, habit/task lists with Undo (3 sec)
- Phase 3: TrackerView - HabitListView (streak badge, swipe delete, archive), TaskListView (priority, overdue), StatisticsView (heatmap 84 days, line chart, bar chart via Swift Charts)
- Phase 4: FinanceView rewrite - month picker, summary card, top expenses progress bars, pie chart, line chart, transactions by day, analytics tab with bar chart + month comparison
- Phase 5: SavingsView rewrite - overview with overdue block, categories tab with type icons, operations tab with category filter + add sheet
- Phase 6: SettingsView - dark/light theme, profile edit, telegram chat id, notifications toggle + time, timezone picker, logout
- Added: AddHabitView with weekly day selector + interval days
- Added: AddTaskView with icon/color/due date picker
- Haptic feedback on all toggle actions
This commit is contained in:
Cosmo
2026-03-25 17:14:59 +00:00
parent 17b82a874f
commit e7af51af10
18 changed files with 2959 additions and 628 deletions

View File

@@ -1,5 +1,7 @@
import Foundation
// MARK: - APIError
enum APIError: Error, LocalizedError {
case unauthorized
case networkError(String)
@@ -8,7 +10,7 @@ enum APIError: Error, LocalizedError {
var errorDescription: String? {
switch self {
case .unauthorized: return "Неверный email или пароль"
case .unauthorized: return "Сессия истекла. Войдите снова."
case .networkError(let m): return "Ошибка сети: \(m)"
case .decodingError(let m): return "Ошибка данных: \(m)"
case .serverError(let c, let m): return "Ошибка \(c): \(m)"
@@ -16,6 +18,8 @@ enum APIError: Error, LocalizedError {
}
}
// MARK: - APIService
class APIService {
static let shared = APIService()
let baseURL = "https://api.digital-home.site"
@@ -39,8 +43,13 @@ class APIService {
let msg = String(data: data, encoding: .utf8) ?? "Unknown"
throw APIError.serverError(http.statusCode, msg)
}
do { return try JSONDecoder().decode(T.self, from: data) }
catch { throw APIError.decodingError(error.localizedDescription) }
let decoder = JSONDecoder()
do { return try decoder.decode(T.self, from: data) }
catch {
// Debug: print first 200 chars of response
let snippet = String(data: data, encoding: .utf8)?.prefix(200) ?? ""
throw APIError.decodingError("\(error.localizedDescription) | Response: \(snippet)")
}
}
// MARK: - Auth
@@ -59,6 +68,17 @@ class APIService {
return try await fetch("/auth/me", token: token)
}
// MARK: - Profile
func getProfile(token: String) async throws -> UserProfile {
return try await fetch("/profile", token: token)
}
func updateProfile(token: String, request: UpdateProfileRequest) async throws -> UserProfile {
let body = try JSONEncoder().encode(request)
return try await fetch("/profile", method: "PUT", token: token, body: body)
}
// MARK: - Tasks
func getTasks(token: String) async throws -> [PulseTask] {
@@ -75,33 +95,80 @@ class APIService {
return try await fetch("/tasks", method: "POST", token: token, body: body)
}
@discardableResult
func updateTask(token: String, id: Int, request: UpdateTaskRequest) async throws -> PulseTask {
let body = try JSONEncoder().encode(request)
return try await fetch("/tasks/\(id)", method: "PUT", token: token, body: body)
}
func completeTask(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/tasks/\(id)/complete", method: "POST", token: token)
}
func uncompleteTask(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/tasks/\(id)/uncomplete", method: "POST", token: token)
}
func deleteTask(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/tasks/\(id)", method: "DELETE", token: token)
}
// MARK: - Habits
func getHabits(token: String) async throws -> [Habit] {
return try await fetch("/habits", token: token)
func getHabits(token: String, includeArchived: Bool = false) async throws -> [Habit] {
let query = includeArchived ? "?archived=true" : ""
return try await fetch("/habits\(query)", token: token)
}
func logHabit(token: String, id: Int) async throws {
let body = try JSONEncoder().encode(HabitLogRequest())
@discardableResult
func createHabit(token: String, body: Data) async throws -> Habit {
return try await fetch("/habits", method: "POST", token: token, body: body)
}
@discardableResult
func updateHabit(token: String, id: Int, body: Data) async throws -> Habit {
return try await fetch("/habits/\(id)", method: "PUT", token: token, body: body)
}
func deleteHabit(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/habits/\(id)", method: "DELETE", token: token)
}
func logHabit(token: String, id: Int, date: String? = nil) async throws {
var params: [String: Any] = [:]
if let d = date { params["completed_at"] = d }
let body = try JSONSerialization.data(withJSONObject: params)
let _: EmptyResponse = try await fetch("/habits/\(id)/log", method: "POST", token: token, body: body)
}
func unlogHabit(token: String, habitId: Int, logId: Int) async throws {
let _: EmptyResponse = try await fetch("/habits/\(habitId)/logs/\(logId)", method: "DELETE", token: token)
}
func getHabitLogs(token: String, habitId: Int, days: Int = 90) async throws -> [HabitLog] {
return try await fetch("/habits/\(habitId)/logs?days=\(days)", token: token)
}
func getHabitStats(token: String, habitId: Int) async throws -> HabitStats {
return try await fetch("/habits/\(habitId)/stats", token: token)
}
func getHabitsStats(token: String) async throws -> HabitsOverallStats {
return try await fetch("/habits/stats", token: token)
}
// MARK: - Finance
func getFinanceSummary(token: String) async throws -> FinanceSummary {
return try await fetch("/finance/summary", token: token)
func getFinanceSummary(token: String, month: Int? = nil, year: Int? = nil) async throws -> FinanceSummary {
var query = ""
if let m = month, let y = year { query = "?month=\(m)&year=\(y)" }
return try await fetch("/finance/summary\(query)", token: token)
}
func getTransactions(token: String) async throws -> [FinanceTransaction] {
return try await fetch("/finance/transactions", token: token)
func getTransactions(token: String, month: Int? = nil, year: Int? = nil) async throws -> [FinanceTransaction] {
var query = ""
if let m = month, let y = year { query = "?month=\(m)&year=\(y)" }
return try await fetch("/finance/transactions\(query)", token: token)
}
@discardableResult
@@ -110,22 +177,57 @@ class APIService {
return try await fetch("/finance/transactions", method: "POST", token: token, body: body)
}
func deleteTransaction(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/finance/transactions/\(id)", method: "DELETE", token: token)
}
func getFinanceCategories(token: String) async throws -> [FinanceCategory] {
return try await fetch("/finance/categories", token: token)
}
func getFinanceAnalytics(token: String, month: Int? = nil, year: Int? = nil) async throws -> FinanceAnalytics {
var query = ""
if let m = month, let y = year { query = "?month=\(m)&year=\(y)" }
return try await fetch("/finance/analytics\(query)", token: token)
}
// MARK: - Savings
func getSavingsCategories(token: String) async throws -> [SavingsCategory] {
return try await fetch("/savings/categories", token: token)
}
@discardableResult
func createSavingsCategory(token: String, body: Data) async throws -> SavingsCategory {
return try await fetch("/savings/categories", method: "POST", token: token, body: body)
}
func updateSavingsCategory(token: String, id: Int, body: Data) async throws {
let _: SavingsCategory = try await fetch("/savings/categories/\(id)", method: "PUT", token: token, body: body)
}
func deleteSavingsCategory(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/savings/categories/\(id)", method: "DELETE", token: token)
}
func getSavingsStats(token: String) async throws -> SavingsStats {
return try await fetch("/savings/stats", token: token)
}
func getSavingsTransactions(token: String, limit: Int = 50) async throws -> [SavingsTransaction] {
return try await fetch("/savings/transactions?limit=\(limit)", token: token)
func getSavingsTransactions(token: String, categoryId: Int? = nil, limit: Int = 50) async throws -> [SavingsTransaction] {
var query = "?limit=\(limit)"
if let c = categoryId { query += "&category_id=\(c)" }
return try await fetch("/savings/transactions\(query)", token: token)
}
func getFinanceCategories(token: String) async throws -> [FinanceCategory] {
return try await fetch("/finance/categories", token: token)
@discardableResult
func createSavingsTransaction(token: String, request: CreateSavingsTransactionRequest) async throws -> SavingsTransaction {
let body = try JSONEncoder().encode(request)
return try await fetch("/savings/transactions", method: "POST", token: token, body: body)
}
func deleteSavingsTransaction(token: String, id: Int) async throws {
let _: EmptyResponse = try await fetch("/savings/transactions/\(id)", method: "DELETE", token: token)
}
}