Skip to content

Commit

Permalink
add syncing page after login/register
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Mar 4, 2024
1 parent 550a824 commit 5df591a
Show file tree
Hide file tree
Showing 38 changed files with 998 additions and 137 deletions.
Binary file added frontend/binary/macos/librealm_dart.dylib
Binary file not shown.
1 change: 1 addition & 0 deletions frontend/binary/macos/realm_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.0
21 changes: 10 additions & 11 deletions frontend/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ PODS:
- FirebaseAuth (~> 10.20.0)
- Firebase/CoreOnly (10.20.0):
- FirebaseCore (= 10.20.0)
- firebase_auth (4.17.5):
- firebase_auth (4.17.6):
- Firebase/Auth (= 10.20.0)
- firebase_core
- Flutter
- firebase_core (2.25.4):
- firebase_core (2.25.5):
- Firebase/CoreOnly (= 10.20.0)
- Flutter
- FirebaseAppCheckInterop (10.21.0)
Expand Down Expand Up @@ -60,17 +60,16 @@ PODS:
- GTMSessionFetcher/Core (< 4.0, >= 1.5)
- GTMSessionFetcher/Core (3.3.1)
- PromisesObjC (2.3.1)
- RecaptchaInterop (100.0.0)
- shared_preferences_foundation (0.0.1):
- realm (1.9.0):
- Flutter
- FlutterMacOS
- RecaptchaInterop (100.0.0)

DEPENDENCIES:
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- Flutter (from `Flutter`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- realm (from `.symlinks/plugins/realm/ios`)

SPEC REPOS:
trunk:
Expand All @@ -96,14 +95,14 @@ EXTERNAL SOURCES:
:path: Flutter
google_sign_in_ios:
:path: ".symlinks/plugins/google_sign_in_ios/darwin"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
realm:
:path: ".symlinks/plugins/realm/ios"

SPEC CHECKSUMS:
AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570
Firebase: 10c8cb12fb7ad2ae0c09ffc86cd9c1ab392a0031
firebase_auth: 7351d07504173efaf1fb31fe3ffb73b2c521eae0
firebase_core: a46c312d8bae4defa3d009b2aa7b5b413aeb394e
firebase_auth: b237f065b2afc6bd7962124e1cbacdbef31036e6
firebase_core: c8628c7ce80f79439149549052bff22f6784fbf5
FirebaseAppCheckInterop: 69fc7d8f6a1cbfa973efb8d1723651de30d12525
FirebaseAuth: 9c5c400d2c3055d8ae3a0284944c86fa95d48dac
FirebaseCore: 28045c1560a2600d284b9c45a904fe322dc890b6
Expand All @@ -115,8 +114,8 @@ SPEC CHECKSUMS:
GTMAppAuth: 99fb010047ba3973b7026e45393f51f27ab965ae
GTMSessionFetcher: 8a1b34ad97ebe6f909fb8b9b77fba99943007556
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
realm: 6bd69074cfaa17e0643059c67f7605cc72047e7b
RecaptchaInterop: 7d1a4a01a6b2cb1610a47ef3f85f0c411434cb21
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

Expand Down
57 changes: 57 additions & 0 deletions frontend/lib/common/http/http_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:dio/dio.dart';
import 'package:firebase_auth/firebase_auth.dart';

/* Base dio HTTP client */
class HttpClient {
/* Dio Client singleton instance */
static final HttpClient _singleton = HttpClient._internal();

factory HttpClient() {
return _singleton;
}

HttpClient._internal();

/* Get getter for singleton instance */
Dio get instance => _createDioInstance();

Dio _createDioInstance() {
final dio = Dio(
BaseOptions(
baseUrl: 'https://fitnesse-backend.onrender.com/v1',
),
);

/* Add interceptor to auto-add access token to HTTP requests */
dio.interceptors.add(InterceptorsWrapper(
onRequest: (options, handler) async {
/* Attach firebase id token to `authorization` header */
String? token = await _getFirebaseIdToken();
if (token != null) {
options.headers['authorization'] = 'Bearer $token';
}
return handler.next(options);
},
onResponse: (response, handler) {
/* Handle responses */
return handler.next(response);
},
onError: (DioException e, handler) {
/* Handle errors */
return handler.next(e);
},
));

return dio;
}

/* Get the firebase id token from the current user */
Future<String?> _getFirebaseIdToken() async {
final user = FirebaseAuth.instance.currentUser;
if (user != null) {
final token = await user.getIdToken();
return token;
}
return null;
}
}
71 changes: 71 additions & 0 deletions frontend/lib/common/models/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Data model for a user */

/* Sex enum matching backend */
import 'package:realm/realm.dart';

part 'user.g.dart';

enum Sex { male, female }

/* Activity level enum matching backend */
enum ActivityLevel {
sedentary,
lightlyActive,
moderatelyActive,
veryActive,
extremelyActive
}

/* Weight goal enum matching backend */
enum WeightGoal {
fastLoss,
moderateLoss,
slowLoss,
maintain,
slowGain,
moderateGain,
fastGain
}

/* Convert enums to int for storage */
int _enumToInt(dynamic enumValue) => enumValue.index;

/* Data model for a user */
@RealmModel()
class _User {
@PrimaryKey()
late String _id;
late DateTime birthday;
@MapTo('sex')
late int sexIndex;
late int height;
late int weight;
@MapTo('activityLevel')
late int activityLevelIndex;
@MapTo('weightGoal')
late int weightGoalIndex;
late bool useMetric;
late _Goals? goals;
late DateTime createdAt;
late DateTime updatedAt;

/* Create getters and setters for enum fields */
Sex get sex => Sex.values[sexIndex];
set sex(Sex value) => sexIndex = _enumToInt(value);

ActivityLevel get activityLevel => ActivityLevel.values[activityLevelIndex];
set activityLevel(ActivityLevel value) =>
activityLevelIndex = _enumToInt(value);

WeightGoal get weightGoal => WeightGoal.values[weightGoalIndex];
set weightGoal(WeightGoal value) => weightGoalIndex = _enumToInt(value);
}

/* Data model for macro goals */
@RealmModel()
class _Goals {
late int calories;
late int protein;
late int fat;
late int carbohydrates;
}
181 changes: 181 additions & 0 deletions frontend/lib/common/models/user.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5df591a

Please sign in to comment.