Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
11 changes: 10 additions & 1 deletion SportApp/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ struct HomeView: View {
Label("Главная", systemImage: "house.fill")
}
.tag(0) // исправить потом

NavigationStack() {
EmptyView()
}
.tabItem {
Label("Мои матчи", systemImage: "pawprint.circle.fill")
}
.tag(1)

NavigationStack() {
ProfileView(isActive: $isAuthenticated)
Expand All @@ -73,7 +81,8 @@ struct HomeView: View {
.tabItem {
Label("Профиль", systemImage: "person.crop.circle")
}
.tag(1)

.tag(2)
}
}

Expand Down
1 change: 1 addition & 0 deletions SportApp/NetworkService/Data/APIRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ struct APIRoutes {
let login: String = "/api/v1/auth/login"
let register: String = "/api/v1/auth/register"
let getUserInfo: String = "/api/v1/users/<id>"
let getParticipants: String = "/api/v1/tournaments/{id}/participants"
}
7 changes: 7 additions & 0 deletions SportApp/Statistics/View/StatisticsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// StatisticsView.swift
// SportApp
//
// Created by user on 11.07.2025.
//

Binary file added SportApp/Tournirs/Model/DTO/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions SportApp/Tournirs/Model/Participant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Participant.swift
// SportApp
//
// Created by user on 10.07.2025.
//

import Foundation

struct Participant: Identifiable, Hashable, Codable {
var id: UUID
var phio: String
var phone_number: String?
var email: String
var age: Int?
var sex: Bool?
var weight: Double?
var height: Double?
}
24 changes: 24 additions & 0 deletions SportApp/Tournirs/Model/Participant/ParticipantDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Participants.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation

struct ParticipantDTO: Identifiable, Hashable, Codable {
var id: String
var name: String
var surname: String
var patronymic: String
var phone_number: String?
var email: String
var date_of_birth: String?
var sex: String?
var weight: Double?
var height: Double?
var bio: String?
var avatar_url: String?

}
27 changes: 27 additions & 0 deletions SportApp/Tournirs/Model/Participant/ParticipantEndpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ParticipantsEndpoint.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation

struct ParticipantEndpoint: Endpoint {
var baseURL = APIRoutes().baseURL
var tournamentID: String

var path: String {
return APIRoutes().getParticipants.replacingOccurrences(of: "{id}", with: "\(tournamentID)")
}

var method = HTTPMethod.get
var headers: [String: String]? = ["Content-Type": "application/json"]
var loginString: String? = "Admin:hashedpassword"
var isTokenRequired: Bool = true

init(tournamentID: String) {
self.tournamentID = tournamentID
}
}

22 changes: 22 additions & 0 deletions SportApp/Tournirs/Model/Participant/ParticipantPostEndpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ParticipantsPostEndpoint.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation

struct ParticipantPostEndpoint: Endpoint {
var baseURL = APIRoutes().baseURL

var path = APIRoutes().getParticipants

var method = HTTPMethod.post

var headers: [String: String]?

var loginString: String?

var isTokenRequired: Bool = true
}
21 changes: 21 additions & 0 deletions SportApp/Tournirs/Model/Participant/ParticipantPostRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ParticipantPostRequest.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation

struct ParticipantPostRequest: Encodable {
var id: String
var phio: String
var email: String

/*
init(participant: Participant) {
id = participant.id

}
*/
}
10 changes: 10 additions & 0 deletions SportApp/Tournirs/Model/Participant/ParticipantRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// ParticipantRequest.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation

struct ParticipantRequest: RequestDTO {}
6 changes: 3 additions & 3 deletions SportApp/Tournirs/Model/Tournir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

struct Tournir: Codable, Identifiable, Hashable {
var id = UUID()
var id: UUID
var title: String
var description: String
var sport: String
Expand Down Expand Up @@ -43,8 +43,8 @@ struct Requirements: Codable, Hashable {
heightMax = 200
weightMin = 0
weightMax = 100
mmrMin = 0
mmrMax = 10000
mmrMin = 500
mmrMax = 3000
}
}

