Laurent 7 months ago
commit f931147a20
  1. 12
      PadelClub.xcodeproj/project.pbxproj
  2. 2
      PadelClub/Utils/Network/NetworkFederalService.swift
  3. 41
      PadelClub/ViewModel/FederalDataViewModel.swift
  4. 133
      PadelClub/Views/Navigation/Agenda/EventListView.swift

@ -3666,7 +3666,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3711,7 +3711,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3829,7 +3829,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3874,7 +3874,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3918,7 +3918,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub.beta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3960,7 +3960,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.13;
MARKETING_VERSION = 1.2.14;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub.beta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

@ -46,7 +46,7 @@ class NetworkFederalService {
// Print JSON data before decoding
if let jsonObject = try? JSONSerialization.jsonObject(with: data) {
print("Response JSON: \(jsonObject)")
//print("Response JSON: \(jsonObject)")
} else {
print("Response is not a valid JSON")
// Try to print as string if not JSON

@ -158,14 +158,43 @@ class FederalDataViewModel {
(dayDuration == nil || (dayDuration != nil && dayDuration == tournament.dayDuration))
}
func gatherTournaments(clubs: [Club], startDate: Date, endDate: Date? = nil) async throws {
func gatherTournaments(clubs: [Club], startDate: Date, endDate: Date? = nil) async throws {
// Use actor or lock to safely collect results from concurrent operations
actor TournamentCollector {
private var federalTournaments: [FederalTournament] = []
func add(tournaments: [FederalTournament]) {
self.federalTournaments.append(contentsOf: tournaments)
}
func getAllTournaments() -> [FederalTournament] {
return federalTournaments
}
}
let collector = TournamentCollector()
try await clubs.filter { $0.code != nil }.concurrentForEach { club in
let newTournaments = try await NetworkFederalService.shared.getClubFederalTournaments(page: 0, tournaments: [], club: club.name, codeClub: club.code!, startDate: startDate, endDate: endDate)
let newTournaments = try await NetworkFederalService.shared.getClubFederalTournaments(
page: 0,
tournaments: [],
club: club.name,
codeClub: club.code!,
startDate: startDate,
endDate: endDate
)
newTournaments.forEach { tournament in
if self.federalTournaments.contains(where: { $0.id == tournament.id }) == false {
self.federalTournaments.append(tournament)
}
// Safely add to collector
await collector.add(tournaments: newTournaments)
}
// Get all collected tournaments
let allNewTournaments = await collector.getAllTournaments()
// Now safely update the main array with unique items
for tournament in allNewTournaments {
if !self.federalTournaments.contains(where: { $0.id == tournament.id }) {
self.federalTournaments.append(tournament)
}
}
}

@ -44,8 +44,16 @@ struct EventListView: View {
Text("\(count.formatted()) tournoi" + count.pluralSuffix)
}
} footer: {
if _tournaments.isEmpty == false, let pcTournaments = _tournaments as? [Tournament] {
_menuOptions(pcTournaments)
if _tournaments.isEmpty == false {
if let pcTournaments = _tournaments as? [Tournament] {
_menuOptions(pcTournaments)
} else if let federalTournaments = _tournaments as? [FederalTournament], navigation.agendaDestination == .tenup {
FooterButtonView("Tout récupérer", role: .destructive) {
federalTournaments.forEach { federalTournament in
_importFederalTournamentBatch(federalTournament: federalTournament)
}
}
}
}
}
.headerProminence(.increased)
@ -76,24 +84,19 @@ struct EventListView: View {
if navigation.agendaDestination == .tenup
&& dataStore.user.hasTenupClubs() == true
&& _tournaments.isEmpty {
_gatherFederalTournaments(startDate: section)
await _gatherFederalTournaments(startDate: section)
}
}
}
}
}
private func _gatherFederalTournaments(startDate: Date) {
// isGatheringFederalTournaments = true
Task {
do {
let clubs : [Club] = dataStore.user.clubsObjects()
try await federalDataViewModel.gatherTournaments(clubs: clubs.filter { $0.code != nil }, startDate: startDate, endDate: startDate.endOfMonth)
} catch {
Logger.error(error)
// self.error = error
}
// isGatheringFederalTournaments = false
private func _gatherFederalTournaments(startDate: Date) async {
do {
let clubs : [Club] = dataStore.user.clubsObjects()
try await federalDataViewModel.gatherTournaments(clubs: clubs.filter { $0.code != nil }, startDate: startDate)
} catch {
Logger.error(error)
}
}
@ -274,7 +277,77 @@ struct EventListView: View {
} label: {
Text("Description des tournois")
}
Divider()
Menu {
Button {
pcTournaments.forEach { tournament in
tournament.umpireCustomMail = nil
tournament.umpireCustomPhone = nil
tournament.umpireCustomContact = nil
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Effacer les informations du JAP")
}
let umpireCustomMail = pcTournaments.first(where: { tournament in
tournament.umpireCustomMail != nil
})?.umpireCustomMail
let umpireCustomPhone = pcTournaments.first(where: { tournament in
tournament.umpireCustomPhone != nil
})?.umpireCustomPhone
let umpireCustomContact = pcTournaments.first(where: { tournament in
tournament.umpireCustomContact != nil
})?.umpireCustomContact
Button {
pcTournaments.forEach { tournament in
tournament.umpireCustomMail = umpireCustomMail
tournament.umpireCustomPhone = umpireCustomPhone
tournament.umpireCustomContact = umpireCustomContact
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Indiquer le même JAP pour tous")
}
Button {
pcTournaments.forEach { tournament in
tournament.hideUmpireMail = true
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Masquer le mail")
}
Button {
pcTournaments.forEach { tournament in
tournament.hideUmpireMail = false
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Afficher le mail")
}
Button {
pcTournaments.forEach { tournament in
tournament.hideUmpirePhone = true
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Masquer le téléphone")
}
Button {
pcTournaments.forEach { tournament in
tournament.hideUmpirePhone = false
}
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments)
} label: {
Text("Afficher le téléphone")
}
} label: {
Text("Infos JAP")
}
}
private func _nextMonths() -> [Date] {
@ -363,6 +436,38 @@ struct EventListView: View {
TournamentCellView(tournament: federalTournament)
}
private func _event(of tournament: FederalTournament) -> Event? {
return dataStore.events.first(where: { $0.tenupId == tournament.id.string })
}
private func _importFederalTournamentBatch(federalTournament: FederalTournament) {
federalTournament.tournaments.forEach { tournament in
_create(federalTournament: federalTournament, existingTournament: _event(of: federalTournament)?.existingBuild(tournament), build: tournament)
}
}
private func _create(federalTournament: FederalTournament, existingTournament: Tournament?, build: any TournamentBuildHolder) {
if let existingTournament {
} else {
let event = federalTournament.getEvent()
let newTournament = Tournament.newEmptyInstance()
newTournament.event = event.id
//todo
//newTournament.umpireMail()
//newTournament.jsonData = jsonData
newTournament.tournamentLevel = build.level
newTournament.tournamentCategory = build.category
newTournament.federalTournamentAge = build.age
newTournament.dayDuration = federalTournament.dayDuration
newTournament.startDate = federalTournament.startDate.atBeginningOfDay(hourInt: 9)
newTournament.setupFederalSettings()
do {
try dataStore.tournaments.addOrUpdate(instance: newTournament)
} catch {
Logger.error(error)
}
}
}
}
//#Preview {

Loading…
Cancel
Save