import 'package:http/http.dart' as http; import 'dart:convert'; import 'package:insparkspokalen_ui/models/teamModel.dart'; import 'package:insparkspokalen_ui/services/teamUserSyncService.dart'; import 'package:insparkspokalen_ui/services/googleAuthService.dart'; class TeamService { final String baseUrlTeam = 'https://group-10-15.pvt.dsv.su.se/team'; final TeamUserSyncService _syncService = TeamUserSyncService(); //final String baseUrl = 'http://localhost:8080'; Future> showTeams() async { // We'll use the sync service to keep team data in sync return await _syncService.fetchAllTeams(); } //Future getGroup(int id) {} Future createTeam(String teamName) async { final url = Uri.parse('$baseUrlTeam/add/$teamName'); // Lagnamnet läggs till i URL print("Debug URL Create = $url"); //final url = Uri.parse('http://localhost:8080/add/team/$teamName'); final response = await http.get(url); if (response.statusCode == 200) { // If team is successfully created, refresh all teams await _syncService.fetchAllTeams(); return true; } return false; } //Ta bort grupp Future removeTeam(int teamId, String teamName) async { final url = Uri.parse('$baseUrlTeam/remove/$teamId'); final response = await http.get(url); if (response.statusCode == 200) { // If team is removed, refresh all teams await _syncService.fetchAllTeams(); return true; } return false; } //Future updateTeam(int id, UpdateGroupModel group) {} // Funktion för att lägga till poäng Future updateScore(int teamId, int scoreChange) async { final url = Uri.parse('$baseUrlTeam/change/$teamId/$scoreChange'); final response = await http.get(url); if (response.statusCode == 200) { // If score is updated, update the specific team await _syncService.fetchTeamById(teamId); return true; } return false; } // Add user to team - now using the sync service Future addUserToTeam(int teamId) async { final user = GoogleAuthService.getCurrentUser(); if (user == null) return false; // Using the sync service to join team return await _syncService.joinTeam(teamId); } getTeamById(teamId) async { final url = Uri.parse('$baseUrlTeam/get-team/$teamId'); final response = await http.get(url); } }