ほぼ完成:QRcodeトライ
This commit is contained in:
@ -75,13 +75,13 @@ class ApiService extends GetxService{
|
||||
if (response.statusCode == 200) {
|
||||
// UTF-8でデコード
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
//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);
|
||||
//print('\nTeam Data:');
|
||||
//_printDataComparison(teamJson, Team);
|
||||
teams.add(Team.fromJson(teamJson));
|
||||
}
|
||||
return teams;
|
||||
@ -114,8 +114,8 @@ class ApiService extends GetxService{
|
||||
|
||||
List<NewCategory> categories = [];
|
||||
for (var categoryJson in categoriesJson) {
|
||||
print('\nCategory Data:');
|
||||
_printDataComparison(categoryJson, NewCategory);
|
||||
//print('\nCategory Data:');
|
||||
//_printDataComparison(categoryJson, NewCategory);
|
||||
categories.add(NewCategory.fromJson(categoryJson));
|
||||
}
|
||||
|
||||
@ -143,11 +143,11 @@ class ApiService extends GetxService{
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
//print('User Response body: $decodedResponse');
|
||||
final jsonData = json.decode(decodedResponse);
|
||||
|
||||
print('\nUser Data Comparison:');
|
||||
_printDataComparison(jsonData, User);
|
||||
//print('\nUser Data Comparison:');
|
||||
//_printDataComparison(jsonData, User);
|
||||
|
||||
return User.fromJson(jsonData);
|
||||
} else {
|
||||
@ -277,7 +277,11 @@ class ApiService extends GetxService{
|
||||
headers: {'Authorization': 'Token $token','Content-Type': 'application/json; charset=UTF-8'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 204) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
@ -302,10 +306,18 @@ class ApiService extends GetxService{
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> createTeamMember(int teamId, String? email, String firstname, String lastname, DateTime? dateOfBirth,bool? female) async {
|
||||
Future<User> createTeamMember(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);
|
||||
@ -379,6 +391,17 @@ class ApiService extends GetxService{
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllTeamMembers(int teamId) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/destroy_all/?confirm=true'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to delete team members');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resendMemberInvitation(int memberId) async {
|
||||
init();
|
||||
getToken();
|
||||
@ -503,7 +526,7 @@ class ApiService extends GetxService{
|
||||
}
|
||||
|
||||
|
||||
Future<Entry> updateEntry(int entryId, int eventId, int categoryId, DateTime date) async {
|
||||
Future<Entry> updateEntry(int entryId, int teamId, int eventId, int categoryId, DateTime date) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
@ -519,6 +542,7 @@ class ApiService extends GetxService{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team': teamId,
|
||||
'event': eventId,
|
||||
'category': categoryId,
|
||||
'date': formattedDate,
|
||||
@ -547,4 +571,41 @@ class ApiService extends GetxService{
|
||||
throw Exception('Failed to delete entry');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> updateUserDetail(User user, String token) async {
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
int? userid = user.id;
|
||||
String url = '$serverUrl/api/userdetail/$userid/';
|
||||
|
||||
try {
|
||||
String? formattedDate;
|
||||
if (user.dateOfBirth != null) {
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(user.dateOfBirth!);
|
||||
}
|
||||
final http.Response response = await http.put(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'firstname': user.firstname,
|
||||
'lastname': user.lastname,
|
||||
'date_of_birth': formattedDate,
|
||||
'female': user.female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
print('Update failed with status code: ${response.statusCode}');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in updateUserDetail: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user