Skip to content

Commit

Permalink
Revert "Merge pull request #1704 from c3bryant/notifications-v2"
Browse files Browse the repository at this point in the history
This reverts commit 6fa1fe7, reversing
changes made to e6fcd6f.
  • Loading branch information
c3bryant committed Feb 8, 2022
1 parent c9c405b commit b4d7b7e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 45 deletions.
2 changes: 2 additions & 0 deletions lib/core/providers/ventilation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class VentilationDataProvider extends ChangeNotifier {
_isLoading = true;
_error = null;
notifyListeners();
print("Items in Ventilation IDS");

// create new list of ventilation data to display
List<VentilationDataModel?> tempModels = [];
Expand Down Expand Up @@ -174,6 +175,7 @@ class VentilationDataProvider extends ChangeNotifier {
ventilationDataModels.add(_ventilationService.data);
ventilationIDs =
_userDataProvider!.userProfileModel!.selectedVentilationLocations!;

} catch (e) {
_error = VentilationConstants.addLocationFailed;
print("Error while adding location: $e");
Expand Down
48 changes: 9 additions & 39 deletions lib/core/services/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/notifications.dart';

class MessageService {
final String myMessagesApiUrl =
'https://api-qa.ucsd.edu:8243/mp-mymessages/1.0.0/messages?start=';
final String topicsApiUrl =
'https://bvgjvzaakl.execute-api.us-west-2.amazonaws.com/dev/topics?';

bool _isLoading = false;
DateTime? _lastUpdated;
String? _error;
Messages? _data;

final NetworkHelper _networkHelper = NetworkHelper();

final String myMessagesApiUrl =
'https://api-qa.ucsd.edu:8243/mp-mymessages/2.0.0';
final String topicsApiUrl =
'https://api-qa.ucsd.edu:8243/mp-topicmessages/2.0.0';

final Map<String, String> topicsHeaders = {
"accept": "application/json",
};

Future<bool> fetchMyMessagesData(
int? timestamp, Map<String, String> authHeaders) async {
_error = null;
Expand All @@ -28,8 +24,7 @@ class MessageService {
try {
/// fetch data
String _response = await _networkHelper.authorizedFetch(
myMessagesApiUrl + '/messages?start=' + timestamp.toString(),
authHeaders);
myMessagesApiUrl + timestamp.toString(), authHeaders);

/// parse data
final data = messagesFromJson(_response);
Expand All @@ -47,51 +42,26 @@ class MessageService {
_error = null;
_isLoading = true;

String topicsEndpoint = '/topics?topics=' + topics.join(',');
String topicsEndpoint = 'topics=' + topics.join(',');
String timestampEndpoint = '&start=' + timestamp.toString();

try {
/// fetch data
String _response = await _networkHelper.authorizedFetch(
topicsApiUrl + topicsEndpoint + timestampEndpoint, topicsHeaders);
String _response = await _networkHelper
.fetchData(topicsApiUrl + topicsEndpoint + timestampEndpoint);

/// parse data
final data = messagesFromJson(_response);
_isLoading = false;
_data = data;
return true;
} catch (e) {
if (e.toString().contains("401")) {
if (await getNewToken()) {
return await fetchTopicData(timestamp, topics);
}
}
_error = e.toString();
_isLoading = false;
return false;
}
}

Future<bool> getNewToken() async {
final String tokenEndpoint = "https://api-qa.ucsd.edu:8243/token";
final Map<String, String> tokenHeaders = {
"content-type": 'application/x-www-form-urlencoded',
"Authorization":
"Basic djJlNEpYa0NJUHZ5akFWT0VRXzRqZmZUdDkwYTp2emNBZGFzZWpmaWZiUDc2VUJjNDNNVDExclVh"
};
try {
var response = await _networkHelper.authorizedPost(
tokenEndpoint, tokenHeaders, "grant_type=client_credentials");

topicsHeaders["Authorization"] = "Bearer " + response["access_token"];

return true;
} catch (e) {
_error = e.toString();
return false;
}
}

String? get error => _error;
Messages? get messagingModels => _data;
bool get isLoading => _isLoading;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/services/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:campus_mobile_experimental/core/models/topics.dart';

class NotificationService {
final NetworkHelper _networkHelper = NetworkHelper();
final String _endpoint = 'https://api-qa.ucsd.edu:8243/mp-registration/2.0.0';
final String _endpoint = 'https://api-qa.ucsd.edu:8243/mp-registration/1.0.0';
final String _topicsEndpoint =
'https://mobile.ucsd.edu/replatform/v1/qa/topics.json';
bool _isLoading = false;
Expand Down
9 changes: 5 additions & 4 deletions lib/core/services/notifications_freefood.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:campus_mobile_experimental/app_networking.dart';
import 'package:campus_mobile_experimental/core/models/notifications_freefood.dart';

class FreeFoodService {
final String baseEndpoint = 'https://api-qa.ucsd.edu:8243/campusevents/2.0.0';
final String baseEndpoint =
'https://api-qa.ucsd.edu:8243/campusevents/1.0.0/';

bool _isLoading = false;
DateTime? _lastUpdated;
Expand All @@ -22,7 +23,7 @@ class FreeFoodService {
try {
/// fetch data
var _response = await _networkHelper.authorizedFetch(
baseEndpoint + '/events/' + id + '/count', headers);
baseEndpoint + 'events/' + id + '/rsvpCount', headers);

/// parse data
final data = freeFoodModelFromJson(_response);
Expand All @@ -49,7 +50,7 @@ class FreeFoodService {
_error = null;
_isLoading = true;
try {
String _url = baseEndpoint + '/events/' + id + '/limit';
String _url = baseEndpoint + 'events/' + id + '/rsvpLimit';

/// fetch data
var _response = await _networkHelper.authorizedFetch(_url, headers);
Expand Down Expand Up @@ -78,7 +79,7 @@ class FreeFoodService {
_isLoading = true;

try {
String _url = baseEndpoint + '/events/' + id;
String _url = baseEndpoint + 'events/' + id;

/// update count
var _response = await _networkHelper.authorizedPut(_url, headers, body);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/services/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserProfileService {
UserProfileModel? _userProfileModel;

final NetworkHelper _networkHelper = NetworkHelper();
final String _endpoint = 'https://api-qa.ucsd.edu:8243/mp-registration/2.0.0';
final String _endpoint = 'https://api-qa.ucsd.edu:8243/mp-registration/1.0.0';

Future<bool> downloadUserProfile(Map<String, String> headers) async {
_error = null;
Expand Down
3 changes: 3 additions & 0 deletions lib/core/services/ventilation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class VentilationService {
} catch (e) {
/// if the authorized fetch failed we know we have to refresh the
/// token for this service
print("IN CATCH");
if (e.toString().contains("401")) {
print("Getting new token from fetchLocations");
if (await getNewToken()) {
print("Getting new token from fetchLocations");
return await fetchLocations();
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/ui/common/webview_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class _WebViewContainerState extends State<WebViewContainer>

// builds the actual webview widget
Widget buildBody(context) {
print('webview_container:buildBody: ' + webCardUrl!);
return Container(
height: _contentHeight,
child: WebView(
Expand Down
1 change: 1 addition & 0 deletions lib/ui/ventilation/ventilation_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class _VentilationCardState extends State<VentilationCard> {
}

Widget buildCardContent(List<VentilationDataModel?> models) {
print("Length in card: ${models.length}");
var display;
try {
for (VentilationDataModel? model in models) {
Expand Down

0 comments on commit b4d7b7e

Please sign in to comment.