diff --git a/lib/models/family_member_model.dart b/lib/models/family_member_model.dart index e5ae0b2..48bab91 100644 --- a/lib/models/family_member_model.dart +++ b/lib/models/family_member_model.dart @@ -1,6 +1,6 @@ class FamilyMemberModel { final int familyMemberId, role, pokeCount, talkCount; - final String name, nickname; + final String name, nickname, introMessage; FamilyMemberModel.fromJson(Map json) : familyMemberId = json["familyMemberId"], @@ -8,5 +8,6 @@ class FamilyMemberModel { nickname = json["nickname"], role = json["role"], pokeCount = json["pokeCount"], - talkCount = json["talkCount"]; + talkCount = json["talkCount"], + introMessage = json["introMessage"]; } diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 1793b70..8c609c9 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -2,8 +2,9 @@ import 'package:flutter/material.dart'; import 'package:fam_story_frontend/style.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import '../models/family_member_model.dart'; +import '../services/family_member_api_service.dart'; import 'setting_page.dart'; -import 'alarm_page.dart'; import 'package:fam_story_frontend/models/family_model.dart'; import 'package:fam_story_frontend/models/user_model.dart'; @@ -145,12 +146,7 @@ class _HomePageState extends State { Row( children: [ IconButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => AlarmPage()), - ); - }, + onPressed: () {}, icon: const Icon(Icons.alarm_on), color: AppColor.swatchColor, iconSize: 35), @@ -158,7 +154,8 @@ class _HomePageState extends State { onPressed: () { Navigator.push( context, - MaterialPageRoute(builder: (context) => SettingPage()), + MaterialPageRoute( + builder: (context) => SettingPage()), ); }, icon: const Icon(Icons.settings), @@ -195,7 +192,26 @@ class _HomePageState extends State { buttonSize: 0.28, imageSize: 50, memberImage: 'assets/images/mom.png', - onTap: () {}, + onTap: () async { + //FamilyMemberApi 테스트 + /* + print(await FamilyMemberApiService.putFamilyMember( + 15, 1, "하잉")); + List x = + await FamilyMemberApiService.getAllFamilyMember( + 13); + for (var member in x) { + print(member.familyMemberId); + print(member.talkCount); + print(member.pokeCount); + print(member.name); + print(member.nickname); + print(member.role); + print(member.introMessage); + } + + */ + }, ); }, onAccept: (data) { diff --git a/lib/pages/role_page.dart b/lib/pages/role_page.dart index dc150f7..48373b3 100644 --- a/lib/pages/role_page.dart +++ b/lib/pages/role_page.dart @@ -13,7 +13,8 @@ class RolePage extends StatefulWidget { State createState() => _SelectRolePageState(); } -class _SelectRolePageState extends State with TickerProviderStateMixin { +class _SelectRolePageState extends State + with TickerProviderStateMixin { final _familyNameController = TextEditingController(); int? selectedRole; @@ -32,7 +33,8 @@ class _SelectRolePageState extends State with TickerProviderStateMixin @override Widget build(BuildContext context) { - final args = ModalRoute.of(context)?.settings.arguments as Map; + final args = + ModalRoute.of(context)?.settings.arguments as Map; final familyName = args['familyName'] as String; final familyId = args['familyId'] as int; @@ -54,11 +56,17 @@ class _SelectRolePageState extends State with TickerProviderStateMixin children: [ Text( "fam'Story", - style: TextStyle(color: AppColor.textColor, fontSize: 40, fontWeight: FontWeight.bold), + style: TextStyle( + color: AppColor.textColor, + fontSize: 40, + fontWeight: FontWeight.bold), ), Text( "Tell Me Who You Are !", - style: TextStyle(color: AppColor.textColor, fontSize: 20, fontWeight: FontWeight.bold), + style: TextStyle( + color: AppColor.textColor, + fontSize: 20, + fontWeight: FontWeight.bold), ) ], ), @@ -96,7 +104,8 @@ class _SelectRolePageState extends State with TickerProviderStateMixin const SizedBox(height: 16.0), GridView.builder( shrinkWrap: true, - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, crossAxisSpacing: 14.0, mainAxisSpacing: 14.0, @@ -184,7 +193,9 @@ class _SelectRolePageState extends State with TickerProviderStateMixin // TODO: API 연결, 가족 멤버 생성, 가족 ID 가져 오기 print(roleDescriptions[selectedRole!]); try { - int familyMemberId = await FamilyMemberApiService.postFamilyMember(familyId, selectedRole!); + int familyMemberId = + await FamilyMemberApiService.postFamilyMember( + familyId, selectedRole!, ""); } catch (e) { print(e.toString()); } @@ -212,20 +223,26 @@ class _SelectRolePageState extends State with TickerProviderStateMixin onPressed: () { Navigator.of(context).pop(); // 현재 라우트 팝 Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (context) => const RootPage()), + MaterialPageRoute( + builder: (context) => + const RootPage()), ); }, style: TextButton.styleFrom( - foregroundColor: AppColor.objectColor, // 텍스트 색상 - padding: const EdgeInsets.fromLTRB(40, 10, 40, 10), // 버튼 패딩 조정 + foregroundColor: + AppColor.objectColor, // 텍스트 색상 + padding: const EdgeInsets.fromLTRB( + 40, 10, 40, 10), // 버튼 패딩 조정 minimumSize: const Size(100, 40), - backgroundColor: AppColor.textColor, // 버튼 배경색 + backgroundColor: + AppColor.textColor, // 버튼 배경색 ), child: const Text( 'Let\'s Go Home', style: TextStyle( fontSize: 18, // 버튼 글씨 크기 - color: AppColor.objectColor, // 버튼 글씨 색상 + color: + AppColor.objectColor, // 버튼 글씨 색상 ), ), ), @@ -239,7 +256,8 @@ class _SelectRolePageState extends State with TickerProviderStateMixin shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(35), ), - backgroundColor: selectedRole != null ? AppColor.textColor : Colors.grey, + backgroundColor: + selectedRole != null ? AppColor.textColor : Colors.grey, minimumSize: const Size(120, 40), // selectedRole에 따라 배경색 조절 ), child: Text( diff --git a/lib/services/family_member_api_service.dart b/lib/services/family_member_api_service.dart index 601d4bc..b931cfa 100644 --- a/lib/services/family_member_api_service.dart +++ b/lib/services/family_member_api_service.dart @@ -9,7 +9,6 @@ import 'package:http/http.dart' as http; import '../models/family_member_model.dart'; import '../models/family_model.dart'; -// TODO: 에러 코드 추가 class FamilyMemberApiService { static const String baseUrl = 'https://famstory.thisiswandol.com/api'; @@ -49,7 +48,8 @@ class FamilyMemberApiService { } /// POST: /family-member [가족 구성원] 가족 구성원 생성 - static Future postFamilyMember(int familyId, int role) async { + static Future postFamilyMember( + int familyId, int role, String introMessage) async { final url = Uri.parse('$baseUrl/family-member'); const storage = FlutterSecureStorage(); @@ -71,8 +71,12 @@ class FamilyMemberApiService { 'Accept': 'application/json', 'Authorization': 'Bearer $loginToken', }, - body: jsonEncode( - {"familyId": familyId, "role": role, "fcmToken": fcmToken}), + body: jsonEncode({ + "familyId": familyId, + "role": role, + "fcmToken": fcmToken, + "introMessage": introMessage + }), ); // 가족 생성 완료 @@ -85,7 +89,8 @@ class FamilyMemberApiService { } /// PUT: /family-member [가족 구성원] 가족 구성원 역할 수정 - static Future putFamilyMember(int familyMemberId, int role) async { + static Future putFamilyMember( + int familyMemberId, int role, String introMessage) async { final url = Uri.parse('$baseUrl/family-member'); const storage = FlutterSecureStorage(); @@ -98,12 +103,6 @@ class FamilyMemberApiService { Map userInfo = json.decode(userInfoString); String loginToken = userInfo['token']; - // TODO: 가족 멤버 정보 수정 창에서 null 체크 하기 - // 가족 이름만 수정 가능 - Map data = {}; - data.putIfAbsent("familyMemberId", () => familyMemberId); - data.putIfAbsent("role", () => role); - final response = await http.put( url, headers: { @@ -111,7 +110,8 @@ class FamilyMemberApiService { 'Accept': 'application/json', 'Authorization': 'Bearer $loginToken', }, - body: jsonEncode(data), + body: jsonEncode( + {"id": familyMemberId, "role": role, "introMessage": introMessage}), ); if (response.statusCode == 200) { @@ -126,7 +126,7 @@ class FamilyMemberApiService { /// DELETE: /family-member [가족 구성원] 가족 구성원 삭제 static Future deleteFamilyMember(int familyMemberId) async { final url = - Uri.parse('$baseUrl/family-member?family-memberId=$familyMemberId'); + Uri.parse('$baseUrl/family-member?familyMemberId=$familyMemberId'); const storage = FlutterSecureStorage(); String? userInfoString = await storage.read(key: 'login'); @@ -157,7 +157,7 @@ class FamilyMemberApiService { } /// Get: /family-member [가족 구성원] 구성원 ID를 통한 가족 구성원 정보 반환 - static Future getFamilyMember(int familyMemberId) async { + static Future getFamilyMemberID(int familyMemberId) async { final url = Uri.parse('$baseUrl/family-member?family-memberId=$familyMemberId'); const storage = FlutterSecureStorage(); @@ -194,7 +194,7 @@ class FamilyMemberApiService { } /// Get: /family-member/user [가족 구성원] 회원이 속한 가족 구성원 정보 반환 - static Future getUser() async { + static Future getFamilyMember() async { final url = Uri.parse('$baseUrl/family-member/user'); const storage = FlutterSecureStorage(); @@ -207,7 +207,7 @@ class FamilyMemberApiService { Map userInfo = json.decode(userInfoString); String loginToken = userInfo['token']; - final response = await http.delete( + final response = await http.get( url, headers: { 'Content-Type': 'application/json', @@ -230,7 +230,7 @@ class FamilyMemberApiService { } /// Post : /family-member/family [가족 구성원] 가족 구성원이 속한 가족의 정보 조회 - static Future postUser( + static Future postAndGetFamily( int familyMemberId, String fcmToken) async { final url = Uri.parse('$baseUrl/family-member/family'); const storage = FlutterSecureStorage(); @@ -297,9 +297,11 @@ class FamilyMemberApiService { print(jsonDecode(response.body)['message']); List jsonDataList = jsonDecode(response.body)['data']; List familyMemberList = List.from( - jsonDataList.map((item) => FamilyModel.fromJson(item))); + jsonDataList.map((item) => FamilyMemberModel.fromJson(item))); return familyMemberList; } + FamilyModel familyInfo = + FamilyModel.fromJson(jsonDecode(response.body)['data']); // 예외 처리; 메시지를 포함한 예외를 던짐 String errorMessage = jsonDecode(response.body)['message'] ?? 'Error'; print(errorMessage);