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
20 changes: 20 additions & 0 deletions SportApp/Navigation/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Coordinator: ObservableObject {
if currentTournir != nil{
print(currentTournir!.users)
}
giveTournir()
}

func updateUser() {
Expand All @@ -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)
}
}
}
}
3 changes: 2 additions & 1 deletion SportApp/NetworkService/Data/APIRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id>"
let getParticipants: String = "/api/v1/tournaments/{id}/participants"
let postPartisipant: String = "/api/v1/tournaments/{tournamentId}/participants/{participantId}"
}
6 changes: 3 additions & 3 deletions SportApp/NetworkService/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions SportApp/Registration/Model/DTO/User/GetUser/UserDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion SportApp/Registration/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion SportApp/Registration/View/RegistrationShieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions SportApp/Registration/ViewModel/RegistrationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 32 additions & 0 deletions SportApp/Statistics/Model/DTO/PostPartisipantEndpoint.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

10 changes: 10 additions & 0 deletions SportApp/Statistics/Model/DTO/PostPartisipantRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// PostPartisipantRequest.swift
// SportApp
//
// Created by Zaitsev Vladislav on 13.07.2025.
//

struct PostPartisipantRequest: RequestDTO {

}
2 changes: 2 additions & 0 deletions SportApp/Tournirs/Model/DTO/Tournir/TournirDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,7 @@ struct TournirDTO: Codable {
registrationDeadline = nil
place = tournir.place
organizedId = tournir.organizer_id.uuidString
tournirInstantState = tournir.tournirInstanteState.rawValue
}
}

Expand Down
11 changes: 11 additions & 0 deletions SportApp/Tournirs/Model/DTO/Tournir/TournirPostRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
10 changes: 8 additions & 2 deletions SportApp/Tournirs/Model/Tournir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion SportApp/Tournirs/View/TournirCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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(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()
Expand Down
2 changes: 1 addition & 1 deletion SportApp/Tournirs/ViewModel/TournirsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading