Skip to content

Commit

Permalink
Deleting parties, minor changes and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpiniasty committed Jul 11, 2023
1 parent 439e94e commit 41f3d14
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 173 deletions.
38 changes: 0 additions & 38 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http_parser/http_parser.dart';

import '../utils/consts.dart';
import '../models/party.dart';
Expand Down Expand Up @@ -64,40 +62,4 @@ class PartyController {
}
return invitations;
}

///Creates a party using information provided in [party]
static Future<bool> createParty(Party party) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
final req = http.MultipartRequest("POST", Uri.parse(url));
req.fields.addAll(<String, String>{
"owner_public_id": party.ownerPublicId!,
"name": party.name,
"privacy_status": party.privacyStatus.toString(),
"description": party.description,
"location": party.location!.toPOINT(),
"start_time": party.startTime.toIso8601String(),
"stop_time": party.stopTime.toIso8601String(),
"participants":
jsonEncode([for (final p in party.participants!) p.toMap()]),
});
req.headers.addAll({
"Content-Type": "multipart/form-data",
"Authorization": "Bearer $token",
});
if (party.image != null) {
req.files.add(
http.MultipartFile(
"image",
File(party.image!).readAsBytes().asStream(),
File(party.image!).lengthSync(),
filename: party.image!,
contentType: MediaType("image", "jpeg"),
),
);
}
final res = await req.send();
return res.statusCode == 201;
}
}
74 changes: 54 additions & 20 deletions lib/controllers/party_creator_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';

import '../utils/consts.dart' show mainUrl;
import '../models/party.dart';
Expand Down Expand Up @@ -29,26 +31,6 @@ class PartyCreatorController {
return parties;
}

///Creates a party
static Future<bool> createParty(Party p) async {
final url = "$mainUrl/parties/";
final res = await http.post(
Uri.parse(url),
body: {
"owner": {},
"owner_public_id": p.ownerPublicId,
"name": p.name,
"privacy_status": p.privacyStatus,
"description": p.description,
"location": p.location!.toPOINT(),
"start_time": p.startTime.toIso8601String(),
"stop_time": p.stopTime.toIso8601String(),
},
);

return res.statusCode == 201;
}

///Retrieves a list of join requests to user's owned parties
static Future<List<PartyRequest>> joinRequests() async {
const storage = FlutterSecureStorage();
Expand All @@ -67,4 +49,56 @@ class PartyCreatorController {
}
return requests;
}

///Creates a party using information provided in [party]
static Future<bool> createParty(Party party) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
final req = http.MultipartRequest("POST", Uri.parse(url));
req.fields.addAll(<String, String>{
"owner_public_id": party.ownerPublicId!,
"name": party.name,
"privacy_status": party.privacyStatus.toString(),
"description": party.description,
"location": party.location!.toPOINT(),
"start_time": party.startTime.toIso8601String(),
"stop_time": party.stopTime.toIso8601String(),
"participants":
jsonEncode([for (final p in party.participants!) p.toMap()]),
});
req.headers.addAll({
"Content-Type": "multipart/form-data",
"Authorization": "Bearer $token",
});
//FIXME creating party without image
if (party.image != null) {
req.files.add(
http.MultipartFile(
"image",
File(party.image!).readAsBytes().asStream(),
File(party.image!).lengthSync(),
filename: party.image!,
contentType: MediaType("image", "jpeg"),
),
);
}
final res = await req.send();
return res.statusCode == 201;
}

///Deletes party with the provided [id]
static Future<bool> deleteParty(String id) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/$id/";
final res = await http.delete(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 204;
}
}
6 changes: 5 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"editProfile": "Edit profile",
"organization": "Organization",
"logOut": "Log out",
"editParty": "Edit party",
"deleteParty": "Delete party",
"deleteSuccess": "Party deleted successfully",
"deleteFailure": "Could not delete party",

"editProfilePage": "Edit profile",
"changePfp": "Change profile picture",
Expand Down Expand Up @@ -117,7 +121,7 @@
"partyDate": "Date",
"partyTime": "Time",
"noFriendsInvited": "No friends invited yet",
"createdSuccessfuly": "Party created successfuly",
"createdSuccessfully": "Party created successfully",
"creationFailed": "Party creation failed",

"requiredField": "Field required",
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 @@ -37,6 +37,10 @@
"editProfile": "Edytuj profil",
"organization": "Organizacja",
"logOut": "Wyloguj się",
"editParty": "Edytuj imprezę",
"deleteParty": "Usuń imprezę",
"deleteSuccess": "Usunięto imprezę",
"deleteFailure": "Nie udało się usunąć imprezy",

"editProfilePage": "Edytuj profil",
"changePfp": "Zmień zdjęcie profilowe",
Expand Down Expand Up @@ -117,7 +121,7 @@
"partyDate": "Data",
"partyTime": "Godzina",
"noFriendsInvited": "Nikogo nie zaproszono",
"createdSuccessfuly": "Utworzono imprezę",
"createdSuccessfully": "Utworzono imprezę",
"creationFailed": "Nie utworzono imprezy",

"requiredField": "Pole wymagane",
Expand Down
17 changes: 8 additions & 9 deletions lib/routes/create_party_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'dart:io';

