Skip to content

Commit

Permalink
Bug fixes in NotificationsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpiniasty committed Jul 18, 2023
1 parent 0f4a897 commit 77940a1
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 103 deletions.
24 changes: 4 additions & 20 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class PartyController {
final res = await http.get(
Uri.parse(url),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
Expand Down Expand Up @@ -76,28 +75,13 @@ class PartyController {
return parties;
}

// FIXME url
static Future<bool> acceptPartyInvitation(PartyInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/invitations/${inv.partyPublicId}/${inv.id}";
final url =
"$mainUrl/parties/invitations/${inv.party!.publicId}/${inv.id}/";
final res = await http.post(
Uri.parse(url),
body: {
"party": {
"owner": {},
"owner_public_id": inv.party!.ownerPublicId,
"name": inv.party!.name,
"privacy_status": inv.party!.privacyStatus,
"description": inv.party!.description,
"location": inv.party!.location!.toPOINT(),
"start_time": inv.party!.startTime.toIso8601String(),
"stop_time": inv.party!.stopTime.toIso8601String(),
},
"party_public_id": inv.partyPublicId,
"receiver": {},
"receiver_public_id": inv.receiverPublicId,
},
headers: {
"Authorization": "Bearer $token",
},
Expand All @@ -106,11 +90,11 @@ class PartyController {
return res.statusCode == 201;
}

// FIXME url
static Future<bool> rejectPartyInvitation(PartyInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/invitations/${inv.partyPublicId}/${inv.id}";
final url =
"$mainUrl/parties/invitations/${inv.party!.publicId}/${inv.id}/";
final res = await http.delete(
Uri.parse(url),
headers: {
Expand Down
48 changes: 24 additions & 24 deletions lib/controllers/party_creator_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:drinkify/models/friend.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
Expand Down Expand Up @@ -51,7 +52,7 @@ class PartyCreatorController {
}

///Creates a party using information provided in [party]
static Future<bool> createParty(Party party) async {
static Future<Party?> createParty(Party party) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
Expand Down Expand Up @@ -84,7 +85,7 @@ class PartyCreatorController {
);
}
final res = await req.send();
return res.statusCode == 201;
return Party.fromMap(jsonDecode(await res.stream.bytesToString()));
}

///Deletes party with the provided [id]
Expand All @@ -102,49 +103,48 @@ class PartyCreatorController {
return res.statusCode == 204;
}

//FIXME url
//FIXME sending request
static Future<bool> acceptPartyRequest(PartyRequest req) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/requests/${req.partyPublicId}/${req.id}/";
final url = "$mainUrl/parties/requests/${req.party!.publicId}/${req.id}/";
final res = await http.post(
Uri.parse(url),
body: jsonEncode({
"party": {
"owner": {},
"owner_public_id": req.party!.ownerPublicId,
"name": req.party!.name,
"privacy_status": req.party!.privacyStatus,
"description": req.party!.description,
"location": req.party!.location!.toPOINT(),
"start_time": req.party!.startTime.toIso8601String(),
"stop_time": req.party!.stopTime.toIso8601String(),
},
"party_public_id": req.partyPublicId,
"sender": {},
"sender_public_id": req.senderPublicId,
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}

//FIXME url
//FIXME
static Future<bool> rejectPartyRequest(PartyRequest req) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/requests/${req.partyPublicId}/${req.id}/";
final url = "$mainUrl/parties/requests/${req.party!.publicId}/${req.id}/";
final res = await http.delete(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 204;
}

static Future<bool> sendPartyInvitation(Party p, Friend f) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/invitations/${p.publicId}";
final res = await http.post(
Uri.parse(url),
body: {
//TODO implement those fields
},
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}
}
1 change: 0 additions & 1 deletion lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class UserController {
return res.statusCode == 201;
}

// FIXME url
static Future<bool> rejectFriendInvitation(FriendInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
Expand Down
6 changes: 5 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@

"notificationsNotifications": "Notifications",
"notificationFrom": "From",
"notificationTo": "To",
"friendInvitations": "Friend invitations",
"partyInvitations": "Party invitations",
"joinRequests": "Join requests",
"sentJoinRequests": "Sent join requests",
"acceptNotif": "Accept",
"rejectNotif": "Reject",
"acceptedNotif": "Accepted",
"rejectedNotif": "Rejected",
"acceptRejectError": "An error occurred",

"settings": "Settings",
"editProfile": "Edit profile",
Expand Down
6 changes: 5 additions & 1 deletion lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@

"notificationsNotifications": "Powiadomienia",
"notificationFrom": "Od",
"notificationTo": "Do",
"friendInvitations": "Zaproszenia do znajomych",
"partyInvitations": "Zaproszenia na imprezę",
"joinRequests": "Prośby o dołączenie",
"sentJoinRequests": "Wysłane prośby o dołączenie",
"acceptNotif": "Zaakceptuj",
"rejectNotif": "Odrzuć",
"acceptedNotif": "Zaakceptowano",
"rejectedNotif": "Odrzucono",
"acceptRejectError": "Wystąpił błąd",

"settings": "Ustawienia",
"editProfile": "Edytuj profil",
Expand Down
9 changes: 7 additions & 2 deletions lib/routes/create_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> with MapUtils {
}
setState(() => errorFields = tempErrorList);
if (errorFields.isNotEmpty && !_wrongDate) return;
final isCreated = await PartyCreatorController.createParty(
final createdParty = await PartyCreatorController.createParty(
Party(
name: partyTitle,
description: descriptionCtrl.text,
Expand All @@ -167,13 +167,18 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> with MapUtils {
image: thumbnail?.path,
),
);
if (createdParty != null) {
for (final p in invitedUsers) {
PartyCreatorController.sendPartyInvitation(createdParty, p);
}
}
if (!mounted) return;
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Theming.bgColor,
builder: (_) => SuccessSheet(
success: isCreated,
success: createdParty != null,
successMsg: AppLocalizations.of(context)!.createdSuccessfully,
failureMsg: AppLocalizations.of(context)!.creationFailed,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/notification_routes/party_requests_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PartyRequestsPage extends StatelessWidget {
text: TextSpan(
children: [
TextSpan(
text: AppLocalizations.of(ctx)!.notificationFrom,
text: AppLocalizations.of(ctx)!.notificationTo,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
Expand Down
17 changes: 8 additions & 9 deletions lib/routes/selected_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ class _SelectedPartyPage extends State<SelectedPartyPage> {
}

final LocationData posData = await location.getLocation();
if (context.mounted) {
setState(() {
userLocation = LatLng(
posData.latitude!,
posData.longitude!,
);
showUserLocation = true;
});
}
if (!mounted) return;
setState(() {
userLocation = LatLng(
posData.latitude!,
posData.longitude!,
);
showUserLocation = true;
});
}

double mapFullSize(BuildContext ctx) => MediaQuery.of(ctx).size.height - 120;
Expand Down
Loading

0 comments on commit 77940a1

Please sign in to comment.