Skip to content

Commit

Permalink
refactor api urls
Browse files Browse the repository at this point in the history
  • Loading branch information
thealiflab committed Jul 6, 2021
1 parent 67cb1d8 commit 67d685f
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ lib/generated_plugin_registrant.dart
# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
/android/key.properties

# Hide API URLS
/lib/utilities/api_constants.dart
4 changes: 2 additions & 2 deletions lib/api/all_category_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -13,7 +13,7 @@ class AllCategoryAPI {

try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/category"),
Uri.parse(baseUrl + categoryExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
4 changes: 2 additions & 2 deletions lib/api/all_vendors_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -13,7 +13,7 @@ class AllVendorsAPI {

try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/vendor/0"),
Uri.parse(baseUrl + vendorsExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
4 changes: 2 additions & 2 deletions lib/api/category_vendors_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -13,7 +13,7 @@ class CategoryVendorsAPI {

try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/vendor/where/categoryId/$id"),
Uri.parse(baseUrl + categoryVendorsExt + id),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
4 changes: 2 additions & 2 deletions lib/api/claim_discount_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -11,7 +11,7 @@ class ClaimDiscountApi {
localStorage = await SharedPreferences.getInstance();
try {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/customer/claimDiscount"),
Uri.parse(baseUrl + claimDiscountExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
6 changes: 3 additions & 3 deletions lib/api/enter_otp_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -11,7 +11,7 @@ class EnterOTPApi {
try {
if (localStorage.getBool("resetPassword")) {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/forgotPassword"),
Uri.parse(baseUrl + forgetPasswordExt),
headers: <String, String>{
'State': 'Second',
},
Expand All @@ -25,7 +25,7 @@ class EnterOTPApi {
}
} else {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/customer/register"),
Uri.parse(baseUrl + registerExt),
headers: <String, String>{
'State': 'Second',
},
Expand Down
6 changes: 3 additions & 3 deletions lib/api/enter_phone_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -11,7 +11,7 @@ class EnterPhoneApi {
try {
if (localStorage.getBool("resetPassword")) {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/forgotPassword"),
Uri.parse(baseUrl + forgetPasswordExt),
headers: <String, String>{
'State': 'First',
},
Expand All @@ -25,7 +25,7 @@ class EnterPhoneApi {
}
} else {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/customer/register"),
Uri.parse(baseUrl + registerExt),
headers: <String, String>{
'State': 'First',
},
Expand Down
4 changes: 2 additions & 2 deletions lib/api/guest_login_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -9,7 +9,7 @@ class GuestLoginAPI {
Future<dynamic> getGData() async {
try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/guest/login"),
Uri.parse(baseUrl + guestLoginExt),
headers: <String, String>{
'X-Guest': 'guestLogin',
},
Expand Down
4 changes: 2 additions & 2 deletions lib/api/login_api.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';

class LoginService {
Future<LoginResponseModel> login(LoginRequestModel requestModel) async {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/login"),
Uri.parse(baseUrl + loginExt),
body: requestModel.toJson(),
);

Expand Down
4 changes: 2 additions & 2 deletions lib/api/logout_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -14,7 +14,7 @@ class LogoutAPI {

try {
http.Response response = await http.post(
Uri.parse("$baseUrl/api/v1/logout"),
Uri.parse(baseUrl + logoutExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
8 changes: 4 additions & 4 deletions lib/api/renew_subscription_api.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;

class RenewSubAPI {
//Get Request for Registration details
Future getRegistrationFee() async {
String url = "$baseUrl/api/v1/globals/registrationFee";
String url = baseUrl + registrationFeeExt;
localStorage = await SharedPreferences.getInstance();
String authorization = "Bearer ${localStorage.get('Authorization')}";
var response = await http.get(Uri.parse(url), headers: {
Expand All @@ -33,7 +33,7 @@ class RenewSubAPI {

// <===================== Get Request for Subscription details
Future getSubscriptionFee() async {
String url = "$baseUrl/api/v1/globals/subscriptionFee";
String url = baseUrl + subscriptionFeeExt;
localStorage = await SharedPreferences.getInstance();

String authorization = "Bearer ${localStorage.get('Authorization')}";
Expand Down Expand Up @@ -64,7 +64,7 @@ class RenewSubAPI {
try {
http.Response response = await http.get(
Uri.parse(
"$baseUrl/api/v1/customer/renewSubscription?subscription_limit=$month&transaction_id=$tID&subscription_fee=$fee"),
"$baseUrl$renewSubscriptionExt?subscription_limit=$month&transaction_id=$tID&subscription_fee=$fee"),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
4 changes: 2 additions & 2 deletions lib/api/top_vendors_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -13,7 +13,7 @@ class TopVendorsAPI {

try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/globals/topVendors"),
Uri.parse(baseUrl + topVendorExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
4 changes: 2 additions & 2 deletions lib/api/user_details_update_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';

SharedPreferences localStorage;

Expand All @@ -10,7 +10,7 @@ class UserDetailsUpdate {
localStorage = await SharedPreferences.getInstance();
try {
final response = await http.post(
Uri.parse("$baseUrl/api/v1/customer/update"),
Uri.parse(baseUrl + userDetailsUpdateExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
6 changes: 3 additions & 3 deletions lib/api/user_info_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dd_app/model/customer_info_model.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

SharedPreferences localStorage;
Expand All @@ -11,7 +11,7 @@ class UserInfoAPI {
localStorage = await SharedPreferences.getInstance();
try {
http.Response response = await http.get(
Uri.parse("$baseUrl/api/v1/customer"),
Uri.parse(baseUrl + customerExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand All @@ -28,7 +28,7 @@ class UserInfoAPI {
Future<CustomerInfoGetModel> getUserInfo() async {
localStorage = await SharedPreferences.getInstance();
var response = await http.get(
Uri.parse("$baseUrl/api/v1/customer"),
Uri.parse(baseUrl + customerExt),
headers: <String, String>{
'Authorization': 'Bearer ${localStorage.get('Authorization')}',
'Customer-ID': '${localStorage.get('Customer-ID')}',
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home_screen/drawer_per_user.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';

class DrawerPerUser extends StatelessWidget {
final String imageURL;
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home_screen/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'drawer_per_user.dart';
import 'open_qr_scanner.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:dd_app/api/user_info_api.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../search/search_bar_page.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/screens/profile_screen/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:dd_app/screens/home_screen/home_page.dart';
import 'package:dd_app/screens/profile_screen/profile_edit_screen.dart';
import 'package:dd_app/utilities/action_button.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import "package:flutter/material.dart";
import 'profile_info_panel.dart';
import 'package:dd_app/api/user_info_api.dart';
Expand Down
16 changes: 2 additions & 14 deletions lib/screens/profile_screen/profile_edit_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:dd_app/screens/home_screen/home_page.dart';
import 'package:dd_app/screens/profile_screen/profile.dart';
import "package:flutter/material.dart";
import 'package:dd_app/api/user_info_api.dart';
import 'package:dd_app/utilities/text_field_container.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:dd_app/utilities/action_button.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
Expand Down Expand Up @@ -39,18 +39,6 @@ class _ProfileEditState extends State<ProfileEdit> {
//http client
Dio dio = new Dio();

//refresh indicator
// var _refreshProfileKey = GlobalKey<RefreshIndicatorState>();
// Future<Null> refreshProfile() async {
// _refreshProfileKey.currentState?.show(atTop: false);
// await Future.delayed(Duration(seconds: 1));
// setState(() {
// imageCache.clear();
// imageCache.clearLiveImages();
// });
// return null;
// }

@override
void initState() {
apiData = userInfoAPI.getUData();
Expand Down Expand Up @@ -93,7 +81,7 @@ class _ProfileEditState extends State<ProfileEdit> {
{"profileImage": await MultipartFile.fromFile(imageFile.path)});

final response =
await dio.post("$baseUrl/api/v1/customer/update", data: formData);
await dio.post(baseUrl + userDetailsUpdateExt, data: formData);
print("upload image response data ${response.data}");
print(
"status of the resutl: ${json.decode(response.toString())['status']} <--");
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/search/search_bar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:dd_app/api/all_vendors_api.dart';
import 'package:dd_app/utilities/api_constants.dart';

SharedPreferences localStorage;
var dataFromAPI;
Expand Down Expand Up @@ -170,7 +171,7 @@ class _SearchBarPageState extends State<SearchBarPage> {

void _getVendorNames() async {
localStorage = await SharedPreferences.getInstance();
var url = Uri.parse('https://apps.dd.limited/api/v1/vendor/0');
var url = Uri.parse(baseUrl + vendorsExt);
http.Response response = await http.get(
url,
headers: <String, String>{
Expand Down
1 change: 1 addition & 0 deletions lib/utilities/claim_now_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:dd_app/utilities/snack_bar_message.dart';
import 'package:dd_app/api/claim_discount_api.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'dart:ui';

ClaimDiscountRequest claimDiscountRequest;
Expand Down
3 changes: 0 additions & 3 deletions lib/utilities/constants.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:flutter/material.dart';

//API Constants
const baseUrl = "https://apps.dd.limited";

//UI Constants
const kPrimaryColor = Color(0xFF24b5c4);
const kLightPrimaryColor = Color(0xFF34d3ae);
Expand Down
1 change: 1 addition & 0 deletions lib/utilities/vendor_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
import 'package:dd_app/utilities/constants.dart';
import 'package:dd_app/utilities/api_constants.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:dd_app/utilities/claim_now_alert_dialog.dart';

Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down

0 comments on commit 67d685f

Please sign in to comment.