From 73fac61aa00cd9f65eab7b45cc180b1981b2b35b Mon Sep 17 00:00:00 2001 From: kituNew Date: Mon, 14 Jul 2025 00:34:34 +0300 Subject: [PATCH 1/2] last dance --- SportApp/Navigation/Coordinator.swift | 20 ++++++++++++ SportApp/NetworkService/Data/APIRoutes.swift | 3 +- SportApp/NetworkService/NetworkService.swift | 6 ++-- .../View/RegistrationShieldView.swift | 2 +- .../Model/DTO/PostPartisipantEndpoint.swift | 32 +++++++++++++++++++ .../Model/DTO/PostPartisipantRequest.swift | 10 ++++++ .../Model/DTO/Tournir/TournirDTO.swift | 2 ++ .../DTO/Tournir/TournirPostRequest.swift | 11 +++++++ SportApp/Tournirs/Model/Tournir.swift | 10 ++++-- SportApp/Tournirs/View/TournirCell.swift | 2 +- SportApp/Tournirs/View/TournirMaker.swift | 2 +- .../ViewModel/TournirsViewModel.swift | 2 +- 12 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 SportApp/Statistics/Model/DTO/PostPartisipantEndpoint.swift create mode 100644 SportApp/Statistics/Model/DTO/PostPartisipantRequest.swift diff --git a/SportApp/Navigation/Coordinator.swift b/SportApp/Navigation/Coordinator.swift index 5e2dceb..b5971fb 100644 --- a/SportApp/Navigation/Coordinator.swift +++ b/SportApp/Navigation/Coordinator.swift @@ -32,6 +32,7 @@ class Coordinator: ObservableObject { if currentTournir != nil{ print(currentTournir!.users) } + giveTournir() } func updateUser() { @@ -54,4 +55,23 @@ class Coordinator: ObservableObject { } } } + + func giveTournir(userID: String? = nil, tournirID: String? = nil) { + Task { + let tournirID: String = tournirID ?? (currentTournir!.id.uuidString) + let userID: String = userID ?? (user.id.uuidString) + let postPartisipantEndpoint = PostPartisipantEndpoint(userId: userID, tournirId: tournirID) + let postPartisipantRequest = PostPartisipantRequest() + print(postPartisipantEndpoint.path) + do { + let respone: String = try await NetworkService.shared.request( + endpoint: postPartisipantEndpoint, + requestDTO: postPartisipantRequest + ) + print(respone) + } catch { + print(error) + } + } + } } diff --git a/SportApp/NetworkService/Data/APIRoutes.swift b/SportApp/NetworkService/Data/APIRoutes.swift index e9106a7..1183202 100644 --- a/SportApp/NetworkService/Data/APIRoutes.swift +++ b/SportApp/NetworkService/Data/APIRoutes.swift @@ -10,10 +10,11 @@ import Foundation struct APIRoutes { let baseURL = URL(string: "http://51.250.38.151:8082") let userURL = URL(string: "http://51.250.38.151:8081") - let bffURL = URL(string: "http://51.250.38.151:8083") + let bffURL = URL(string: "http://51.250.38.151:8080") let getTournirs: String = "/api/v1/tournaments" let login: String = "/api/v1/auth/login" let register: String = "/api/v1/auth/register" let getUserInfo: String = "/api/v1/users/" let getParticipants: String = "/api/v1/tournaments/{id}/participants" + let postPartisipant: String = "/api/v1/tournaments/{tournamentId}/participants/{participantId}" } diff --git a/SportApp/NetworkService/NetworkService.swift b/SportApp/NetworkService/NetworkService.swift index 402b421..aa08832 100644 --- a/SportApp/NetworkService/NetworkService.swift +++ b/SportApp/NetworkService/NetworkService.swift @@ -73,9 +73,9 @@ final class NetworkService { } -// if let p = urlRequest.httpBody { -// print(String(data: p, encoding: .utf8) ?? "") -// } + if let p = urlRequest.httpBody { + print(String(data: p, encoding: .utf8) ?? "") + } let (data, response) = try await URLSession.shared.data(for: urlRequest) guard let httpResponse = response as? HTTPURLResponse else { diff --git a/SportApp/Registration/View/RegistrationShieldView.swift b/SportApp/Registration/View/RegistrationShieldView.swift index 99819b5..9ecb0be 100644 --- a/SportApp/Registration/View/RegistrationShieldView.swift +++ b/SportApp/Registration/View/RegistrationShieldView.swift @@ -6,7 +6,7 @@ struct RegistrationShieldView: View { @Binding var isAuthenticated: Bool @State var phio: String = "" - @State var email: String = "1@1.ru" + @State var email: String = "GPT@moment.ru" @State var password: String = "" @State var passwordCheck: String = "" @State var isLogInPressed = false diff --git a/SportApp/Statistics/Model/DTO/PostPartisipantEndpoint.swift b/SportApp/Statistics/Model/DTO/PostPartisipantEndpoint.swift new file mode 100644 index 0000000..ed72ad8 --- /dev/null +++ b/SportApp/Statistics/Model/DTO/PostPartisipantEndpoint.swift @@ -0,0 +1,32 @@ +// +// PostPartisipantEndpoint.swift +// SportApp +// +// Created by Zaitsev Vladislav on 13.07.2025. +// + +import Foundation + +struct PostPartisipantEndpoint: Endpoint { + var baseURL = APIRoutes().baseURL + + var userId: String + var tournirId: String + + var path: String + + var method = HTTPMethod.post + + var headers: [String: String]? + + var loginString: String? // = "Admin:hashedpassword" + + var isTokenRequired: Bool = true + + init(userId: String, tournirId: String) { + self.userId = userId + self.tournirId = tournirId + path = APIRoutes().postPartisipant.replacingOccurrences(of: "{participantId}", with: userId).replacingOccurrences(of: "{tournamentId}", with: tournirId) + } +} + diff --git a/SportApp/Statistics/Model/DTO/PostPartisipantRequest.swift b/SportApp/Statistics/Model/DTO/PostPartisipantRequest.swift new file mode 100644 index 0000000..31ee5e0 --- /dev/null +++ b/SportApp/Statistics/Model/DTO/PostPartisipantRequest.swift @@ -0,0 +1,10 @@ +// +// PostPartisipantRequest.swift +// SportApp +// +// Created by Zaitsev Vladislav on 13.07.2025. +// + +struct PostPartisipantRequest: RequestDTO { + +} diff --git a/SportApp/Tournirs/Model/DTO/Tournir/TournirDTO.swift b/SportApp/Tournirs/Model/DTO/Tournir/TournirDTO.swift index e2704f3..9e7d4c9 100644 --- a/SportApp/Tournirs/Model/DTO/Tournir/TournirDTO.swift +++ b/SportApp/Tournirs/Model/DTO/Tournir/TournirDTO.swift @@ -22,6 +22,7 @@ struct TournirDTO: Codable { var registrationDeadline: String? var place: String? var organizedId: String? + var tournirInstantState: String? init(tournir: Tournir) { id = tournir.id.uuidString @@ -33,6 +34,7 @@ struct TournirDTO: Codable { registrationDeadline = nil place = tournir.place organizedId = tournir.organizer_id.uuidString + tournirInstantState = tournir.tournirInstanteState.rawValue } } diff --git a/SportApp/Tournirs/Model/DTO/Tournir/TournirPostRequest.swift b/SportApp/Tournirs/Model/DTO/Tournir/TournirPostRequest.swift index 8522334..2330fa0 100644 --- a/SportApp/Tournirs/Model/DTO/Tournir/TournirPostRequest.swift +++ b/SportApp/Tournirs/Model/DTO/Tournir/TournirPostRequest.swift @@ -21,6 +21,7 @@ struct TournirPostRequest: Encodable { var registrationDeadline: String? var place: String? var organizedId: String + var tournirInstantState: String init(tournir: Tournir) { title = tournir.title @@ -33,5 +34,15 @@ struct TournirPostRequest: Encodable { organizedId = tournir.organizer_id.uuidString typeTournament = TypeIsTeam.toString(tournir.type_tournir) typeGroup = TypeTournir.toString(tournir.type_group) + tournirInstantState = tournir.tournirInstanteState.rawValue + } + + init (title: String, typeGroup: String, typeTournament: String, sport: String, organizedId: String, tournirInstantState: String) { + self.title = title + self.typeGroup = typeGroup + self.sport = sport + self.organizedId = organizedId + self.tournirInstantState = tournirInstantState + self.typeTournament = typeTournament } } diff --git a/SportApp/Tournirs/Model/Tournir.swift b/SportApp/Tournirs/Model/Tournir.swift index 98ea97b..3202e92 100644 --- a/SportApp/Tournirs/Model/Tournir.swift +++ b/SportApp/Tournirs/Model/Tournir.swift @@ -25,7 +25,7 @@ struct Tournir: Codable, Identifiable, Hashable { var requirements: Requirements var tournirInstanteState: TournirInstaseState var currentMatch: Int = 0 - let matchs: Int + var matchs: Int var winner: User? init( @@ -62,7 +62,13 @@ struct Tournir: Codable, Identifiable, Hashable { self.organizer_id = organizer_id self.users = users self.requirements = requirements - self.matchs = Int(ceil(log2(Double(max_participants)))) + self.matchs = 0 + if max_participants > 0 { + let logValue = log2(Double(max_participants)) + if logValue.isFinite { + matchs = Int(ceil(logValue)) + } + } self.tournirInstanteState = tournirInstaseState self.max_participants = nextPowerOfTwo(max_participants) diff --git a/SportApp/Tournirs/View/TournirCell.swift b/SportApp/Tournirs/View/TournirCell.swift index 864428e..cc36b42 100644 --- a/SportApp/Tournirs/View/TournirCell.swift +++ b/SportApp/Tournirs/View/TournirCell.swift @@ -20,7 +20,7 @@ struct TournirCell: View { var body: some View { VStack { HStack { - Text(tournir.title) + Text(tournir.title == "" ? "Без названия" : tournir.title) .font(.system(size: 20, weight: .bold)) .lineLimit(1) .padding(.trailing, 30) diff --git a/SportApp/Tournirs/View/TournirMaker.swift b/SportApp/Tournirs/View/TournirMaker.swift index 347c13f..85c3aae 100644 --- a/SportApp/Tournirs/View/TournirMaker.swift +++ b/SportApp/Tournirs/View/TournirMaker.swift @@ -177,7 +177,7 @@ struct TournirMaker: View { Spacer() Button(action: { - 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: 16, organizer_id: coordinator.user.id, 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: 16, organizer_id: coordinator.user.id, requirements: Requirements(), tournirInstaseState: .openedRegistrationTournaments) viewModel.tournirs.append(tourinr) viewModel.giveTournir(tournir: tourinr) coordinator.dismissSheet() diff --git a/SportApp/Tournirs/ViewModel/TournirsViewModel.swift b/SportApp/Tournirs/ViewModel/TournirsViewModel.swift index dda844f..35d8f57 100644 --- a/SportApp/Tournirs/ViewModel/TournirsViewModel.swift +++ b/SportApp/Tournirs/ViewModel/TournirsViewModel.swift @@ -45,7 +45,7 @@ class TournirsViewModel: ObservableObject { } let mappedEvents = tournirResponses.map { dto -> Tournir in - 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(uuidString: dto.organizedId ?? "") ?? 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(uuidString: dto.organizedId ?? "") ?? UUID(), requirements: Requirements()/*, tournirInstaseState: dto.tournirInstantState*/) } return mappedEvents } From 98b31588a7de716fc2d049cffe2d5d984f3058c7 Mon Sep 17 00:00:00 2001 From: kituNew Date: Mon, 14 Jul 2025 13:02:59 +0300 Subject: [PATCH 2/2] pop --- SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift | 4 ++-- SportApp/Registration/Model/User.swift | 2 +- SportApp/Registration/ViewModel/RegistrationViewModel.swift | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift b/SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift index 8c07a69..b3447c6 100644 --- a/SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift +++ b/SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift @@ -14,7 +14,7 @@ struct UserDTO: Codable { var patronymic: String? var phoneNumber: String? var email: String - var hashedPassword: String + var hashedPassword: String? var dateOfBirth: String? var age: Int? var sex: String? @@ -28,7 +28,7 @@ struct UserDTO: Codable { init(user: User) { self.id = user.id.uuidString self.email = user.email - self.hashedPassword = user.password + //self.hashedPassword = user.password self.admin = user.isAdmin let components = user.phio.split(separator: " ", omittingEmptySubsequences: false) diff --git a/SportApp/Registration/Model/User.swift b/SportApp/Registration/Model/User.swift index 83e2c54..adf70b8 100644 --- a/SportApp/Registration/Model/User.swift +++ b/SportApp/Registration/Model/User.swift @@ -36,7 +36,7 @@ struct User: Identifiable, Hashable, Codable { self.phio = fullName self.phone = dto.phoneNumber - self.password = dto.hashedPassword + self.password = "" self.email = dto.email self.dateOfBirth = Self.dateFormatter.date(from: dto.dateOfBirth ?? "") self.age = dto.age diff --git a/SportApp/Registration/ViewModel/RegistrationViewModel.swift b/SportApp/Registration/ViewModel/RegistrationViewModel.swift index 0b61c6f..44132d5 100644 --- a/SportApp/Registration/ViewModel/RegistrationViewModel.swift +++ b/SportApp/Registration/ViewModel/RegistrationViewModel.swift @@ -72,9 +72,9 @@ class RegistrationViewModel: ObservableObject { await MainActor.run { self.token = newToken - //print(self.token ?? "nil") + print(self.token ?? "nil") NetworkService.shared.token = token - KeyСhainManager.shared.saveToken(newToken) + //KeyСhainManager.shared.saveToken(newToken) //UserDefaults.standard.set(newToken, forKey: "auth_token") //JWTDecodeFunc(jwt: newToken) //print(getTokenExpiration(newToken))