Skip to content

Commit

Permalink
feat: Add the coupon button for chicken days. (#215)
Browse files Browse the repository at this point in the history
* feat: Add the coupon button for chicken days.

* feat: Reduce the size of the button

* feat: integrate coupon flow with backend

Signed-off-by: Aman <[email protected]>

* chor: fix lint issues

Signed-off-by: Aman <[email protected]>

---------

Signed-off-by: Aman <[email protected]>
Co-authored-by: Aman <[email protected]>
  • Loading branch information
Ayush0Chaudhary and aman-singh7 authored Feb 6, 2023
1 parent 33a20a3 commit a709737
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 216 deletions.
39 changes: 37 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: 20e59316b8b8474554b38493b8ca888794b0234a
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: android
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: ios
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: linux
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: macos
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: web
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: windows
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
21 changes: 20 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
include: package:pedantic/analysis_options.yaml
include: package:flutter_lints/flutter.yaml


linter:
rules:
constant_identifier_names: false
prefer_const_constructors: false
avoid_print: false
sized_box_for_whitespace: false
no_leading_underscores_for_local_identifiers: false
library_private_types_in_public_api: false
use_key_in_widget_constructors: false
unnecessary_string_interpolations: false
avoid_function_literals_in_foreach_calls: false
avoid_unnecessary_containers: false
prefer_const_constructors_in_immutables: false
prefer_interpolation_to_compose_strings: false
prefer_typing_uninitialized_variables: false
depend_on_referenced_packages: false

31 changes: 16 additions & 15 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PODS:
- Firebase/RemoteConfig (= 10.3.0)
- firebase_core
- Flutter
- FirebaseABTesting (10.3.0):
- FirebaseABTesting (10.4.0):
- FirebaseCore (~> 10.0)
- FirebaseAnalytics (10.3.0):
- FirebaseAnalytics/AdIdSupport (= 10.3.0)
Expand All @@ -54,9 +54,9 @@ PODS:
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreInternal (10.3.0):
- FirebaseCoreInternal (10.4.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseInstallations (10.3.0):
- FirebaseInstallations (10.4.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
Expand Down Expand Up @@ -109,7 +109,7 @@ PODS:
- GoogleUtilities/Network (~> 7.8)
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleDataTransport (9.2.0):
- GoogleDataTransport (9.2.1):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
Expand Down Expand Up @@ -140,8 +140,9 @@ PODS:
- OrderedSet (5.0.0)
- package_info_plus (0.4.5):
- Flutter
- path_provider_ios (0.0.1):
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- PromisesObjC (2.1.1)
- ReachabilitySwift (5.0.0)
- Sentry/HybridSDK (7.31.5)
Expand Down Expand Up @@ -169,7 +170,7 @@ DEPENDENCIES:
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`)
Expand Down Expand Up @@ -216,8 +217,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/fluttertoast/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/ios"
sentry_flutter:
:path: ".symlinks/plugins/sentry_flutter/ios"
share_plus:
Expand All @@ -234,32 +235,32 @@ SPEC CHECKSUMS:
firebase_core: bf59c32d2e53814f558efa20840c1902fa2fe461
firebase_messaging: ee597229fc260f8fa491fa8f2d4a32dfbfa406fa
firebase_remote_config: 5007603d4cec2dc1e5016077a7ec36ed93c5041b
FirebaseABTesting: e6660693429b4663573c82f8d2f1041deff1753a
FirebaseABTesting: ae3b32fe26e761fd54c68e37a632a0097b599c87
FirebaseAnalytics: 036232b6a1e2918e5f67572417be1173576245f3
FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a
FirebaseCoreInternal: 29b76f784d607df8b2a1259d73c3f04f1210137b
FirebaseInstallations: e2f26126089dcf41e215f7b8925af8d953c7d602
FirebaseCoreInternal: e301297f4c15a17489e48ed722d733b1578e0c02
FirebaseInstallations: 36b38c733fd37e50857e5e8d74138648f466f18c
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
FirebaseRemoteConfig: c24f767c17b0440ee63c7e93380d599173556113
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
fluttertoast: eb263d302cc92e04176c053d2385237e9f43fad0
GoogleAppMeasurement: c7d6fff39bf2d829587d74088d582e32d75133c3
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleDataTransport: ea169759df570f4e37bdee1623ec32a7e64e67c4
GoogleUtilities: c2bdc4cf2ce786c4d2e6b3bcfd599a25ca78f06f
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
Sentry: 4c9babff9034785067c896fd580b1f7de44da020
sentry_flutter: d3dad547d3db4918a8051a5ef738cc195c427b4b
sentry_flutter: b10ae7a5ddcbc7f04648eeb2672b5747230172f1
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
url_launcher_ios: ae1517e5e344f5544fb090b079e11f399dfbe4d2

PODFILE CHECKSUM: 0661a8b4d2adb53671731a5c90a8e5964fc4bf1f

Expand Down
4 changes: 3 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -220,6 +220,7 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -234,6 +235,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@
<false/>
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions lib/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class AppTheme {
color: blackSecondary,
fontFamily: 'OpenSans',
);
static TextStyle bodyText3 = TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
color: blackSecondary,
fontFamily: 'OpenSans',
);
static TextStyle overline = TextStyle(
fontSize: 6.sp,
fontWeight: FontWeight.w400,
Expand Down
2 changes: 2 additions & 0 deletions lib/locator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appetizer/services/analytics_service.dart';
import 'package:appetizer/services/api/coupon_api.dart';
import 'package:appetizer/services/api/feedback_api.dart';
import 'package:appetizer/services/api/leave_api.dart';
import 'package:appetizer/services/api/menu_api.dart';
Expand Down Expand Up @@ -45,6 +46,7 @@ import 'package:get_it/get_it.dart';
GetIt locator = GetIt.instance;

Future<void> setupLocator() async {
locator.registerLazySingleton(() => CouponApi());
locator.registerLazySingleton(() => FeedbackApi());
locator.registerLazySingleton(() => LeaveApi());
locator.registerLazySingleton(() => MenuApi());
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: deprecated_member_use

import 'package:appetizer/app_theme.dart';
import 'package:appetizer/config/environment_config.dart';
import 'package:appetizer/firebase_options.dart';
Expand Down
37 changes: 35 additions & 2 deletions lib/models/menu/week_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ class MealItem {
};
}

enum MealItemType { MCL, SLD, EXT, MCD, STR, SNK }
enum MealItemType { MCL, SLD, EXT, MCD, STR, SNK, CPN }

final breakfastTypeValues = EnumValues({
'ext': MealItemType.EXT,
'mcd': MealItemType.MCD,
'mcl': MealItemType.MCL,
'sld': MealItemType.SLD,
'snk': MealItemType.SNK,
'str': MealItemType.STR
'str': MealItemType.STR,
'cpn': MealItemType.CPN,
});

class DayMenu {
Expand Down Expand Up @@ -173,6 +174,7 @@ class Meal {
DateTime startTime;
DateTime endTime;
LeaveStatus leaveStatus;
CouponStatus couponStatus;
dynamic wastage;
bool isSwitchable;
SwitchStatus switchStatus;
Expand Down Expand Up @@ -200,6 +202,7 @@ class Meal {
required this.isLeaveToggleOutdated,
required this.startDateTime,
required this.endDateTime,
required this.couponStatus,
});

factory Meal.fromJson(Map<String, dynamic> json, DateTime date) => Meal(
Expand All @@ -211,6 +214,7 @@ class Meal {
startTime: DateFormat('HH:mm:ss').parse(json['start_time']),
endTime: DateFormat('HH:mm:ss').parse(json['end_time']),
leaveStatus: LeaveStatus.fromJson(json['leave_status']),
couponStatus: CouponStatus.fromJson(json['coupon_status']),
wastage: json['wastage'],
isSwitchable: json['is_switchable'] ?? false,
switchStatus: SwitchStatus.fromJson(json['switch_status']),
Expand Down Expand Up @@ -252,6 +256,7 @@ class Meal {
DateTime? startTime,
DateTime? endTime,
LeaveStatus? leaveStatus,
CouponStatus? couponStatus,
dynamic wastage,
bool? isSwitchable,
SwitchStatus? switchStatus,
Expand All @@ -270,6 +275,7 @@ class Meal {
startTime: startTime ?? this.startTime,
endTime: endTime ?? this.endTime,
leaveStatus: leaveStatus ?? this.leaveStatus,
couponStatus: couponStatus ?? this.couponStatus,
wastage: wastage ?? this.wastage,
isSwitchable: isSwitchable ?? this.isSwitchable,
switchStatus: switchStatus ?? this.switchStatus,
Expand Down Expand Up @@ -321,6 +327,26 @@ class LeaveStatus {
};
}

class CouponStatus {
int? id;
CouponStatusEnum status;

CouponStatus({
this.id,
required this.status,
});

factory CouponStatus.fromJson(Map<String, dynamic>? json) => CouponStatus(
id: json?['id'],
status: couponStatusValues.map[json?['status'] ?? 'N']!,
);

Map<String, dynamic> toJson() => {
'id': id,
'status': couponStatusValues.reverse[status],
};
}

class SwitchStatus {
int id;
SwitchStatusEnum status;
Expand All @@ -345,6 +371,13 @@ class SwitchStatus {

enum LeaveStatusEnum { N, A, D, P, U }

enum CouponStatusEnum { N, A }

final couponStatusValues = EnumValues({
'N': CouponStatusEnum.N,
'A': CouponStatusEnum.A,
});

final leaveStatusValues = EnumValues({
'N': LeaveStatusEnum.N,
'A': LeaveStatusEnum.A,
Expand Down
45 changes: 45 additions & 0 deletions lib/services/api/coupon_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:appetizer/config/environment_config.dart';
import 'package:appetizer/constants.dart';
import 'package:appetizer/models/failure_model.dart';
import 'package:appetizer/models/menu/week_menu.dart';
import 'package:appetizer/utils/api_utils.dart';
import 'package:http/http.dart' as http;

class CouponApi {
var headers = {'Content-Type': 'application/json'};
http.Client client = http.Client();

Future<CouponStatus> applyForCoupon(int mealId) async {
var endpoint = '/api/coupon/';
var uri = EnvironmentConfig.BASE_URL + endpoint;

try {
await ApiUtils.addTokenToHeaders(headers);
var jsonResponse =
await ApiUtils.post(uri, headers: headers, body: {'meal': mealId});

return CouponStatus(
status: CouponStatusEnum.A,
id: jsonResponse['id'],
);
} on Exception catch (e) {
print(e.toString());
throw Failure(Constants.GENERIC_FAILURE);
}
}

Future<CouponStatus> cancelCoupon(int couponId) async {
var endpoint = '/api/coupon/$couponId';
var uri = EnvironmentConfig.BASE_URL + endpoint;

try {
await ApiUtils.addTokenToHeaders(headers);
await ApiUtils.delete(uri, headers: headers);

return CouponStatus(status: CouponStatusEnum.N);
} on Exception catch (e) {
print(e.toString());
throw Failure(Constants.GENERIC_FAILURE);
}
}
}
Loading

0 comments on commit a709737

Please sign in to comment.