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:
@@ -1,5 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
// MARK: - FinanceTransaction
|
||||
|
||||
struct FinanceTransaction: Codable, Identifiable {
|
||||
let id: Int
|
||||
var amount: Double
|
||||
@@ -9,6 +11,17 @@ struct FinanceTransaction: Codable, Identifiable {
|
||||
var date: String?
|
||||
var createdAt: String?
|
||||
|
||||
var isIncome: Bool { type == "income" }
|
||||
|
||||
var dateFormatted: String {
|
||||
guard let d = date else { return "" }
|
||||
let parts = String(d.prefix(10)).split(separator: "-")
|
||||
guard parts.count == 3 else { return String(d.prefix(10)) }
|
||||
return "\(parts[2]).\(parts[1]).\(parts[0])"
|
||||
}
|
||||
|
||||
var dateOnly: String { String(date?.prefix(10) ?? "") }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, amount, description, type, date
|
||||
case categoryId = "category_id"
|
||||
@@ -16,6 +29,8 @@ struct FinanceTransaction: Codable, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - FinanceCategory
|
||||
|
||||
struct FinanceCategory: Codable, Identifiable {
|
||||
let id: Int
|
||||
var name: String
|
||||
@@ -24,21 +39,66 @@ struct FinanceCategory: Codable, Identifiable {
|
||||
var type: String
|
||||
}
|
||||
|
||||
// MARK: - FinanceSummary
|
||||
|
||||
struct FinanceSummary: Codable {
|
||||
var totalIncome: Double?
|
||||
var totalExpense: Double?
|
||||
var balance: Double?
|
||||
var carriedOver: Double?
|
||||
var month: String?
|
||||
var byCategory: [CategorySpend]?
|
||||
var daily: [DailySpend]?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case balance, month
|
||||
case totalIncome = "total_income"
|
||||
case totalExpense = "total_expense"
|
||||
case carriedOver = "carried_over"
|
||||
case byCategory = "by_category"
|
||||
case daily
|
||||
}
|
||||
}
|
||||
|
||||
struct CategorySpend: Codable, Identifiable {
|
||||
var id: Int { categoryId ?? 0 }
|
||||
var categoryId: Int?
|
||||
var categoryName: String?
|
||||
var total: Double?
|
||||
var icon: String?
|
||||
var color: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case total, icon, color
|
||||
case categoryId = "category_id"
|
||||
case categoryName = "category_name"
|
||||
}
|
||||
}
|
||||
|
||||
struct DailySpend: Codable, Identifiable {
|
||||
var id: String { date }
|
||||
let date: String
|
||||
let total: Double?
|
||||
let income: Double?
|
||||
let expense: Double?
|
||||
}
|
||||
|
||||
// MARK: - FinanceAnalytics
|
||||
|
||||
struct FinanceAnalytics: Codable {
|
||||
var currentMonth: FinanceSummary?
|
||||
var previousMonth: FinanceSummary?
|
||||
var byCategory: [CategorySpend]?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case currentMonth = "current_month"
|
||||
case previousMonth = "previous_month"
|
||||
case byCategory = "by_category"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CreateTransactionRequest
|
||||
|
||||
struct CreateTransactionRequest: Codable {
|
||||
var amount: Double
|
||||
var categoryId: Int?
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import Foundation
|
||||
|
||||
enum HabitFrequency: String, Codable {
|
||||
case daily, weekly, monthly
|
||||
// MARK: - Habit Frequency
|
||||
|
||||
enum HabitFrequency: String, Codable, CaseIterable {
|
||||
case daily, weekly, monthly, interval, custom
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .daily: return "Ежедневно"
|
||||
case .weekly: return "Еженедельно"
|
||||
case .monthly: return "Ежемесячно"
|
||||
case .interval: return "Через N дней"
|
||||
case .custom: return "Особое"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Habit
|
||||
|
||||
struct Habit: Codable, Identifiable {
|
||||
let id: Int
|
||||
var name: String
|
||||
@@ -25,6 +31,13 @@ struct Habit: Codable, Identifiable {
|
||||
var longestStreak: Int?
|
||||
var completedToday: Bool?
|
||||
var totalCompleted: Int?
|
||||
var isArchived: Bool?
|
||||
var startDate: String?
|
||||
var createdAt: String?
|
||||
var updatedAt: String?
|
||||
|
||||
var accentColorHex: String { color ?? "00d4aa" }
|
||||
var displayIcon: String { icon ?? "🔥" }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, name, description, icon, color, frequency
|
||||
@@ -35,9 +48,105 @@ struct Habit: Codable, Identifiable {
|
||||
case longestStreak = "longest_streak"
|
||||
case completedToday = "completed_today"
|
||||
case totalCompleted = "total_completed"
|
||||
case isArchived = "is_archived"
|
||||
case startDate = "start_date"
|
||||
case createdAt = "created_at"
|
||||
case updatedAt = "updated_at"
|
||||
}
|
||||
|
||||
var frequencyLabel: String {
|
||||
switch frequency {
|
||||
case .daily: return "Ежедневно"
|
||||
case .weekly:
|
||||
guard let days = targetDays, !days.isEmpty else { return "Еженедельно" }
|
||||
let names = ["Вс","Пн","Вт","Ср","Чт","Пт","Сб"]
|
||||
return days.sorted().compactMap { names[safe: $0] }.joined(separator: ", ")
|
||||
case .interval:
|
||||
let n = targetCount ?? 1
|
||||
return "Каждые \(n) дн."
|
||||
case .monthly: return "Ежемесячно"
|
||||
case .custom: return "Особое"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - HabitLog
|
||||
|
||||
struct HabitLog: Codable, Identifiable {
|
||||
let id: Int
|
||||
let habitId: Int?
|
||||
let completedAt: String?
|
||||
let note: String?
|
||||
|
||||
var dateOnly: String { String(completedAt?.prefix(10) ?? "") }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case habitId = "habit_id"
|
||||
case completedAt = "completed_at"
|
||||
case note
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - HabitFreeze
|
||||
|
||||
struct HabitFreeze: Codable, Identifiable {
|
||||
let id: Int
|
||||
let habitId: Int?
|
||||
let startDate: String
|
||||
let endDate: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case habitId = "habit_id"
|
||||
case startDate = "start_date"
|
||||
case endDate = "end_date"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - HabitStats
|
||||
|
||||
struct HabitStats: Codable {
|
||||
let currentStreak: Int
|
||||
let longestStreak: Int
|
||||
let thisMonth: Int
|
||||
let totalCompleted: Int?
|
||||
let completionRate: Double?
|
||||
|
||||
var completionPercent: Int { Int((completionRate ?? 0) * 100) }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case currentStreak = "current_streak"
|
||||
case longestStreak = "longest_streak"
|
||||
case thisMonth = "this_month"
|
||||
case totalCompleted = "total_completed"
|
||||
case completionRate = "completion_rate"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - HabitsOverallStats
|
||||
|
||||
struct HabitsOverallStats: Codable {
|
||||
let todayCompleted: Int?
|
||||
let activeHabits: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case todayCompleted = "today_completed"
|
||||
case activeHabits = "active_habits"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CompletionDataPoint (for charts)
|
||||
|
||||
struct CompletionDataPoint: Identifiable {
|
||||
let id = UUID()
|
||||
let date: Date
|
||||
let rate: Double
|
||||
let label: String
|
||||
}
|
||||
|
||||
// MARK: - HabitLogRequest
|
||||
|
||||
struct HabitLogRequest: Codable {
|
||||
var completedAt: String?
|
||||
var note: String?
|
||||
@@ -46,3 +155,12 @@ struct HabitLogRequest: Codable {
|
||||
case note
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Safe Array Subscript
|
||||
|
||||
extension Array {
|
||||
subscript(safe index: Int) -> Element? {
|
||||
guard index >= 0, index < count else { return nil }
|
||||
return self[index]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,28 +16,40 @@ struct SavingsCategory: Codable, Identifiable {
|
||||
var depositStartDate: String?
|
||||
var depositEndDate: String?
|
||||
var recurringAmount: Double?
|
||||
|
||||
var recurringDay: Int?
|
||||
|
||||
var icon: String {
|
||||
if isCredit == true { return "creditcard.fill" }
|
||||
if isDeposit == true { return "percent" }
|
||||
if isAccount == true { return "building.columns.fill" }
|
||||
if isRecurring == true { return "arrow.clockwise" }
|
||||
return "banknote.fill"
|
||||
}
|
||||
|
||||
var color: String {
|
||||
|
||||
var colorHex: String {
|
||||
if isCredit == true { return "ff4757" }
|
||||
if isDeposit == true { return "ffa502" }
|
||||
if isAccount == true { return "7c3aed" }
|
||||
if isRecurring == true { return "00d4aa" }
|
||||
return "8888aa"
|
||||
}
|
||||
|
||||
|
||||
var typeLabel: String {
|
||||
if isCredit == true { return "Кредит \(Int(interestRate ?? 0))%" }
|
||||
if isDeposit == true { return "Вклад \(Int(interestRate ?? 0))%" }
|
||||
if isAccount == true { return "Счёт" }
|
||||
if isRecurring == true { return "Накопления" }
|
||||
return "Копилка"
|
||||
if isRecurring == true { return "Регулярные" }
|
||||
return "Накопление"
|
||||
}
|
||||
|
||||
|
||||
var typeEmoji: String {
|
||||
if isCredit == true { return "💳" }
|
||||
if isDeposit == true { return "🏦" }
|
||||
if isAccount == true { return "🏧" }
|
||||
if isRecurring == true { return "🔄" }
|
||||
return "💰"
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, name, description
|
||||
case isDeposit = "is_deposit"
|
||||
@@ -52,6 +64,7 @@ struct SavingsCategory: Codable, Identifiable {
|
||||
case depositStartDate = "deposit_start_date"
|
||||
case depositEndDate = "deposit_end_date"
|
||||
case recurringAmount = "recurring_amount"
|
||||
case recurringDay = "recurring_day"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +79,18 @@ struct SavingsTransaction: Codable, Identifiable {
|
||||
var createdAt: String?
|
||||
var categoryName: String?
|
||||
var userName: String?
|
||||
|
||||
|
||||
var isDeposit: Bool { type == "deposit" }
|
||||
|
||||
|
||||
var dateFormatted: String {
|
||||
guard let d = date else { return "" }
|
||||
let parts = String(d.prefix(10)).split(separator: "-")
|
||||
guard parts.count == 3 else { return String(d.prefix(10)) }
|
||||
return "\(parts[2]).\(parts[1]).\(parts[0])"
|
||||
}
|
||||
|
||||
var dateOnly: String { String(date?.prefix(10) ?? "") }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, amount, type, description, date
|
||||
case categoryId = "category_id"
|
||||
@@ -84,11 +106,30 @@ struct SavingsStats: Codable {
|
||||
var totalDeposits: Double?
|
||||
var totalWithdrawals: Double?
|
||||
var categoriesCount: Int?
|
||||
|
||||
var monthlyPayments: Double?
|
||||
var overdueAmount: Double?
|
||||
var overdueCount: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case totalBalance = "total_balance"
|
||||
case totalDeposits = "total_deposits"
|
||||
case totalWithdrawals = "total_withdrawals"
|
||||
case categoriesCount = "categories_count"
|
||||
case monthlyPayments = "monthly_payments"
|
||||
case overdueAmount = "overdue_amount"
|
||||
case overdueCount = "overdue_count"
|
||||
}
|
||||
}
|
||||
|
||||
struct CreateSavingsTransactionRequest: Codable {
|
||||
var categoryId: Int
|
||||
var amount: Double
|
||||
var type: String
|
||||
var description: String?
|
||||
var date: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case amount, type, description, date
|
||||
case categoryId = "category_id"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
// MARK: - PulseTask
|
||||
|
||||
struct PulseTask: Codable, Identifiable {
|
||||
let id: Int
|
||||
var title: String
|
||||
@@ -11,6 +13,9 @@ struct PulseTask: Codable, Identifiable {
|
||||
var dueDate: String?
|
||||
var reminderTime: String?
|
||||
var createdAt: String?
|
||||
var isRecurring: Bool?
|
||||
var recurrenceType: String?
|
||||
var recurrenceInterval: Int?
|
||||
|
||||
var priorityColor: String {
|
||||
switch priority {
|
||||
@@ -31,22 +36,80 @@ struct PulseTask: Codable, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
var isOverdue: Bool {
|
||||
guard !completed, let due = dueDate else { return false }
|
||||
let dateStr = String(due.prefix(10))
|
||||
let today = ISO8601DateFormatter().string(from: Date()).prefix(10)
|
||||
return dateStr < today
|
||||
}
|
||||
|
||||
var dueDateFormatted: String? {
|
||||
guard let due = dueDate else { return nil }
|
||||
let dateStr = String(due.prefix(10))
|
||||
let todayStr = String(ISO8601DateFormatter().string(from: Date()).prefix(10))
|
||||
let tomorrowDate = Calendar.current.date(byAdding: .day, value: 1, to: Date())!
|
||||
let tomorrowStr = String(ISO8601DateFormatter().string(from: tomorrowDate).prefix(10))
|
||||
if dateStr == todayStr { return "Сегодня" }
|
||||
if dateStr == tomorrowStr { return "Завтра" }
|
||||
let parts = dateStr.split(separator: "-")
|
||||
guard parts.count == 3 else { return dateStr }
|
||||
return "\(parts[2]).\(parts[1]).\(parts[0])"
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, title, description, completed, priority, icon, color
|
||||
case dueDate = "due_date"
|
||||
case reminderTime = "reminder_time"
|
||||
case createdAt = "created_at"
|
||||
case isRecurring = "is_recurring"
|
||||
case recurrenceType = "recurrence_type"
|
||||
case recurrenceInterval = "recurrence_interval"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - TaskStats
|
||||
|
||||
struct TaskStats: Codable {
|
||||
let totalTasks: Int?
|
||||
let completedTasks: Int?
|
||||
let todayTasks: Int?
|
||||
let todayCompleted: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case totalTasks = "total_tasks"
|
||||
case completedTasks = "completed_tasks"
|
||||
case todayTasks = "today_tasks"
|
||||
case todayCompleted = "today_completed"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CreateTaskRequest
|
||||
|
||||
struct CreateTaskRequest: Codable {
|
||||
var title: String
|
||||
var description: String?
|
||||
var priority: Int?
|
||||
var dueDate: String?
|
||||
var icon: String?
|
||||
var color: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case title, description, priority
|
||||
case title, description, priority, icon, color
|
||||
case dueDate = "due_date"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UpdateTaskRequest
|
||||
|
||||
struct UpdateTaskRequest: Codable {
|
||||
var title: String?
|
||||
var description: String?
|
||||
var priority: Int?
|
||||
var dueDate: String?
|
||||
var completed: Bool?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case title, description, priority, completed
|
||||
case dueDate = "due_date"
|
||||
}
|
||||
}
|
||||
|
||||
41
PulseHealth/Models/UserModels.swift
Normal file
41
PulseHealth/Models/UserModels.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
import Foundation
|
||||
|
||||
// MARK: - UserProfile
|
||||
|
||||
struct UserProfile: Codable {
|
||||
var telegramChatId: String?
|
||||
var morningNotification: Bool?
|
||||
var eveningNotification: Bool?
|
||||
var morningTime: String?
|
||||
var eveningTime: String?
|
||||
var timezone: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case telegramChatId = "telegram_chat_id"
|
||||
case morningNotification = "morning_notification"
|
||||
case eveningNotification = "evening_notification"
|
||||
case morningTime = "morning_time"
|
||||
case eveningTime = "evening_time"
|
||||
case timezone
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UpdateProfileRequest
|
||||
|
||||
struct UpdateProfileRequest: Codable {
|
||||
var telegramChatId: String?
|
||||
var morningNotification: Bool?
|
||||
var eveningNotification: Bool?
|
||||
var morningTime: String?
|
||||
var eveningTime: String?
|
||||
var timezone: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case telegramChatId = "telegram_chat_id"
|
||||
case morningNotification = "morning_notification"
|
||||
case eveningNotification = "evening_notification"
|
||||
case morningTime = "morning_time"
|
||||
case eveningTime = "evening_time"
|
||||
case timezone
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user