import 'package:drinkify/models/friend.dart';
import 'package:drinkify/widgets/dialogs/image_picker_sheet.dart';
import 'package:drinkify/widgets/dialogs/success_sheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
Expand All @@ -19,9 +15,12 @@ import '../routes/create_party_routes/description_page.dart';
import '../widgets/createpartypage/party_status.dart';
import '../widgets/createpartypage/datetime_fields.dart';
import '../widgets/createpartypage/invite_friends.dart';
import '../controllers/party_controller.dart';
import '../models/party.dart';
import '../widgets/createpartypage/form_field_party.dart';
import '../controllers/party_creator_controller.dart';
import '../models/friend.dart';
import '../widgets/dialogs/image_picker_sheet.dart';
import '../widgets/dialogs/success_sheet.dart';

class CreatePartyRoute extends StatefulWidget {
const CreatePartyRoute({super.key});
Expand Down Expand Up @@ -178,7 +177,7 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
if (errorFields.isNotEmpty && !_wrongDate) return;
const storage = FlutterSecureStorage();
final userId = await storage.read(key: "user_publicId");
final isCreated = await PartyController.createParty(
final isCreated = await PartyCreatorController.createParty(
Party(
ownerPublicId: userId!,
name: partyTitle,
Expand All @@ -194,11 +193,11 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
if (!mounted) return;
showModalBottomSheet(
context: context,
isScrollControlled: isCreated,
isScrollControlled: true,
backgroundColor: Theming.bgColor,
builder: (_) => SuccessSheet(
success: false,
successMsg: AppLocalizations.of(context)!.createdSuccessfuly,
success: isCreated,
successMsg: AppLocalizations.of(context)!.createdSuccessfully,
failureMsg: AppLocalizations.of(context)!.creationFailed,
),
);
Expand Down
74 changes: 40 additions & 34 deletions lib/routes/friend_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,34 @@ class _FriendListPageState extends State<FriendListPage> {
backgroundColor: Theming.bgColor,
body: Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: Theming.bgColor,
pinned: true,
surfaceTintColor: Colors.transparent,
centerTitle: true,
title: Text(
AppLocalizations.of(context)!.friends,
style: const TextStyle(
CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: Theming.bgColor,
pinned: true,
surfaceTintColor: Colors.transparent,
centerTitle: true,
title: Text(
AppLocalizations.of(context)!.friends,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
leading: Padding(
padding: const EdgeInsets.only(left: 20),
child: IconButton(
onPressed: () => context.pop(),
icon: const Icon(
Icons.arrow_back_ios_rounded,
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
leading: GestureDetector(
onTap: () => context.pop(),
child: const Icon(Icons.arrow_back_ios_new_rounded),
),
),
friends.isEmpty ? const SliverToBoxAdapter() : _friendList(),
],
),
),
friends.isEmpty ? const SliverToBoxAdapter() : _friendList(),
],
),
Center(
child: Text(
Expand All @@ -77,21 +80,24 @@ class _FriendListPageState extends State<FriendListPage> {

Widget _friendList() {
return SliverToBoxAdapter(
child: Column(
children: [
for (final f in friends)
UserHolder(
f,
onButtonTap: () => context.go("/profile", extra: f),
buttonChild: Text(
AppLocalizations.of(context)!.navbarProfile,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Column(
children: [
for (final f in friends)
UserHolder(
f,
onButtonTap: () => context.go("/profile", extra: f),
buttonChild: Text(
AppLocalizations.of(context)!.navbarProfile,
style: const TextStyle(
color: Theming.whiteTone,
fontWeight: FontWeight.bold,
),
),
),
),
],
],
),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/notifications_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../utils/theming.dart';
import '../widgets/dialogs/invitation_sheet.dart';
import '../widgets/dialogs/notification_sheet.dart';
import '../controllers/party_creator_controller.dart';
import '../controllers/user_controller.dart';
import '../models/friend_invitiation.dart';
Expand Down Expand Up @@ -108,7 +108,7 @@ class _NotificationsPageState extends State<NotificationsPage>
onTap: () {
showModalBottomSheet(
context: ctx,
builder: (_) => const InvitationSheet(),
builder: (_) => const NotificationSheet(),
);
},
splashColor: Theming.whiteTone.withOpacity(0.05),
Expand Down
11 changes: 9 additions & 2 deletions lib/routes/parties_users_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart' hide SearchController;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';

import '../widgets/partiespage/search_and_map.dart';
import '../widgets/partiespage/party_holder.dart';
Expand All @@ -9,9 +10,9 @@ import '../widgets/dialogs/success_sheet.dart';
import '../models/party.dart';
import '../models/friend.dart';
import '../models/friend_invitiation.dart';
import '../models/search_type.dart';
import '../controllers/user_controller.dart';
import '../utils/theming.dart';
import '../models/search_type.dart';

class PartiesUsersPage extends StatefulWidget {
const PartiesUsersPage({super.key});
Expand Down Expand Up @@ -93,7 +94,13 @@ class _PartiesUsersPageState extends State<PartiesUsersPage> {
const SizedBox(height: 130),
for (final i in iter)
T == Party
? PartyHolder(i as Party)
? PartyHolder(
i as Party,
() => context.push(
'/party',
extra: i,
),
)
: UserHolder(
i as Friend,
onButtonTap: () async {
Expand Down
18 changes: 18 additions & 0 deletions lib/routes/party_info_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';

import 'package:drinkify/models/party.dart';

class PartyInfoPage extends StatelessWidget {
final Party party;
const PartyInfoPage(this.party, {super.key});

//TODO finish this page
@override
Widget build(BuildContext context) {
return const SingleChildScrollView(
child: Column(
children: [],
),
);
}
}
Loading

0 comments on commit 41f3d14

Please sign in to comment.