Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: pass gameid on donation part 2 (KIDS-1699) #1271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/features/family/app/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void initCubits() {
..registerLazySingleton<GiveCubit>(
() => GiveCubit(
getIt(),
getIt(),
),
)
..registerLazySingleton<OrganisationBloc>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:givt_app/core/enums/enums.dart';
import 'package:givt_app/features/family/app/family_pages.dart';
import 'package:givt_app/features/family/app/injection.dart';
import 'package:givt_app/features/family/extensions/extensions.dart';
import 'package:givt_app/features/family/features/flows/cubit/flows_cubit.dart';
import 'package:givt_app/features/family/features/giving_flow/collectgroup_details/cubit/collectgroup_details_cubit.dart';
Expand All @@ -14,6 +15,7 @@ import 'package:givt_app/features/family/features/giving_flow/create_transaction
import 'package:givt_app/features/family/features/giving_flow/screens/success_screen.dart';
import 'package:givt_app/features/family/features/giving_flow/widgets/slider_widget.dart';
import 'package:givt_app/features/family/features/profiles/cubit/profiles_cubit.dart';
import 'package:givt_app/features/family/features/reflect/domain/reflect_and_share_repository.dart';
import 'package:givt_app/features/family/shared/design/components/components.dart';
import 'package:givt_app/features/family/shared/design/illustrations/fun_give.dart';
import 'package:givt_app/features/family/shared/design/illustrations/fun_icon.dart';
Expand Down Expand Up @@ -108,6 +110,7 @@ class ChooseAmountSliderScreen extends StatelessWidget {
mediumId: mediumId,
amount: state.amount,
isActOfService: isActOfService,
gameGuid: isActOfService ? getIt<ReflectAndShareRepository>().getGameId() : null,
);

await context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:givt_app/core/enums/amplitude_events.dart';
import 'package:givt_app/core/logging/logging_service.dart';
import 'package:givt_app/features/family/features/giving_flow/create_transaction/models/transaction.dart';
import 'package:givt_app/features/family/features/giving_flow/create_transaction/repositories/create_transaction_repository.dart';
import 'package:givt_app/features/family/features/reflect/domain/reflect_and_share_repository.dart';
import 'package:givt_app/features/give/models/givt_transaction.dart';
import 'package:givt_app/utils/analytics_helper.dart';

Expand All @@ -14,8 +15,10 @@ part 'give_state.dart';
class GiveCubit extends Cubit<GiveState> {
GiveCubit(
this._createTransactionRepository,
this._reflectAndShareRepository,
) : super(GiveInitial());
final CreateTransactionRepository _createTransactionRepository;
final ReflectAndShareRepository _reflectAndShareRepository;

Future<void> createTransaction({
required String userId,
Expand All @@ -30,6 +33,9 @@ class GiveCubit extends Cubit<GiveState> {
amount: amount.toDouble(),
mediumId: base64Encode(utf8.encode(mediumId)),
isActOfService: isGratitude,
gameGuid: isGratitude
? _reflectAndShareRepository.getGameId()
: null,
);
try {
await _createTransactionRepository.createTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ class ReflectAndShareRepository {
}

String? getGameId() => _gameId;

Future<void> createGameSession() async {
try {
_gameId = await _familyApiService.createGame();
} catch (e, s) {
_gameId = null;
LoggingInfo.instance.error(
e.toString(),
methodName: s.toString(),
Expand Down
14 changes: 11 additions & 3 deletions lib/features/family/network/family_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ class FamilyAPIService {

Future<bool> updateGame(String gameGuid, Map<String, dynamic> body) async {
final url = Uri.https(_apiURL, '/givtservice/v1/game/$gameGuid');
final response = await client.put(url, body: jsonEncode(body));
final response = await client.put(url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: jsonEncode(body));
if (response.statusCode >= 300) {
throw GivtServerFailure(
statusCode: response.statusCode,
Expand All @@ -357,8 +362,11 @@ class FamilyAPIService {
}

Future<String> createGame() async {
final url = Uri.https(_apiURL, '/givtservice/v1/game');
final response = await client.post(url);
final url = Uri.https(_apiURL, '/givtservice/v1/Game');
final response = await client.post(url, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}, body: jsonEncode({}));
if (response.statusCode >= 300) {
throw GivtServerFailure(
statusCode: response.statusCode,
Expand Down