공개페이지
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
class PublicEvent {
|
||||
final String id;
|
||||
final String title;
|
||||
final String? description;
|
||||
final String? eventType;
|
||||
final DateTime? startDate;
|
||||
final DateTime? endDate;
|
||||
final String? location;
|
||||
final int gameCount;
|
||||
final DateTime? registrationDeadline;
|
||||
final int? maxParticipants;
|
||||
final num? participantFee;
|
||||
final String? status;
|
||||
|
||||
PublicEvent({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.eventType,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
this.location,
|
||||
required this.gameCount,
|
||||
this.registrationDeadline,
|
||||
this.maxParticipants,
|
||||
this.participantFee,
|
||||
this.status,
|
||||
});
|
||||
|
||||
factory PublicEvent.fromJson(Map<String, dynamic> json) {
|
||||
String parseId(dynamic v) => v?.toString() ?? '';
|
||||
DateTime? parseDate(dynamic v) {
|
||||
if (v == null) return null;
|
||||
final s = v.toString();
|
||||
return DateTime.tryParse(s);
|
||||
}
|
||||
|
||||
int parseInt(dynamic v, {int def = 0}) {
|
||||
if (v == null) return def;
|
||||
if (v is int) return v;
|
||||
return int.tryParse(v.toString()) ?? def;
|
||||
}
|
||||
|
||||
num? parseNum(dynamic v) {
|
||||
if (v == null) return null;
|
||||
if (v is num) return v;
|
||||
return num.tryParse(v.toString());
|
||||
}
|
||||
|
||||
return PublicEvent(
|
||||
id: parseId(json['id']),
|
||||
title: (json['title'] ?? '').toString(),
|
||||
description: json['description']?.toString(),
|
||||
eventType: json['eventType']?.toString(),
|
||||
startDate: parseDate(json['startDate']),
|
||||
endDate: parseDate(json['endDate']),
|
||||
location: json['location']?.toString(),
|
||||
gameCount: parseInt(json['gameCount'], def: 3),
|
||||
registrationDeadline: parseDate(json['registrationDeadline']),
|
||||
maxParticipants: json['maxParticipants'] == null ? null : parseInt(json['maxParticipants']),
|
||||
participantFee: parseNum(json['participantFee']),
|
||||
status: json['status']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
bool get isReady => (status == 'ready');
|
||||
bool get isActive => (status == 'active');
|
||||
bool get isFinished => (status == 'completed');
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
class PublicParticipant {
|
||||
final String participantId;
|
||||
final String? memberId;
|
||||
final String name;
|
||||
final String? gender;
|
||||
final String? memberType;
|
||||
final num? average;
|
||||
final int handicap;
|
||||
final String? status;
|
||||
final String? paymentStatus;
|
||||
final String? comment;
|
||||
final bool isGuest;
|
||||
// 점수는 서버에서 number 또는 {score, handicap} 객체로 올 수 있음
|
||||
// rawScores: 입력 점수(핸디캡 제외)
|
||||
// handicaps: 각 게임 핸디캡(없으면 0)
|
||||
final List<int?> rawScores;
|
||||
final List<int> handicaps;
|
||||
|
||||
PublicParticipant({
|
||||
required this.participantId,
|
||||
required this.memberId,
|
||||
required this.name,
|
||||
required this.gender,
|
||||
required this.memberType,
|
||||
required this.average,
|
||||
required this.handicap,
|
||||
required this.status,
|
||||
required this.paymentStatus,
|
||||
required this.comment,
|
||||
required this.isGuest,
|
||||
required this.rawScores,
|
||||
required this.handicaps,
|
||||
});
|
||||
|
||||
factory PublicParticipant.fromJson(Map<String, dynamic> json, {int gameCount = 3}) {
|
||||
int parseInt(dynamic v, {int def = 0}) {
|
||||
if (v == null) return def;
|
||||
if (v is int) return v;
|
||||
return int.tryParse(v.toString()) ?? def;
|
||||
}
|
||||
num? parseNum(dynamic v) {
|
||||
if (v == null) return null;
|
||||
if (v is num) return v;
|
||||
return num.tryParse(v.toString());
|
||||
}
|
||||
|
||||
final List<dynamic> src = (json['scores'] is List) ? (json['scores'] as List) : const [];
|
||||
final List<int?> raw = List<int?>.filled(gameCount, null);
|
||||
final List<int> hcs = List<int>.filled(gameCount, 0);
|
||||
for (int i = 0; i < src.length && i < gameCount; i++) {
|
||||
final el = src[i];
|
||||
if (el == null) {
|
||||
raw[i] = null;
|
||||
hcs[i] = 0;
|
||||
} else if (el is num) {
|
||||
raw[i] = el.toInt();
|
||||
hcs[i] = 0;
|
||||
} else if (el is Map) {
|
||||
final score = el['score'];
|
||||
final hc = el['handicap'];
|
||||
raw[i] = (score is num) ? score.toInt() : int.tryParse(score?.toString() ?? '');
|
||||
hcs[i] = (hc is num) ? hc.toInt() : (int.tryParse(hc?.toString() ?? '') ?? 0);
|
||||
} else {
|
||||
raw[i] = int.tryParse(el.toString());
|
||||
hcs[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
final dynamic pidRaw = json['participantId'];
|
||||
final String pid = (pidRaw != null && pidRaw.toString().isNotEmpty)
|
||||
? pidRaw.toString()
|
||||
: (json['id']?.toString() ?? '');
|
||||
|
||||
return PublicParticipant(
|
||||
participantId: pid,
|
||||
memberId: json['memberId']?.toString(),
|
||||
name: (json['name'] ?? '이름없음').toString(),
|
||||
gender: json['gender']?.toString(),
|
||||
memberType: json['memberType']?.toString(),
|
||||
average: parseNum(json['average']),
|
||||
handicap: parseInt(json['handicap'], def: 0),
|
||||
status: json['status']?.toString(),
|
||||
paymentStatus: json['paymentStatus']?.toString(),
|
||||
comment: json['comment']?.toString(),
|
||||
isGuest: json['isGuest'] == true,
|
||||
rawScores: raw,
|
||||
handicaps: hcs,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
class PublicTeamMemberSummary {
|
||||
final String? participantId;
|
||||
final String? memberId;
|
||||
final String name;
|
||||
final List<int?> rawScores;
|
||||
final List<int> handicaps;
|
||||
|
||||
PublicTeamMemberSummary({
|
||||
required this.participantId,
|
||||
required this.memberId,
|
||||
required this.name,
|
||||
required this.rawScores,
|
||||
required this.handicaps,
|
||||
});
|
||||
|
||||
factory PublicTeamMemberSummary.fromJson(Map<String, dynamic> json, {int gameCount = 3}) {
|
||||
final participantId = json['participantId']?.toString();
|
||||
final memberId = json['memberId']?.toString();
|
||||
final name = (json['name'] ?? '이름없음').toString();
|
||||
// 점수 포맷은 PublicParticipant와 동일 규칙
|
||||
final List<dynamic> src = (json['scores'] is List) ? (json['scores'] as List) : const [];
|
||||
final List<int?> raw = List<int?>.filled(gameCount, null);
|
||||
final List<int> hcs = List<int>.filled(gameCount, 0);
|
||||
for (int i = 0; i < src.length && i < gameCount; i++) {
|
||||
final el = src[i];
|
||||
if (el == null) {
|
||||
raw[i] = null;
|
||||
hcs[i] = 0;
|
||||
} else if (el is num) {
|
||||
raw[i] = el.toInt();
|
||||
hcs[i] = 0;
|
||||
} else if (el is Map) {
|
||||
final score = el['score'];
|
||||
final hc = el['handicap'];
|
||||
raw[i] = (score is num) ? score.toInt() : int.tryParse(score?.toString() ?? '');
|
||||
hcs[i] = (hc is num) ? hc.toInt() : (int.tryParse(hc?.toString() ?? '') ?? 0);
|
||||
} else {
|
||||
raw[i] = int.tryParse(el.toString());
|
||||
hcs[i] = 0;
|
||||
}
|
||||
}
|
||||
return PublicTeamMemberSummary(
|
||||
participantId: participantId,
|
||||
memberId: memberId,
|
||||
name: name,
|
||||
rawScores: raw,
|
||||
handicaps: hcs,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PublicTeam {
|
||||
final String teamId;
|
||||
final int teamNumber;
|
||||
final int handicap; // 팀 핸디캡
|
||||
final List<PublicTeamMemberSummary> members;
|
||||
|
||||
PublicTeam({
|
||||
required this.teamId,
|
||||
required this.teamNumber,
|
||||
required this.handicap,
|
||||
required this.members,
|
||||
});
|
||||
|
||||
factory PublicTeam.fromJson(Map<String, dynamic> json, {int gameCount = 3}) {
|
||||
int parseInt(dynamic v, {int def = 0}) {
|
||||
if (v == null) return def;
|
||||
if (v is int) return v;
|
||||
return int.tryParse(v.toString()) ?? def;
|
||||
}
|
||||
final List<dynamic> mem = (json['members'] is List) ? (json['members'] as List) : const [];
|
||||
return PublicTeam(
|
||||
teamId: (json['teamId'] ?? json['id'] ?? '').toString(),
|
||||
teamNumber: parseInt(json['teamNumber'], def: 0),
|
||||
handicap: parseInt(json['handicap'], def: 0),
|
||||
members: mem.map((e) => PublicTeamMemberSummary.fromJson((e as Map).cast<String, dynamic>(), gameCount: gameCount)).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user