Skip to content

Commit

Permalink
Merge pull request #238 from RunTerror/new_beacon_branch
Browse files Browse the repository at this point in the history
Auth home and cubit module migration
  • Loading branch information
Akshatji800 committed Sep 28, 2024
2 parents 72c1c09 + f547313 commit c2f4532
Show file tree
Hide file tree
Showing 74 changed files with 5,004 additions and 1,479 deletions.
12 changes: 7 additions & 5 deletions lib/Bloc/config/graphql_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class GraphQLConfig {
));

Future getToken() async {
final _token = userConfig!.currentUser!.authToken;
token = _token;
await localApi.init();
final user = await localApi.fetchUser();
if (user != null) {
token = user.authToken;
}
return true;
}

GraphQLClient clientToQuery() {
return GraphQLClient(
cache: GraphQLCache(),
// cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
link: httpLink,
);
}
Expand All @@ -45,7 +47,7 @@ class GraphQLConfig {

GraphQLClient graphQlClient() {
return GraphQLClient(
cache: GraphQLCache(),
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
link: Link.split(
(request) => request.isSubscription,
websocketLink,
Expand Down
12 changes: 12 additions & 0 deletions lib/Bloc/config/user_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:beacon/Bloc/data/models/user/user_model.dart';
import 'package:beacon/locator.dart';

class UserModelConfig {
UserModel _userModel = UserModel(authToken: 'null');
UserModel get userModel => _userModel;

Future<bool> updateUser(UserModel updateUserDetails) async {
_userModel = updateUserDetails;
return localApi.saveUser(updateUserDetails);
}
}
30 changes: 30 additions & 0 deletions lib/Bloc/core/constants/location.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:geolocator/geolocator.dart';

class LocationService {
static Future<Position> getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;

serviceEnabled = await Geolocator.isLocationServiceEnabled();

if (!serviceEnabled) {
return Future.error('Location service is disabled.');
}

permission = await Geolocator.checkPermission();

if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permission is denied');
}
}

if (permission == LocationPermission.deniedForever) {
return Future.error('Location permission is permanently denied.');
}

return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
}
32 changes: 0 additions & 32 deletions lib/Bloc/core/queries/auth.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:developer';

class AuthQueries {
String registerUser(String? name, String email, String? password) {
return '''
Expand Down Expand Up @@ -43,7 +41,6 @@ class AuthQueries {
}

String fetchUserInfo() {
log('fetching user info');
return '''
query{
me{
Expand All @@ -52,38 +49,9 @@ class AuthQueries {
name
groups{
_id
title
shortcode
leader {
_id
name
}
members {
_id
name
}
beacons{
_id
}
}
beacons{
_id
title
shortcode
leader {
_id
name
}
followers{
_id
name
}
location {
lat
lon
}
startsAt
expiresAt
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions lib/Bloc/core/queries/group.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import 'package:graphql_flutter/graphql_flutter.dart';

class GroupQueries {
String fetchUserGroups(int page, int pageSize) {
return '''
query {
groups(page: $page, pageSize: $pageSize) {
_id
title
shortcode
leader {
_id
name
}
members {
_id
name
}
beacons {
_id
}
}
}
''';
}

String createGroup(String? title) {
return '''
mutation{
Expand Down Expand Up @@ -129,6 +152,36 @@ class GroupQueries {
''';
}

String fetchHikes(String groupID, int page, int pageSize) {
return '''
query{
beacons(groupId: "$groupID", page: $page, pageSize: $pageSize){
_id
title
shortcode
leader {
_id
name
}
location{
lat
lon
}
followers {
_id
name
}
group{
_id
}
startsAt
expiresAt
}
}
''';
}

final groupJoinedSubGql = gql(r'''
subscription StreamNewlyJoinedGroups($id: ID!){
groupJoined(id: $id){
Expand Down
6 changes: 2 additions & 4 deletions lib/Bloc/core/resources/data_state.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:graphql/client.dart';

abstract class DataState<T> {
final T? data;
final OperationException? error;
final String? error;

const DataState({this.data, this.error});
}
Expand All @@ -12,5 +10,5 @@ class DataSuccess<T> extends DataState<T> {
}

class DataFailed<T> extends DataState<T> {
const DataFailed(OperationException error) : super(error: error);
const DataFailed(String error) : super(error: error);
}
2 changes: 1 addition & 1 deletion lib/Bloc/core/services/shared_prefrence_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesService {
class SharedPreferenceService {
SharedPreferenceService() {
init();
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Bloc/core/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:developer';
import 'package:beacon/old/components/utilities/constants.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:graphql/client.dart';
Expand All @@ -13,7 +14,7 @@ class Utils {
message,
style: TextStyle(color: Colors.black),
),
// backgroundColor: kLightBlue.withOpacity(0.8),
backgroundColor: kLightBlue.withOpacity(0.8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
Expand All @@ -40,7 +41,7 @@ class Utils {
}

Future<bool> checkInternetConnectivity() async {
final connectivityResult = await (Connectivity().checkConnectivity());
final connectivityResult = await Connectivity().checkConnectivity();

if (connectivityResult == ConnectivityResult.mobile ||
connectivityResult == ConnectivityResult.wifi ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
class Validator {
static String? validateName(String name) {
if (name.isEmpty) {
static String? validateName(String? name) {
if (name != null && name.isEmpty) {
return "Name must not be left blank";
}
return null;
}

static String? validateEmail(String email) {
static String? validateEmail(String? email) {
// If email is empty return.
if (email.isEmpty) {
if (email != null && email.isEmpty) {
return "Email must not be left blank";
}
const String pattern =
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$";
final RegExp regex = RegExp(pattern);
if (!regex.hasMatch(email)) {
if (email != null && !regex.hasMatch(email)) {
return 'Please enter a valid Email Address';
}
return null;
}

static String? validatePassword(String password) {
static String? validatePassword(String? password) {
// If password is empty return.
if (password.isEmpty) {
if (password != null && password.isEmpty) {
return "Password must not be left blank";
}
// const String pattern = r'^(?=.*?[0-9])(?=.*?[!@#\$&*%^~.]).{8,}$';
Expand All @@ -32,7 +32,7 @@ class Validator {
const String noSpaces = r'^\S+$';
final RegExp noSpaceRegex = RegExp(noSpaces);

if (password.length < 8) {
if (password!.length < 8) {
return "Must be of atleast 8 characters";
}
// if (!regExp.hasMatch(password)) {
Expand All @@ -44,33 +44,33 @@ class Validator {
return null;
}

static String? validateBeaconTitle(String title) {
if (title.isEmpty) {
static String? validateBeaconTitle(String? title) {
if (title != null && title.isEmpty) {
return "Title must not be left blank";
}
return null;
}

static String? validatePasskey(String passkey) {
if (passkey.isEmpty) {
static String? validatePasskey(String? passkey) {
if (passkey != null && passkey.isEmpty) {
return "Passkey must not be left blank";
}
const String pattern = r'[A-Z]+';
final RegExp regExp = RegExp(pattern);
if (!regExp.hasMatch(passkey) || passkey.length != 6) {
if (!regExp.hasMatch(passkey!) || passkey.length != 6) {
return "Invalid passkey";
}
return null;
}

static String? validateDuration(String duration) {
if (duration.startsWith("0:00:00.")) {
static String? validateDuration(String? duration) {
if (duration != null && duration.startsWith("0:00:00.")) {
return "Duration cannot be $duration";
}
return null;
}

static String? validateStartingTime(String startTime) {
static String? validateStartingTime(String? startTime) {
print(startTime);
return null;
}
Expand Down
Loading

0 comments on commit c2f4532

Please sign in to comment.