Initial commit: Flutter app + PHP/MySQL backend on Hostinger
Replaces Firebase with a self-hosted PHP/MySQL API served from winded.prymsolutions.com. Includes full backend (schema, auth, events, teams, brackets, suggestions, stats, media, file upload) and updated Flutter repositories and domain models. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../domain/join_request.dart';
|
||||
import '../domain/team.dart';
|
||||
|
||||
part 'teams_repository.g.dart';
|
||||
|
||||
class TeamsRepository {
|
||||
TeamsRepository(this._api);
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
Future<List<Team>> fetchTeams({bool adminAll = false}) async {
|
||||
final params = adminAll ? <String, String>{'all': '1'} : null;
|
||||
final data = await _api.get('/teams/index.php', params: params);
|
||||
final list = (data['teams'] as List?) ?? [];
|
||||
return list.whereType<Map<String, dynamic>>().map(Team.fromJson).toList();
|
||||
}
|
||||
|
||||
Future<Team?> getTeam(String id) async {
|
||||
try {
|
||||
final data = await _api.get('/teams/detail.php', params: {'id': id});
|
||||
return Team.fromJson(data);
|
||||
} on ApiException catch (e) {
|
||||
if (e.statusCode == 404) return null;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> createTeam(Team team) async {
|
||||
final data = await _api.post('/teams/index.php', team.toJson());
|
||||
return data['id'] as String;
|
||||
}
|
||||
|
||||
Future<Team> updateTeam(Team team) async {
|
||||
final data = await _api.put(
|
||||
'/teams/detail.php',
|
||||
team.toJson(),
|
||||
params: {'id': team.id},
|
||||
);
|
||||
return Team.fromJson(data);
|
||||
}
|
||||
|
||||
Future<void> updateTeamStatus(String teamId, String status) async {
|
||||
await _api.put('/teams/detail.php', {'status': status}, params: {'id': teamId});
|
||||
}
|
||||
|
||||
Future<void> deleteTeam(String id) async {
|
||||
await _api.delete('/teams/detail.php', params: {'id': id});
|
||||
}
|
||||
|
||||
Future<String> submitJoinRequest({
|
||||
required String teamId,
|
||||
required String teamName,
|
||||
required String playerId,
|
||||
required String playerName,
|
||||
required String playerEmail,
|
||||
}) async {
|
||||
final data = await _api.post('/teams/join_requests.php', {
|
||||
'team_id': teamId,
|
||||
'team_name': teamName,
|
||||
'player_name': playerName,
|
||||
'player_email': playerEmail,
|
||||
});
|
||||
return data['id'] as String;
|
||||
}
|
||||
|
||||
Future<List<JoinRequest>> fetchJoinRequestsForTeam(String teamId) async {
|
||||
final data = await _api.get(
|
||||
'/teams/join_requests.php',
|
||||
params: {'team_id': teamId},
|
||||
);
|
||||
final list = (data['requests'] as List?) ?? [];
|
||||
return list.whereType<Map<String, dynamic>>().map(JoinRequest.fromJson).toList();
|
||||
}
|
||||
|
||||
Future<List<JoinRequest>> fetchJoinRequestsForPlayer(String playerId) async {
|
||||
final data = await _api.get(
|
||||
'/teams/join_requests.php',
|
||||
params: {'player_id': playerId},
|
||||
);
|
||||
final list = (data['requests'] as List?) ?? [];
|
||||
return list.whereType<Map<String, dynamic>>().map(JoinRequest.fromJson).toList();
|
||||
}
|
||||
|
||||
Future<void> updateJoinRequestStatus(String requestId, String status) async {
|
||||
await _api.put(
|
||||
'/teams/join_requests.php',
|
||||
{'id': requestId, 'status': status},
|
||||
params: {'id': requestId},
|
||||
);
|
||||
}
|
||||
|
||||
Stream<List<Team>> watchTeams() async* {
|
||||
yield await fetchTeams();
|
||||
await for (final _ in Stream<void>.periodic(const Duration(seconds: 30))) {
|
||||
yield await fetchTeams();
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<Team>> adminWatchAllTeams() async* {
|
||||
yield await fetchTeams(adminAll: true);
|
||||
await for (final _ in Stream<void>.periodic(const Duration(seconds: 30))) {
|
||||
yield await fetchTeams(adminAll: true);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<JoinRequest>> watchJoinRequestsForTeam(String teamId) async* {
|
||||
yield await fetchJoinRequestsForTeam(teamId);
|
||||
await for (final _ in Stream<void>.periodic(const Duration(seconds: 30))) {
|
||||
yield await fetchJoinRequestsForTeam(teamId);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<JoinRequest>> watchJoinRequestsForPlayer(String playerId) async* {
|
||||
yield await fetchJoinRequestsForPlayer(playerId);
|
||||
await for (final _ in Stream<void>.periodic(const Duration(seconds: 30))) {
|
||||
yield await fetchJoinRequestsForPlayer(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
TeamsRepository teamsRepository(TeamsRepositoryRef ref) {
|
||||
return TeamsRepository(ref.watch(apiClientProvider));
|
||||
}
|
||||
|
||||
@riverpod
|
||||
Stream<List<Team>> teamsStream(TeamsStreamRef ref) {
|
||||
return ref.watch(teamsRepositoryProvider).watchTeams();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'teams_repository.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$teamsRepositoryHash() => r'eb7ca229935756d7a761b8dd59a29ffe6238c841';
|
||||
|
||||
/// See also [teamsRepository].
|
||||
@ProviderFor(teamsRepository)
|
||||
final teamsRepositoryProvider = Provider<TeamsRepository>.internal(
|
||||
teamsRepository,
|
||||
name: r'teamsRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$teamsRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef TeamsRepositoryRef = ProviderRef<TeamsRepository>;
|
||||
String _$teamsStreamHash() => r'1a8b1558c8b4419188620e8a0a11f63260cd382c';
|
||||
|
||||
/// Stream of teams surfaced to the UI. Currently emits the mock list as a
|
||||
/// single tick — swap to `ref.watch(teamsRepositoryProvider).watchTeams()`
|
||||
/// once Firestore is seeded.
|
||||
///
|
||||
/// Copied from [teamsStream].
|
||||
@ProviderFor(teamsStream)
|
||||
final teamsStreamProvider = AutoDisposeStreamProvider<List<Team>>.internal(
|
||||
teamsStream,
|
||||
name: r'teamsStreamProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$teamsStreamHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef TeamsStreamRef = AutoDisposeStreamProviderRef<List<Team>>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
Reference in New Issue
Block a user