Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: 프로필 등록 api 연결 수정 #66

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions economic_fe/lib/data/models/user_profile.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
class UserProfile {
String nickname;
String birthDate;
String gender;
String profileIntro;
String businessType;
String job;
String ageRange;
String gender;
String? profileIntro;
bool isLearningAlarmAllowed;
bool isCommunityAlarmAllowed;

UserProfile({
required this.nickname,
required this.birthDate,
required this.gender,
required this.profileIntro,
required this.businessType,
required this.job,
required this.ageRange,
required this.gender,
this.profileIntro,
this.isLearningAlarmAllowed = false,
this.isCommunityAlarmAllowed = false,
this.isLearningAlarmAllowed = true, // 기본값
this.isCommunityAlarmAllowed = true, // 기본값
});

// JSON 변환
factory UserProfile.fromJson(Map<String, dynamic> json) {
return UserProfile(
nickname: json['nickname'] ?? '',
birthDate: json['birthDate'] ?? '',
gender: json['gender'] ?? '',
profileIntro: json['profileIntro'] ?? '',
businessType: json['businessType'] ?? '',
job: json['job'] ?? '',
isLearningAlarmAllowed: json['isLearningAlarmAllowed'] ?? true,
isCommunityAlarmAllowed: json['isCommunityAlarmAllowed'] ?? true,
);
}

Map<String, dynamic> toJson() {
return {
'nickname': nickname,
'businessType': businessType,
'job': job,
'ageRange': ageRange,
'gender': gender,
'profileIntro': profileIntro,
'isLearningAlarmAllowed': isLearningAlarmAllowed,
'isCommunityAlarmAllowed': isCommunityAlarmAllowed,
"nickname": nickname,
"birthDate": birthDate,
"gender": gender,
"profileIntro": profileIntro,
"businessType": businessType,
"job": job,
"isLearningAlarmAllowed": isLearningAlarmAllowed,
"isCommunityAlarmAllowed": isCommunityAlarmAllowed,
};
}
}
43 changes: 11 additions & 32 deletions economic_fe/lib/data/services/remote_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ class RemoteDataSource {
/// API POST
///
/// 데이터 생성시 사용
/// jsonData 포함X
/// jsonData 포함O
static Future<dynamic> postApiWithJson(
String endPoint,
Map<String, dynamic> jsonData,
) async {
String apiUrl = '$baseUrl/$endPoint';
// String authToken = dotenv.env['AUTHORIZATION_KEY']!; // 환경 변수에서 가져오기
Map<String, String> headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
Expand Down Expand Up @@ -494,44 +493,24 @@ class RemoteDataSource {
}
}

/// api/v1/terms/{id}/scrap
/// 용어 스크랩
static Future<dynamic> postTermsScrap(int id) async {
String endPoint = "api/v1/terms/$id/scrap";

try {
final response = await _postApi(endPoint);

if (response != null) {
debugPrint("스크랩 post 성공");
return true;
} else {
debugPrint("스크랩 실패");
return false;
}
} catch (e) {
debugPrint("scrap Error : $e");
return false;
}
}

/// api/v1/terms/{id}/scrap
/// 용어 스크랩 취소
static Future<dynamic> deleteScrap(int id) async {
String endPoint = "api/v1/terms/$id/scrap";
/// 사용자 프로필 등록 API
/// API: api/v1/user/profile
static Future<dynamic> registerUserProfile(
Map<String, dynamic> userProfile) async {
String endpoint = 'api/v1/user/profile';

try {
final response = await _deleteApi(endPoint);
final response = await postApiWithJson(endpoint, userProfile);

if (response != null) {
debugPrint("스크랩 delete 성공");
if (response == 200) {
debugPrint('사용자 프로필 등록 성공');
return true;
} else {
debugPrint("스크랩 delete 실패");
debugPrint('사용자 프로필 등록 실패: $response');
return false;
}
} catch (e) {
debugPrint("scrap delete Error : $e");
debugPrint('registerUserProfile Error: $e');
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion economic_fe/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RippleApp extends StatelessWidget {
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Ripple',
initialRoute: '/article',
initialRoute: '/',
getPages: UserRouter.getPages(), // 라우트 설정
);
}
Expand Down
117 changes: 53 additions & 64 deletions economic_fe/lib/view/screens/profile_setting/basic_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BasicInfoPage extends StatelessWidget {
appBar: CustomAppBar(
title: '기본 정보',
onPress: () {
controller.navigateToProfileSetting(context);
Get.back();
},
icon: Icons.close,
),
Expand Down Expand Up @@ -104,7 +104,7 @@ class BasicInfoPage extends StatelessWidget {
height: ScreenUtils.getHeight(context, 18.8),
),
const BasicLabel(
label: '닉네임(필수)',
label: '닉네임',
),
SizedBox(
height: ScreenUtils.getHeight(context, 4),
Expand All @@ -114,9 +114,11 @@ class BasicInfoPage extends StatelessWidget {
height: ScreenUtils.getHeight(context, 44),
child: Obx(() {
return TextField(
onChanged: controller.validateNickname, // 입력 값에 따라 유효성 검사
controller:
TextEditingController(text: controller.nickname.value),
onChanged: (value) {
controller.nickname.value = value; // 닉네임 업데이트
controller.validateNickname(value);
},
controller: controller.nicknameController,
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.all(12.0),
Expand Down Expand Up @@ -224,32 +226,28 @@ class BasicInfoPage extends StatelessWidget {
child: Row(
children: [
GestureDetector(
onTap: () => controller.selectGender('남'),
child: controller.selectedGender.value == '남'
? const BasicGenderButton(
isSelected: true,
text: '남',
textColor: Colors.black,
)
: const BasicGenderButton(
isSelected: false,
text: '남',
textColor: Color(0xFFA2A2A2),
),
onTap: () => controller.selectGender('MALE'),
child: BasicGenderButton(
text: '남',
textColor:
controller.selectedGender.value == 'MALE'
? Colors.black
: const Color(0xffa2a2a2),
isSelected:
controller.selectedGender.value == 'MALE',
),
),
GestureDetector(
onTap: () => controller.selectGender('여'),
child: controller.selectedGender.value == '여'
? const BasicGenderButton(
isSelected: true,
text: '여',
textColor: Colors.black,
)
: const BasicGenderButton(
isSelected: false,
text: '여',
textColor: Color(0xFFA2A2A2),
),
onTap: () => controller.selectGender('FEMALE'),
child: BasicGenderButton(
text: '여',
textColor:
controller.selectedGender.value == 'FEMALE'
? Colors.black
: const Color(0xffa2a2a2),
isSelected:
controller.selectedGender.value == 'FEMALE',
),
),
],
),
Expand Down Expand Up @@ -330,31 +328,28 @@ class BasicInfoPage extends StatelessWidget {
),
SizedBox(
width: ScreenUtils.getWidth(context, 216),
child: Obx(() {
return TextField(
controller: TextEditingController(
text: controller.userInput.value),
onChanged: controller.onTextChanged,
maxLines: 5,
inputFormatters: [
// 글자 수가 maxLength를 초과하지 않도록 제한
LengthLimitingTextInputFormatter(
controller.maxLength),
],
decoration: InputDecoration(
border: InputBorder.none,
hintText: '한 줄 소개를 입력하세요.',
hintStyle: Palette.pretendard(
context,
const Color(0xFFA2A2A2),
16,
FontWeight.w400,
1.5,
-0.4,
),
child: TextField(
controller: controller.userInputController,
onChanged: controller.onTextChanged,
maxLines: 5,
inputFormatters: [
// 글자 수가 maxLength를 초과하지 않도록 제한
LengthLimitingTextInputFormatter(
controller.maxLength),
],
decoration: InputDecoration(
border: InputBorder.none,
hintText: '한 줄 소개를 입력하세요.',
hintStyle: Palette.pretendard(
context,
const Color(0xFFA2A2A2),
16,
FontWeight.w400,
1.5,
-0.4,
),
);
}),
),
),
),
],
),
Expand Down Expand Up @@ -404,22 +399,16 @@ class BasicInfoPage extends StatelessWidget {
),
// 저장하기 버튼 활성화
Obx(() {
bool isButtonEnabled = controller.isValid.value &&
controller.selectedBirthday.value != null;
return isButtonEnabled
return controller.isValid.value &&
controller.selectedBirthday.value != null
? CustomButton(
text: '저장하기',
onPress: () {
controller.onSaveButtonClicked();
controller.navigateToProfileSetting(context);
},
bgColor: Palette.buttonColorBlue,
onPress: () => controller.onSaveButtonClicked(),
bgColor: Palette.buttonColorGreen,
)
: CustomButtonUnfilled(
text: '저장하기',
onPress: () {
// 저장할 수 없으므로 아무 동작도 하지 않음
},
onPress: () {},
);
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JobSelectPage extends StatelessWidget {
appBar: CustomAppBar(
title: '업종/직무',
onPress: () {
controller.navigateToProfileSetting(context);
controller.navigateToProfileSetting();
},
icon: Icons.close,
),
Expand Down Expand Up @@ -105,8 +105,7 @@ class JobSelectPage extends StatelessWidget {
text: '저장하기',
onPress: () {
controller.onSaveButtonClicked();
controller.navigateToProfileSetting(
context); // 프로필 설정 화면으로 이동
controller.navigateToProfileSetting(); // 프로필 설정 화면으로 이동
},
bgColor: Palette.buttonColorBlue,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PartSelectPage extends StatelessWidget {
appBar: CustomAppBar(
title: '업종/직무',
onPress: () {
controller.navigateToProfileSetting(context);
controller.navigateToProfileSetting();
},
icon: Icons.close,
),
Expand Down Expand Up @@ -299,8 +299,7 @@ class PartSelectPage extends StatelessWidget {
text: '저장하기',
onPress: () {
controller.onSaveButtonClicked();
controller.navigateToProfileSetting(
context); // 프로필 설정 화면으로 이동
controller.navigateToProfileSetting(); // 프로필 설정 화면으로 이동
},
bgColor: Palette.buttonColorBlue,
),
Expand Down
Loading