Fix P0-P3 code review issues for clubs and challenges (FRE-4664)

P0: Fix variable shadowing in ClubService.createClub/updateClub and
    ChallengeService.createChallenge/updateChallenge — renamed local
    'var request' to 'var urlRequest' so JSONEncoder encodes the
    typed parameter, not the URLRequest.

P1: Wire CreateClubSheet and CreateChallengeSheet to parent ViewModel —
    sheets now receive viewModel and call createClub/createChallenge
    before dismissing.

P2: Extract HTTPMethod enum to shared Utils/HTTPMethod.swift (was
    defined in NotificationService). Remove dead 'body' parameter from
    buildRequest in all three services. Add error alert UI to
    ClubsView and ChallengesView.

P3: Replace forced URL unwrap with static let defaultBaseURL in all
    three services. Fix MockChallengeService.updateChallenge to track
    updateCalled instead of always throwing notFound.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-05-10 06:42:00 -04:00
parent b8c14ef8a7
commit bc7bf124f5
8 changed files with 81 additions and 43 deletions

View File

@@ -10,6 +10,7 @@ final class MockChallengeService: ChallengeServiceProtocol {
var joinCalledIds: [String] = []
var leaveCalledIds: [String] = []
var createCalled = false
var updateCalled = false
var leaderboard: [LeaderboardEntry] = []
var listCallCount = 0
var listError: Error?
@@ -51,7 +52,28 @@ final class MockChallengeService: ChallengeServiceProtocol {
}
func updateChallenge(id: String, request: UpdateChallengeRequest) async throws -> Challenge {
throw ChallengeError.notFound
updateCalled = true
return Challenge(
id: id,
title: request.title ?? "Updated",
description: request.description ?? "",
challengeType: request.challengeType ?? .distance,
status: .active,
startDate: Date(),
endDate: Date().addingTimeInterval(30 * 24 * 3600),
targetMetric: request.targetMetric ?? .distance,
targetValue: request.targetValue ?? 100,
targetUnit: (request.targetMetric ?? .distance).unit,
participantCount: 0,
rules: request.rules,
imageUrl: nil,
createdBy: "current-user",
createdByName: "Current User",
clubId: nil,
participationStatus: .participating,
userProgress: 0,
createdAt: Date()
)
}
func joinChallenge(id: String) async throws {