ほぼ完成:QRcodeトライ

This commit is contained in:
2024-08-01 20:08:12 +09:00
parent 3d7a5ae0c1
commit ee007795b9
25 changed files with 3214 additions and 1121 deletions

View File

@ -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;
}
}
}

View File

@ -5,6 +5,9 @@ import 'package:get/get.dart';
import 'package:flutter/material.dart';
import '../utils/const.dart';
//import 'package:rogapp/services/team_service.dart';
//import 'package:rogapp/services/member_service.dart';
class AuthService {
Future<AuthUser?> userLogin(String email, String password) async {
@ -131,6 +134,22 @@ class AuthService {
// ユーザー登録
//
/*
Future<void> registerUser(String email, String password, bool isFemale) async {
final user = await register(email, password);
if (user != null) {
final _teamController = TeamController();
_teamController.createTeam(String teamName, int categoryId) ;
final teamService = TeamService();
final memberService = MemberService();
final team = await teamService.createSoloTeam(user.id, isFemale);
await memberService.addMember(team.id, user.id);
}
}
*/
static Future<Map<String, dynamic>> register(
String email, String password) async {
Map<String, dynamic> cats = {};
@ -168,6 +187,7 @@ class AuthService {
return cats;
}
static Future<List<dynamic>?> userDetails(int userid) async {
List<dynamic> cats = [];
String serverUrl = ConstValues.currentServer();