From 753709000fd5c892958ed87767f89a79df8a260f Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 21 Dec 2023 11:43:01 +0300 Subject: [PATCH] Created ew model for user egistration --- .../user_registration_model.dart | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/data/models/userRegistrationModel/user_registration_model.dart b/lib/data/models/userRegistrationModel/user_registration_model.dart index e69de29b..7f32d56c 100644 --- a/lib/data/models/userRegistrationModel/user_registration_model.dart +++ b/lib/data/models/userRegistrationModel/user_registration_model.dart @@ -0,0 +1,102 @@ +import 'dart:convert'; +import 'package:http/http.dart' as http; + +class UserRegistrationSheet { + String firstName; + String lastName; + String email; + String password; + String passwordConfirmation; + bool termsAccepted; + DateTime birthdate; + String gender; + String country; + String city; + String lang; + int weight; + int height; + int chestCircumference; + int waistCircumference; + int hipCircumference; + int bloodPressureUp; + int bloodPressureDown; + bool hasHypo = false; + bool hasHyper = false; + String aboutAllergy = ''; + String aboutTakingPils = ''; + String aboutSportHobbies = ''; + String favoriteFoods = ''; + String unfavoriteFoods = ''; + String additionalInfo = ''; + + UserRegistrationSheet({ + required this.firstName, + required this.lastName, + required this.email, + required this.password, + required this.passwordConfirmation, + required this.termsAccepted, + required this.birthdate, + required this.gender, + required this.country, + required this.city, + required this.lang, + required this.weight, + required this.height, + required this.chestCircumference, + required this.waistCircumference, + required this.hipCircumference, + required this.bloodPressureUp, + required this.bloodPressureDown, + required this.hasHypo, + required this.hasHyper, + required this.aboutAllergy, + required this.aboutTakingPils, + required this.aboutSportHobbies, + required this.favoriteFoods, + required this.unfavoriteFoods, + required this.additionalInfo, + }); + + Map toJson() { + return { + 'first_name': firstName, + 'last_name': lastName, + 'email': email, + 'password': password, + 'password_confirmation': passwordConfirmation, + 'terms': termsAccepted, + 'birthdate': birthdate.toIso8601String(), + 'gender': gender, + 'country': country, + 'city': city, + 'lang': lang, + 'weight': weight, + 'height': height, + 'chest_circumference': chestCircumference, + 'waist_circumference': waistCircumference, + 'hip_circumference': hipCircumference, + 'blood_pressure_up': bloodPressureUp, + 'blood_pressure_down': bloodPressureDown, + 'has_hypo': hasHypo, + 'has_hyper': hasHyper, + 'about_alergy': aboutAllergy, + 'about_taking_pils': aboutTakingPils, + 'about_sport_hobbies': aboutSportHobbies, + 'favorite_foods': favoriteFoods, + 'unfavorite_foods': unfavoriteFoods, + 'additional_info': additionalInfo, + }; + } + + Future sendJson(Uri url) async { + final response = await http.post( + url, + headers: {'Content-Type': 'application/json'}, + body: jsonEncode(toJson()), + ); + if (response.statusCode != 200) { + throw Exception('Failed to send data'); + } + } +}