feat(polls): implement group trip polling MVP

Add complete group trip polling feature allowing users to share trips
with friends for voting using Borda count scoring.

New components:
- TripPoll and PollVote domain models with share codes and rankings
- LocalTripPoll and LocalPollVote SwiftData models for persistence
- CKTripPoll and CKPollVote CloudKit record wrappers
- PollService actor for CloudKit CRUD operations and subscriptions
- PollCreation/Detail/Voting views and view models
- Deep link handling for sportstime://poll/{code} URLs
- Debug Pro status override toggle in Settings

Integration:
- HomeView shows polls section in My Trips
- SportsTimeApp registers SwiftData models and handles deep links

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-13 21:54:42 -06:00
parent 8e78828bde
commit 13385b6562
16 changed files with 2416 additions and 19 deletions

View File

@@ -18,6 +18,8 @@ enum CKRecordType {
static let leagueStructure = "LeagueStructure"
static let teamAlias = "TeamAlias"
static let stadiumAlias = "StadiumAlias"
static let tripPoll = "TripPoll"
static let pollVote = "PollVote"
}
// MARK: - CKTeam
@@ -472,3 +474,114 @@ struct CKTeamAlias {
)
}
}
// MARK: - CKTripPoll
struct CKTripPoll {
static let pollIdKey = "pollId"
static let titleKey = "title"
static let ownerIdKey = "ownerId"
static let shareCodeKey = "shareCode"
static let tripSnapshotsKey = "tripSnapshots"
static let tripVersionsKey = "tripVersions"
static let createdAtKey = "createdAt"
static let modifiedAtKey = "modifiedAt"
let record: CKRecord
init(record: CKRecord) {
self.record = record
}
init(poll: TripPoll) {
let record = CKRecord(recordType: CKRecordType.tripPoll, recordID: CKRecord.ID(recordName: poll.id.uuidString))
record[CKTripPoll.pollIdKey] = poll.id.uuidString
record[CKTripPoll.titleKey] = poll.title
record[CKTripPoll.ownerIdKey] = poll.ownerId
record[CKTripPoll.shareCodeKey] = poll.shareCode
// Encode trips as JSON data
if let tripsData = try? JSONEncoder().encode(poll.tripSnapshots) {
record[CKTripPoll.tripSnapshotsKey] = tripsData
}
record[CKTripPoll.tripVersionsKey] = poll.tripVersions
record[CKTripPoll.createdAtKey] = poll.createdAt
record[CKTripPoll.modifiedAtKey] = poll.modifiedAt
self.record = record
}
func toPoll() -> TripPoll? {
guard let pollIdString = record[CKTripPoll.pollIdKey] as? String,
let pollId = UUID(uuidString: pollIdString),
let title = record[CKTripPoll.titleKey] as? String,
let ownerId = record[CKTripPoll.ownerIdKey] as? String,
let shareCode = record[CKTripPoll.shareCodeKey] as? String,
let tripsData = record[CKTripPoll.tripSnapshotsKey] as? Data,
let tripSnapshots = try? JSONDecoder().decode([Trip].self, from: tripsData),
let tripVersions = record[CKTripPoll.tripVersionsKey] as? [String],
let createdAt = record[CKTripPoll.createdAtKey] as? Date,
let modifiedAt = record[CKTripPoll.modifiedAtKey] as? Date
else { return nil }
var poll = TripPoll(
id: pollId,
title: title,
ownerId: ownerId,
shareCode: shareCode,
tripSnapshots: tripSnapshots,
createdAt: createdAt,
modifiedAt: modifiedAt
)
// Preserve the actual stored versions (not recomputed)
poll.tripVersions = tripVersions
return poll
}
}
// MARK: - CKPollVote
struct CKPollVote {
static let voteIdKey = "voteId"
static let pollIdKey = "pollId"
static let voterIdKey = "voterId"
static let rankingsKey = "rankings"
static let votedAtKey = "votedAt"
static let modifiedAtKey = "modifiedAt"
let record: CKRecord
init(record: CKRecord) {
self.record = record
}
init(vote: PollVote) {
let record = CKRecord(recordType: CKRecordType.pollVote, recordID: CKRecord.ID(recordName: vote.id.uuidString))
record[CKPollVote.voteIdKey] = vote.id.uuidString
record[CKPollVote.pollIdKey] = vote.pollId.uuidString
record[CKPollVote.voterIdKey] = vote.odg
record[CKPollVote.rankingsKey] = vote.rankings
record[CKPollVote.votedAtKey] = vote.votedAt
record[CKPollVote.modifiedAtKey] = vote.modifiedAt
self.record = record
}
func toVote() -> PollVote? {
guard let voteIdString = record[CKPollVote.voteIdKey] as? String,
let voteId = UUID(uuidString: voteIdString),
let pollIdString = record[CKPollVote.pollIdKey] as? String,
let pollId = UUID(uuidString: pollIdString),
let voterId = record[CKPollVote.voterIdKey] as? String,
let rankings = record[CKPollVote.rankingsKey] as? [Int],
let votedAt = record[CKPollVote.votedAtKey] as? Date,
let modifiedAt = record[CKPollVote.modifiedAtKey] as? Date
else { return nil }
return PollVote(
id: voteId,
pollId: pollId,
odg: voterId,
rankings: rankings,
votedAt: votedAt,
modifiedAt: modifiedAt
)
}
}