Expand Down
2 changes: 1 addition & 1 deletion SportApp/Tournirs/View/TournirMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct TournirMaker: View {
Spacer()

Button(action: {
let tourinr: Tournir = Tournir(title: name, description: description, sport: Sport.toStringEng(Sport.allSports[selectedSport]), type_group: .olympic, type_tournir: .solo, start_time: combinedDateTime, created_at: Date(), entry_cost: Double(cost) ?? 0, is_team_based: true, place: "", max_participants: 10, organizer_id: UUID(), requirements: Requirements())
let tourinr: Tournir = Tournir(id: UUID(), title: name, description: description, sport: Sport.toStringEng(Sport.allSports[selectedSport]), type_group: .olympic, type_tournir: .solo, start_time: combinedDateTime, created_at: Date(), entry_cost: Double(cost) ?? 0, is_team_based: true, place: "", max_participants: 10, organizer_id: UUID(), requirements: Requirements())
viewModel.tournirs.append(tourinr)
viewModel.giveTournir(tournir: tourinr)
coordinator.dismissSheet()
Expand Down
22 changes: 8 additions & 14 deletions SportApp/Tournirs/View/TournirsDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct TournirsDetail: View {
@EnvironmentObject var coordinator: Coordinator
@StateObject var viewModel = ParticipantsViewModel()

var body: some View {
VStack {
Expand Down Expand Up @@ -68,28 +69,18 @@ struct TournirsDetail: View {
.frame(height: 1)
.padding(.horizontal, 12)

Text("Участники")

List {
HStack {
Text("Участники")
.padding(.leading)

Spacer()

Text("MMR")
.padding(.trailing)
}

ForEach(coordinator.currentTournir!.users, id: \.id) { user in
HStack {
Text(user.phio)
.padding(.leading)

Spacer()

Text(String(Int(user.mmr ?? 0)))
.padding(.trailing)
ScrollView {
ForEach(viewModel.participants, id: \.id) { participant in
Text(participant.name)
.padding()
}
}
}
Expand All @@ -110,6 +101,9 @@ struct TournirsDetail: View {
Spacer()
}
.navigationTitle("О соревновании")
.onAppear() {
viewModel.loadParticipants(for: coordinator.currentTournir!.id.uuidString)
}

}
}
58 changes: 58 additions & 0 deletions SportApp/Tournirs/ViewModel/ParticipantsViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ParticipantsViewModel.swift
// SportApp
//
// Created by user on 09.07.2025.
//

import Foundation
import Combine

@MainActor
class ParticipantsViewModel: ObservableObject {
@Published var participants: [UserDTO] = []

func loadParticipants(for tournamentID: String) {
Task {
do {
participants = try await fetchParticipants(tournamentID: tournamentID)
print(participants)
} catch {
print(error)
}
}
}

func fetchParticipants(tournamentID: String) async throws -> [UserDTO] {
let participantEndpoint = ParticipantEndpoint(tournamentID: tournamentID)
let participantRequest = ParticipantRequest()

var participantResponses = [UserDTO]()
participantResponses = try await NetworkService.shared.request(
endpoint: participantEndpoint,
requestDTO: participantRequest
)

return participantResponses
}
/*
func giveParticipant(participant: Participant) {
Task {
let participantEndpoint = ParticipantPostEndpoint()
let participantRequest = ParticipantPostRequest(participant: participant)

do {
let respone: ParticipantDTO = try await NetworkService.shared.request(
endpoint: participantEndpoint,
requestDTO: participantRequest
)
print(син)
} catch {
print(error)
}
}

*/

}

7 changes: 4 additions & 3 deletions SportApp/Tournirs/ViewModel/TournirsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TournirsViewModel: ObservableObject {
do {
tournirs = try await fetchTournirs()
} catch {
tournirs = loadMockTournirs()
tournirs = []
}
}
}
Expand All @@ -42,7 +42,7 @@ class TournirsViewModel: ObservableObject {
}

let mappedEvents = tournirResponses.map { dto -> Tournir in
Tournir(title: dto.title ?? "Unnamed", description: dto.description ?? "", sport: dto.sport ?? "Chess", type_group: TypeTournir.fromString(dto.typeGroup ?? ""), type_tournir: TypeIsTeam.fromString(dto.typeTournament ?? ""), start_time: Date(), created_at: Date(), entry_cost: Double(dto.entryCost ?? 0), is_team_based: true, place: dto.place ?? "", max_participants: Int(dto.maxParticipants ?? 0), organizer_id: UUID(), requirements: Requirements())
Tournir(id: UUID(uuidString: dto.id) ?? UUID(), title: dto.title ?? "Unnamed", description: dto.description ?? "", sport: dto.sport ?? "Chess", type_group: TypeTournir.fromString(dto.typeGroup ?? ""), type_tournir: TypeIsTeam.fromString(dto.typeTournament ?? ""), start_time: Date(), created_at: Date(), entry_cost: Double(dto.entryCost ?? 0), is_team_based: true, place: dto.place ?? "", max_participants: Int(dto.maxParticipants ?? 0), organizer_id: UUID(), requirements: Requirements())
}
return mappedEvents
}
Expand All @@ -63,7 +63,7 @@ class TournirsViewModel: ObservableObject {
}
}
}

/*
func loadMockTournirs() -> [Tournir] {
let x = [
Tournir(
Expand Down Expand Up @@ -144,4 +144,5 @@ class TournirsViewModel: ObservableObject {
]
return x
}
*/
}
Loading