This commit is contained in:
Trey t
2023-07-17 19:26:11 -05:00
parent 593cc496cd
commit af538362e8
23 changed files with 637 additions and 438 deletions

View File

@@ -6,28 +6,18 @@
//
import Foundation
struct Equipment: Codable {
let id: Int
let createdAt, updatedAt: String
let category, name: String?
let name, createdAt, updatedAt: String
let is_weight: Bool?
let category: String?
enum CodingKeys: String, CodingKey {
case id
case id, name
case createdAt = "created_at"
case updatedAt = "updated_at"
case category, name
}
}
struct ExerciseEquipment: Codable, Hashable {
let id: Int
let createdAt, updatedAt: String
let exercise, equipment: Int
enum CodingKeys: String, CodingKey {
case id
case createdAt = "created_at"
case updatedAt = "updated_at"
case equipment, exercise
case is_weight
case category
}
}

View File

@@ -7,32 +7,39 @@
import Foundation
struct ExerciseElement: Codable, Equatable {
let workout: Int
let exercise: ExerciseExercise
struct SupersetExercise: Identifiable, Codable, Equatable, Hashable {
var id = UUID()
let workout: Int?
let exercise: Exercise
let weight: Int?
let reps: Int?
let duration: Int?
let durationAudio: String?
let weightAudio: String?
let createdAt: String
let order, superset: Int
enum CodingKeys: String, CodingKey {
case workout, exercise, weight, reps, duration
case workout, exercise, weight, reps, duration, order, superset
case durationAudio = "duration_audio"
case weightAudio = "weight_audio"
case createdAt = "created_at"
}
public func hash(into hasher: inout Hasher) {
return hasher.combine(id)
}
}
struct ExerciseExercise: Codable, Hashable, Identifiable {
static func == (lhs: ExerciseExercise, rhs: ExerciseExercise) -> Bool {
struct Exercise: Identifiable, Codable, Equatable {
static func == (lhs: Exercise, rhs: Exercise) -> Bool {
lhs.id == rhs.id
}
let id: Int
let muscles: [ExerciseMuscle]
let equipment: [ExerciseEquipment]
let equipment: [Equipment]
let muscles: [Muscle]
let audioURL, videoURL, createdAt, updatedAt: String
let name, description, side: String
let isTwoDumbbells, isTrackableDistance, isAlternating, isWeight: Bool

View File

@@ -9,18 +9,11 @@ import Foundation
struct Muscle: Codable {
let id: Int
let name: String
}
struct ExerciseMuscle: Codable, Hashable {
let id: Int
let createdAt, updatedAt: String
let exercise, muscle: Int
let name, createdAt, updatedAt: String
enum CodingKeys: String, CodingKey {
case id
case id, name
case createdAt = "created_at"
case updatedAt = "updated_at"
case exercise, muscle
}
}

View File

@@ -0,0 +1,26 @@
//
// Superset.swift
// Werkout_ios
//
// Created by Trey Tartt on 7/17/23.
//
import Foundation
struct Superset: Codable, Identifiable, Hashable {
let id: Int
let exercises: [SupersetExercise]
let createdAt, updatedAt, name: String?
let rounds, order, workout: Int
enum CodingKeys: String, CodingKey {
case id, exercises
case createdAt = "created_at"
case updatedAt = "updated_at"
case name, rounds, order, workout
}
public func hash(into hasher: inout Hasher) {
return hasher.combine(id)
}
}

View File

@@ -15,17 +15,15 @@ struct Workout: Codable, Identifiable, Equatable {
let id: Int
let name: String
let description: String?
let exercises: [ExerciseElement]
let supersets: [Superset]?
let registeredUser: RegisteredUser?
let femaleVideos, maleVideos, bothVideos: [String]?
let muscles: [String]?
let equipment: [String]?
let exercise_count: Int?
let maleVideos: [String]?
let femaleVideos: [String]?
let bothVideos: [String]?
enum CodingKeys: String, CodingKey {
case name, description, exercises, id, muscles, equipment, exercise_count
case id, name, description, supersets, exercise_count, muscles, equipment
case registeredUser = "registered_user"
case maleVideos = "male_videos"
case femaleVideos = "female_videos"
@@ -34,31 +32,18 @@ struct Workout: Codable, Identifiable, Equatable {
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
if let exercises = try container.decodeIfPresent([ExerciseElement].self, forKey: .exercises) {
self.exercises = exercises
} else {
self.exercises = [ExerciseElement]()
}
self.name = try container.decode(String.self, forKey: .name)
self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? "NA"
self.description = try container.decodeIfPresent(String.self, forKey: .description)
self.registeredUser = try container.decodeIfPresent(RegisteredUser.self, forKey: .registeredUser)
self.id = try container.decode(Int.self, forKey: .id)
self.muscles = try container.decodeIfPresent([String].self, forKey: .muscles)
self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment)
self.exercise_count = try container.decodeIfPresent(Int.self, forKey: .exercise_count)
self.femaleVideos = try container.decodeIfPresent([String].self, forKey: .femaleVideos)
self.maleVideos = try container.decodeIfPresent([String].self, forKey: .maleVideos)
self.bothVideos = try container.decodeIfPresent([String].self, forKey: .bothVideos)
}
var exercisesSortedByCreated_at: [ExerciseElement] {
return self.exercises.sorted(by: {
if let lhsDate = $0.createdAt.dateFromServerDate,
let rhsDate = $1.createdAt.dateFromServerDate {
return lhsDate < rhsDate
}
return false
})
self.supersets = try container.decodeIfPresent([Superset].self, forKey: .supersets)
self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment)
self.muscles = try container.decodeIfPresent([String].self, forKey: .muscles)
self.exercise_count = try container.decodeIfPresent(Int.self, forKey: .exercise_count)
}
}