temporary update
This commit is contained in:
@ -61,7 +61,7 @@ class ApiService extends GetxService{
|
||||
final indexController = Get.find<IndexController>();
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
token = indexController.currentUser[0]['token'] ?? '';
|
||||
print("Get token = $token");
|
||||
//print("Get token = $token");
|
||||
}else{
|
||||
token = "";
|
||||
}
|
||||
@ -77,7 +77,7 @@ class ApiService extends GetxService{
|
||||
final indexController = Get.find<IndexController>();
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
token = indexController.currentUser[0]['token'] ?? '';
|
||||
print("Get token = $token");
|
||||
//print("Get token = $token");
|
||||
}else{
|
||||
token = "";
|
||||
}
|
||||
@ -87,7 +87,7 @@ class ApiService extends GetxService{
|
||||
Future<dynamic> _handleRequest(Future<http.Response> Function() request) async {
|
||||
try {
|
||||
final response = await request();
|
||||
if (response.statusCode == 200) {
|
||||
if (response.statusCode == 200 || response.statusCode == 201 ) {
|
||||
return json.decode(utf8.decode(response.bodyBytes));
|
||||
} else if (response.statusCode == 401) {
|
||||
await _handleUnauthorized();
|
||||
@ -117,42 +117,6 @@ class ApiService extends GetxService{
|
||||
}
|
||||
|
||||
|
||||
Future<List<Team>> getTeams_old() async {
|
||||
init();
|
||||
final token = await getToken2();
|
||||
|
||||
try {
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/teams/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// UTF-8でデコード
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
//print('User Response body: $decodedResponse');
|
||||
List<dynamic> teamsJson = json.decode(decodedResponse);
|
||||
|
||||
List<Team> teams = [];
|
||||
for (var teamJson in teamsJson) {
|
||||
//print('\nTeam Data:');
|
||||
//_printDataComparison(teamJson, Team);
|
||||
teams.add(Team.fromJson(teamJson));
|
||||
}
|
||||
return teams;
|
||||
} else {
|
||||
throw Exception('Failed to load teams. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('Error in getTeams: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<List<NewCategory>> getCategories() async {
|
||||
init();
|
||||
getToken();
|
||||
@ -165,7 +129,7 @@ class ApiService extends GetxService{
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
//print('User Response body: $decodedResponse');
|
||||
List<dynamic> categoriesJson = json.decode(decodedResponse);
|
||||
|
||||
List<NewCategory> categories = [];
|
||||
@ -200,26 +164,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => NewCategory.fromJson(data));
|
||||
}
|
||||
|
||||
Future<NewCategory> getZekkenNumber_old(int categoryId) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/categories-viewset/$categoryId/get_zekken_number/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
final categoriesJson = json.decode(decodedResponse);
|
||||
|
||||
return NewCategory.fromJson(categoriesJson);
|
||||
} else {
|
||||
throw Exception('Failed to increment category number');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Error incrementing category number: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> getCurrentUser() async {
|
||||
init();
|
||||
final token = getToken();
|
||||
@ -324,30 +268,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => Team.fromJson(data));
|
||||
}
|
||||
|
||||
Future<Team> createTeam_old(String teamName, int categoryId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/teams/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
},
|
||||
body: json.encode({
|
||||
'team_name': teamName,
|
||||
'category': categoryId,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return Team.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to create team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Team> updateTeam(int teamId, String teamName, int categoryId) async {
|
||||
final token = await getToken2();
|
||||
return _handleRequest(() => http.put(
|
||||
@ -357,31 +277,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => Team.fromJson(data));
|
||||
}
|
||||
|
||||
Future<Team> updateTeam_old(int teamId, String teamName, int categoryId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/teams/$teamId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team_name': teamName,
|
||||
'category': categoryId,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
|
||||
return Team.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to update team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteTeam(int teamId) async {
|
||||
final token = await getToken2();
|
||||
await _handleRequest(() => http.delete(
|
||||
@ -390,24 +285,6 @@ class ApiService extends GetxService{
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> deleteTeamold_(int teamId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/'),
|
||||
headers: {'Authorization': 'Token $token','Content-Type': 'application/json; charset=UTF-8'},
|
||||
);
|
||||
|
||||
if( response.statusCode == 400) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
throw Exception('まだメンバーが残っているので、チームを削除できません。');
|
||||
}else if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<User>> getTeamMembers(int teamId) async {
|
||||
final token = await getToken2();
|
||||
return _handleRequest(() => http.get(
|
||||
@ -416,26 +293,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => (data as List).map((json) => User.fromJson(json)).toList());
|
||||
}
|
||||
|
||||
Future<List<User>> getTeamMembers_old(int teamId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/'),
|
||||
headers: {'Authorization': 'Token $token','Content-Type': 'application/json; charset=UTF-8'},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
List<dynamic> membersJson = json.decode(decodedResponse);
|
||||
|
||||
return membersJson.map((json) => User.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load team members');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> createTeamMember(int teamId, String? email, String? firstname, String? lastname, DateTime? dateOfBirth, bool? female) async {
|
||||
final token = await getToken2();
|
||||
String? formattedDateOfBirth = dateOfBirth != null ? DateFormat('yyyy-MM-dd').format(dateOfBirth) : null;
|
||||
@ -452,45 +309,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => User.fromJson(data));
|
||||
}
|
||||
|
||||
Future<User> createTeamMember_old(int teamId, String? email, String? firstname, String? lastname, DateTime? dateOfBirth,bool? female) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
// emailが値を持っている場合の処理
|
||||
if (email != null && email.isNotEmpty) {
|
||||
firstname ??= "dummy";
|
||||
lastname ??= "dummy";
|
||||
dateOfBirth ??= DateTime.now();
|
||||
female ??= false;
|
||||
}
|
||||
|
||||
String? formattedDateOfBirth;
|
||||
if (dateOfBirth != null) {
|
||||
formattedDateOfBirth = DateFormat('yyyy-MM-dd').format(dateOfBirth);
|
||||
}
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'email': email,
|
||||
'firstname': firstname,
|
||||
'lastname': lastname,
|
||||
'date_of_birth': formattedDateOfBirth,
|
||||
'female': female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return User.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to create team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> updateTeamMember(int teamId, int? memberId, String firstname, String lastname, DateTime? dateOfBirth, bool? female) async {
|
||||
final token = await getToken2();
|
||||
@ -507,37 +325,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => User.fromJson(data));
|
||||
}
|
||||
|
||||
Future<User> updateTeamMember_old(int teamId,int? memberId, String firstname, String lastname, DateTime? dateOfBirth,bool? female) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
String? formattedDateOfBirth;
|
||||
if (dateOfBirth != null) {
|
||||
formattedDateOfBirth = DateFormat('yyyy-MM-dd').format(dateOfBirth);
|
||||
}
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/$memberId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'firstname': firstname,
|
||||
'lastname': lastname,
|
||||
'date_of_birth': formattedDateOfBirth,
|
||||
'female': female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return User.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to update team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteTeamMember(int teamId, int memberId) async {
|
||||
final token = await getToken2();
|
||||
await _handleRequest(() => http.delete(
|
||||
@ -546,20 +333,6 @@ class ApiService extends GetxService{
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> deleteTeamMember_old(int teamId,int memberId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/$memberId/'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllTeamMembers(int teamId) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/destroy_all/?confirm=true'),
|
||||
@ -594,24 +367,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => (data as List).map((json) => Entry.fromJson(json)).toList());
|
||||
}
|
||||
|
||||
Future<List<Entry>> getEntries_old() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/entry/'),
|
||||
headers: {'Authorization': 'Token $token', 'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
List<dynamic> entriesJson = json.decode(decodedResponse);
|
||||
return entriesJson.map((json) => Entry.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load entries');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Entry>> getTeamEntries(int teamId) async {
|
||||
try {
|
||||
@ -632,6 +387,21 @@ class ApiService extends GetxService{
|
||||
}
|
||||
}
|
||||
|
||||
Future<Entry> updateEntryStatus(int entryId, bool hasParticipated, bool hasGoaled) async {
|
||||
final token = await getToken2();
|
||||
return _handleRequest(() => http.patch(
|
||||
Uri.parse('$baseUrl/entries/$entryId/update-status/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8'
|
||||
},
|
||||
body: json.encode({
|
||||
'hasParticipated': hasParticipated,
|
||||
'hasGoaled': hasGoaled,
|
||||
}),
|
||||
)).then((data) => Entry.fromJson(data));
|
||||
}
|
||||
|
||||
Future<List<Event>> getEvents() async {
|
||||
init();
|
||||
getToken();
|
||||
@ -669,39 +439,6 @@ class ApiService extends GetxService{
|
||||
)).then((data) => Entry.fromJson(data));
|
||||
}
|
||||
|
||||
Future<Entry> createEntry_old(int teamId, int eventId, int categoryId, DateTime date,String zekkenNumber) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
String? formattedDate;
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(date);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/entry/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team': teamId,
|
||||
'event': eventId,
|
||||
'category': categoryId,
|
||||
'date': formattedDate,
|
||||
'zekken_number':zekkenNumber,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
|
||||
return Entry.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print("decodedResponse = $decodedResponse");
|
||||
final errorInfo = json.decode(decodedResponse);
|
||||
throw Exception(errorInfo['error']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateUserInfo(int userId, Entry entry) async {
|
||||
final token = await getToken2();
|
||||
@ -719,40 +456,6 @@ class ApiService extends GetxService{
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> updateUserInfo_old(int userId, Entry entry) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final entryId = entry.id;
|
||||
|
||||
DateTime? date = entry.date;
|
||||
String? formattedDate;
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(date!);
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/userinfo/$userId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'zekken_number': entry.zekkenNumber,
|
||||
'event_code': entry.event.eventName,
|
||||
'group': entry.team.category.categoryName,
|
||||
'team_name': entry.team.teamName,
|
||||
'date': formattedDate,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
final updatedUserInfo = json.decode(decodedResponse);
|
||||
//Get.find<IndexController>().updateUserInfo(updatedUserInfo);
|
||||
|
||||
} else {
|
||||
throw Exception('Failed to update entry');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<Entry> updateEntry(int entryId, int teamId, int eventId, int categoryId, DateTime date,int zekkenNumber) async {
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user