Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
183
lib/services/all_certificate_service.dart
Normal file
183
lib/services/all_certificate_service.dart
Normal file
@ -0,0 +1,183 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/certificate_model.dart';
|
||||
import 'package:initial_folder/models/check_certificate.model.dart';
|
||||
import 'package:initial_folder/models/my_certificate.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:pdf/pdf.dart';
|
||||
|
||||
class AllCertificateServices {
|
||||
Future<Map<String, dynamic>> uploadCertificate(
|
||||
String idPayment, File pdfFile) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
try {
|
||||
Uri url = Uri.parse("$baseUrl/users/upload-sertifikat/$idPayment");
|
||||
|
||||
var request = http.MultipartRequest('POST', url);
|
||||
|
||||
request.headers.addAll(headerWithToken(token));
|
||||
request.files
|
||||
.add(await http.MultipartFile.fromPath('file', pdfFile.path));
|
||||
|
||||
var response = await request.send();
|
||||
var responseData = await response.stream.bytesToString();
|
||||
var jsonData = json.decode(responseData);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
throw ("Sertifikat berhasil di unduh");
|
||||
} else {
|
||||
throw Exception('Gagal mengunggah sertifikat: ${jsonData['message']}');
|
||||
}
|
||||
} catch (e) {
|
||||
return {'status': 500, 'error': true, 'message': e.toString()};
|
||||
}
|
||||
}
|
||||
|
||||
Future getAllCertificate() async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse("$baseUrl/homepage/get_all_sertifikat/$idUser");
|
||||
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<DataMyCertificateModel> certif = [];
|
||||
|
||||
for (var item in data) {
|
||||
certif.add(DataMyCertificateModel.fromJson(item));
|
||||
}
|
||||
|
||||
return certif;
|
||||
} else {
|
||||
throw Exception('Data Kursus Teratas Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future getSertif(String idCourse) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url =
|
||||
Uri.parse("$baseUrl/homepage/sertifikat/$idUser?course_id=$idCourse");
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'];
|
||||
List<CertificateModel> certif = [];
|
||||
|
||||
for (var item in data) {
|
||||
certif.add(CertificateModel.fromJson(item));
|
||||
}
|
||||
|
||||
print("ini data sertif dari api : ${response.body}");
|
||||
|
||||
return certif;
|
||||
} else {
|
||||
throw Exception('Data Kursus Teratas Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future checkSertif(String text) async {
|
||||
print("Ini sertif ${text}");
|
||||
Uri url = Uri.parse("$baseUrl/homepage/cek_status_sertifikat/$text");
|
||||
var response = await http.get(url);
|
||||
var data = jsonDecode(response.body);
|
||||
|
||||
if (data['status'] == 200) {
|
||||
if (data != null && data['data'] != null && data['data'].length > 0) {
|
||||
var certifData = data['data'][0];
|
||||
CheckCertificateData certif = CheckCertificateData.fromJson(certifData);
|
||||
print("Berhasil cek sertif ${response.body}");
|
||||
return certif;
|
||||
} else {
|
||||
print("Kosong cek sertif ${response.body}");
|
||||
return null;
|
||||
}
|
||||
} else if (data['status'] == 404) {
|
||||
print("Gagal cek sertif ${response.body}");
|
||||
return data['massages'] != null
|
||||
? data['massages']
|
||||
: "Error message not available";
|
||||
}
|
||||
}
|
||||
|
||||
Future searchCertif(String keyword) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse(
|
||||
"$baseUrl/homepage/search_sertifikat/$idUser?keyword=$keyword");
|
||||
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
List<DataMyCertificateModel> certif = [];
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
|
||||
for (var item in data) {
|
||||
certif.add(DataMyCertificateModel.fromJson(item));
|
||||
}
|
||||
|
||||
return certif;
|
||||
} else if (response.statusCode == 400) {
|
||||
return certif;
|
||||
} else {
|
||||
return certif;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> convertAndUpload(GlobalKey _globalKey, String idPayment) async {
|
||||
try {
|
||||
RenderRepaintBoundary boundaryRenderObject =
|
||||
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
|
||||
ui.Image image = await boundaryRenderObject.toImage(pixelRatio: 3.0);
|
||||
ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
Uint8List pngBytes = byteData!.buffer.asUint8List();
|
||||
|
||||
final pdf = pw.Document();
|
||||
|
||||
final pdfPageFormat = PdfPageFormat.a4.landscape.copyWith(
|
||||
marginBottom: 0,
|
||||
marginTop: 0,
|
||||
marginLeft: 0,
|
||||
marginRight: 0,
|
||||
);
|
||||
|
||||
pdf.addPage(
|
||||
pw.Page(
|
||||
pageFormat: pdfPageFormat,
|
||||
build: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Image(pw.MemoryImage(pngBytes),
|
||||
fit: pw.BoxFit.cover, ),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Directory tempDir = await getTemporaryDirectory();
|
||||
String tempPath = '${tempDir.path}/certificate_${idPayment}.pdf';
|
||||
File tempFile = File(tempPath);
|
||||
|
||||
await tempFile.writeAsBytes(await pdf.save());
|
||||
|
||||
await uploadCertificate(idPayment, tempFile);
|
||||
} catch (e) {
|
||||
throw Exception('Gagal mengonversi PNG ke PDF: $e');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
62
lib/services/announcement_service.dart
Normal file
62
lib/services/announcement_service.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/announcement_model.dart';
|
||||
import 'package:initial_folder/models/section_model.dart';
|
||||
|
||||
class AnnouncementService {
|
||||
Future<AnnouncementModel> getAnnouncement(String idCourse) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/announcement/$idCourse');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return AnnouncementModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> replyAnnouncement(
|
||||
String tokenAnnouncement, String textBody, String idAnnouncement) async {
|
||||
int? userId = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/announcement/reply');
|
||||
|
||||
var body = jsonEncode({
|
||||
"sender": userId,
|
||||
"token": tokenAnnouncement,
|
||||
"replies": idAnnouncement,
|
||||
"body": textBody,
|
||||
});
|
||||
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> likeAnnouncement(String tokenAnnouncement) async {
|
||||
int? userId = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/announcement/like');
|
||||
|
||||
var body = jsonEncode({"id_user": userId, "token": tokenAnnouncement});
|
||||
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
115
lib/services/auth_service.dart
Normal file
115
lib/services/auth_service.dart
Normal file
@ -0,0 +1,115 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/user_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class AuthService {
|
||||
Future<UserModel> register({
|
||||
required String name,
|
||||
required String email,
|
||||
required String password,
|
||||
required String phoneNumber,
|
||||
}) async {
|
||||
print('[DEBUG] Register called with: name=$name, email=$email, phone=$phoneNumber');
|
||||
Uri url = Uri.parse('$baseUrl/auth/register');
|
||||
var body = jsonEncode({
|
||||
'name': name,
|
||||
'email': email,
|
||||
'password': password,
|
||||
'phone': phoneNumber,
|
||||
});
|
||||
|
||||
print('[DEBUG] Register URL: $url');
|
||||
print('[DEBUG] Register Body: $body');
|
||||
|
||||
var response = await http.post(url, headers: baseHeader, body: body);
|
||||
print('[DEBUG] Register Response: ${response.statusCode} ${response.body}');
|
||||
if (response.statusCode == 201) {
|
||||
return UserModel.fromJson(jsonDecode(response.body)['data']);
|
||||
} else if (response.statusCode == 403) {
|
||||
var responseData = jsonDecode(response.body)['data']['message'];
|
||||
print('[DEBUG] Register 403 ResponseData: $responseData');
|
||||
if (responseData.containsKey('email')) {
|
||||
throw ('Failed\n\nEmail sudah terdaftar');
|
||||
} else if (responseData.containsKey('phone')) {
|
||||
throw ('Failed\n\nNomor HP sudah terdaftar');
|
||||
} else {
|
||||
throw ('Registrasi gagal. Mohon coba lagi.');
|
||||
}
|
||||
} else {
|
||||
throw ('Registrasi gagal. Mohon coba lagi.');
|
||||
}
|
||||
}
|
||||
|
||||
Future<UserModel> login(
|
||||
{required String email, required String password}) async {
|
||||
print('[DEBUG] Login called with: email=$email');
|
||||
Uri url = Uri.parse('$baseUrl/auth/mobile/login');
|
||||
var body = jsonEncode({
|
||||
'email': email,
|
||||
'password': password,
|
||||
});
|
||||
print('[DEBUG] Login URL: $url');
|
||||
print('[DEBUG] Login Body: $body');
|
||||
var response = await http.post(url, headers: baseHeader, body: body);
|
||||
print('[DEBUG] Login Response: ${response.statusCode} ${response.body}');
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'];
|
||||
UserModel user = UserModel.fromJson(data);
|
||||
user.token = data['token'];
|
||||
|
||||
await UsersInfo().setToken(user.token!);
|
||||
|
||||
return user;
|
||||
} else {
|
||||
throw Exception('Gagal login mobile');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> googleSignInAuth({
|
||||
required String idToken,
|
||||
}) async {
|
||||
print('[DEBUG] GoogleSignInAuth called with idToken=$idToken');
|
||||
Uri url = Uri.parse('$baseUrl/auth/googlecheck/signin');
|
||||
var body = jsonEncode({
|
||||
'id_token': idToken,
|
||||
});
|
||||
print('[DEBUG] GoogleSignInAuth URL: $url');
|
||||
print('[DEBUG] GoogleSignInAuth Body: $body');
|
||||
var response = await http.post(url, headers: baseHeader, body: body);
|
||||
print('[DEBUG] GoogleSignInAuth Response: ${response.statusCode} ${response.body}');
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 403) {
|
||||
var res = jsonDecode(response.body)['data'];
|
||||
print('[DEBUG] GoogleSignInAuth Token: ${res['token']}');
|
||||
await UsersInfo().setToken(res['token']);
|
||||
return true;
|
||||
} else if (response.statusCode == 400) {
|
||||
print("Gagal login 400 ${response.body}");
|
||||
throw Exception('Akun anda belum terdaftar');
|
||||
} else {
|
||||
print("Gagal login google ${response.body}");
|
||||
throw Exception('Gagal login');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> checkToken(String? token) async {
|
||||
print('[DEBUG] checkToken called with token=$token');
|
||||
Uri url = Uri.parse('$baseUrl/users/course/my');
|
||||
print('[DEBUG] checkToken URL: $url');
|
||||
var response = await http.get(url, headers: headerWithToken(token));
|
||||
print('[DEBUG] checkToken Response: ${response.statusCode} ${response.body}');
|
||||
if (response.statusCode == 200) {
|
||||
print("Berhasil token ${response.body}");
|
||||
return false;
|
||||
} else if (response.statusCode == 404) {
|
||||
print("404 token ${response.body}");
|
||||
return false;
|
||||
} else {
|
||||
print("Gagal token ${response.body}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
34
lib/services/banners_service.dart
Normal file
34
lib/services/banners_service.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/banners_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class BannersService {
|
||||
Future<Map<String, dynamic>> getAllBanners() async {
|
||||
Uri url = Uri.parse('$baseUrl/mobile/banners');
|
||||
var header = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Connection': 'Keep-Alive'
|
||||
};
|
||||
var response = await http.get(url, headers: header);
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
|
||||
List<BannersModel> banners = [];
|
||||
print("Berhasil banner${response.body}");
|
||||
for (var item in data) {
|
||||
if (item['status'] == '1') {
|
||||
banners.add(BannersModel.fromJson(item));
|
||||
}
|
||||
}
|
||||
return {'status': response.statusCode, 'data': banners};
|
||||
} else if (response.statusCode == 404) {
|
||||
print("Banner kosong, saat ini running banner default. ${response.body}");
|
||||
return {'status': response.statusCode, 'data': []};
|
||||
} else {
|
||||
print("Gagal banner ${response.body}");
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
}
|
29
lib/services/cancel_payment_service.dart
Normal file
29
lib/services/cancel_payment_service.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CancelPaymentService {
|
||||
Future<String> cancelPayment(String paymentId) async {
|
||||
print("Ini id payment?${paymentId}");
|
||||
var token = await UsersInfo().getToken();
|
||||
var idUser = await UsersInfo().getIdUser();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/payment/cancel-payment');
|
||||
|
||||
var body = jsonEncode({
|
||||
'id_payment': paymentId,
|
||||
});
|
||||
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 201) {
|
||||
print("Berhasil cancel cuy${response.body}");
|
||||
return 'Transaksi berhasil dibatalkan';
|
||||
} else {
|
||||
print("Ga berhasil cancel cuy${response.body}");
|
||||
return 'Gagal, pembayaran sudah dibatalkan atau kadaluwarsa';
|
||||
}
|
||||
}
|
||||
}
|
63
lib/services/cart_service.dart
Normal file
63
lib/services/cart_service.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/carts_model.dart';
|
||||
|
||||
class CartService {
|
||||
Future<bool> addCart(idCourse) async {
|
||||
var token = await UsersInfo().getToken();
|
||||
var idUser = await UsersInfo().getIdUser();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/users/add-to-cart');
|
||||
|
||||
var body = jsonEncode({
|
||||
// 'id_user': idUser,
|
||||
'cart_item': idCourse,
|
||||
});
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 201) {
|
||||
return true;
|
||||
} else {
|
||||
throw Exception('Gagal Menambahkan ke keranjang');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteCart(idCart) async {
|
||||
var token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/users/cart/delete/$idCart');
|
||||
|
||||
http.Response response = await http.delete(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
throw Exception('Gagal Menghapus keranjang');
|
||||
}
|
||||
}
|
||||
|
||||
Future<CartsModel> getCarts() async {
|
||||
var token = await UsersInfo().getToken();
|
||||
// var idUser = await UsersInfo().getIdUser();
|
||||
|
||||
// Uri url = Uri.parse('$baseUrl/users/carts/$idUser');
|
||||
Uri url = Uri.parse('$baseUrl/users/carts');
|
||||
http.Response response = await http.get(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
log(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
print("Ini isi cart berhasil ${response.body}");
|
||||
return CartsModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Mengambil data keranjang');
|
||||
}
|
||||
}
|
||||
}
|
48
lib/services/categories_service.dart
Normal file
48
lib/services/categories_service.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/catagories_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/subcategories_model.dart';
|
||||
|
||||
class CategoriesService {
|
||||
Future<List<CategoriesModel>> getAllCategories() async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/categories');
|
||||
|
||||
var header = {'Content-Type': 'application/json; charset=UTF-8'};
|
||||
var response = await http.get(url, headers: header);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CategoriesModel> categories = [];
|
||||
int categoriesAdded = 0;
|
||||
|
||||
for (var item in data) {
|
||||
if (item['parent_category'] == '0' && categoriesAdded < 9) {
|
||||
categories.add(CategoriesModel.fromJson(item));
|
||||
categoriesAdded++;
|
||||
}
|
||||
}
|
||||
|
||||
return categories;
|
||||
} else {
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SubCategoryModel>> getSubCategories(String id) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/subcategories/$id');
|
||||
var header = {'Content-Type': 'application/json; charset=UTF-8'};
|
||||
var response = await http.get(url, headers: header);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<dynamic> data = jsonDecode(response.body);
|
||||
List<SubCategoryModel> subCategories = data
|
||||
.map((subCategoryJson) => SubCategoryModel.fromJson(subCategoryJson))
|
||||
.toList();
|
||||
return subCategories;
|
||||
} else {
|
||||
throw Exception('Failed to load subcategories');
|
||||
}
|
||||
}
|
||||
}
|
37
lib/services/coupon_service.dart
Normal file
37
lib/services/coupon_service.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/discount_course_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CouponService {
|
||||
Future<dynamic> getDiscountCourse(coupon) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/exchange-coupon?voucher=$coupon');
|
||||
print("Ini url api ${url}");
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
if (response.statusCode == 200) {
|
||||
print("Berhasil kupon ${response.body}");
|
||||
Map body = jsonDecode(response.body);
|
||||
var data = body['data'];
|
||||
List<DiscountCourseModel> course = [];
|
||||
String message = '';
|
||||
|
||||
if (data is List) {
|
||||
for (var item in data) {
|
||||
course.add(DiscountCourseModel.fromJson(item));
|
||||
}
|
||||
return course;
|
||||
} else {
|
||||
message = data['message'];
|
||||
return message;
|
||||
}
|
||||
} else {
|
||||
print("Gagal kupon ${response.body}");
|
||||
throw Exception('Data Kursus kupon gagal diambil');
|
||||
}
|
||||
}
|
||||
}
|
51
lib/services/course_by_category_service.dart
Normal file
51
lib/services/course_by_category_service.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
|
||||
class CourseByCategoryService {
|
||||
Future<List<CourseModel>> getCourseCategoryAndSub(categoryId, subId) async {
|
||||
print('ID kategori: $categoryId');
|
||||
print('ID SUb kategori: $subId');
|
||||
Uri url = Uri.parse(
|
||||
'$baseUrl/homepage/courses?category=$categoryId&subcategory=$subId');
|
||||
var header = {'Content-Type': 'application/json; charset=UTF-8'};
|
||||
var response = await http.get(url, headers: header);
|
||||
print(url);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> courseByCategory = [];
|
||||
for (var item in data) {
|
||||
courseByCategory.add(CourseModel.fromJson(item));
|
||||
}
|
||||
print("Berhasil kursus sub kategori ${response.body}");
|
||||
return courseByCategory;
|
||||
} else {
|
||||
print("Gagal kursus sub kategori ${response.body}");
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<CourseModel>> getCourseOnlyCategory(categoryId) async {
|
||||
print('ID kategori: $categoryId');
|
||||
Uri url = Uri.parse('$baseUrl/homepage/courses?category=$categoryId');
|
||||
var header = {'Content-Type': 'application/json; charset=UTF-8'};
|
||||
var response = await http.get(url, headers: header);
|
||||
print(url);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> courseByCategory = [];
|
||||
for (var item in data) {
|
||||
courseByCategory.add(CourseModel.fromJson(item));
|
||||
}
|
||||
print("Berhasil kursus kategori ${response.body}");
|
||||
return courseByCategory;
|
||||
} else {
|
||||
print("Gagal kursus kategori ${response.body}");
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
}
|
190
lib/services/course_service.dart
Normal file
190
lib/services/course_service.dart
Normal file
@ -0,0 +1,190 @@
|
||||
import 'dart:convert';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/detail_course_model.dart';
|
||||
import 'package:initial_folder/models/detail_rating_course_model.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/models/my_course_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CourseService {
|
||||
Future<List<CourseModel>> getOthersCourse(page) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/courses?page=$page&limit=10');
|
||||
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> course = [];
|
||||
for (var item in data) {
|
||||
course.add(CourseModel.fromJson(item));
|
||||
}
|
||||
|
||||
return course;
|
||||
} else {
|
||||
throw Exception('Data Kursus lainnya Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<DetailCourseModel> getDetailCourse(String id) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/course/$id');
|
||||
String? token = await UsersInfo().getToken();
|
||||
var response;
|
||||
if (token == null) {
|
||||
response = await http.get(url, headers: baseHeader);
|
||||
} else {
|
||||
response = await http.get(url, headers: headerWithToken(token));
|
||||
}
|
||||
if (response.statusCode == 200) {
|
||||
print("Berhasil detail course ${response.body}");
|
||||
return DetailCourseModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
print("Gagal detail course ${response.body}");
|
||||
throw Exception('Data Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<DataDetailCourseModel> getDetailCourseCoupon(
|
||||
String id, String coupon) async {
|
||||
Uri url = Uri.parse('$baseUrl/mobile/course-discount/$id/$coupon');
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
if (response.statusCode == 200) {
|
||||
Map body = jsonDecode(response.body);
|
||||
var data = body['data'];
|
||||
print("Ini sukses detail kupon ${response.body}");
|
||||
return DataDetailCourseModel.fromJson(data);
|
||||
} else {
|
||||
print("Ini gagal detail kupon ${response.body}");
|
||||
throw Exception('Data Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<DetailCourseModel> getDetailCourseLogin(String id) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/homepage/course/$id');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print("Berhasil detail course ${response.body}");
|
||||
return DetailCourseModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
print("Gagal detail course ${response.body}");
|
||||
throw Exception('Data Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<RatingCourseDetailModel> getRatingDetailCourse(String id) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/course/rating/$id');
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
if (response.statusCode == 200) {
|
||||
return RatingCourseDetailModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Rating Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<MyCourseModel> getMyCourse() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/course/my');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
if (response.statusCode == 200) {
|
||||
print('getmycourse berhasil');
|
||||
print("Berhasil getmycourse ${response.body}");
|
||||
return MyCourseModel.fromJson(jsonDecode(response.body));
|
||||
} else if (response.statusCode == 404) {
|
||||
print('getmycourse eror');
|
||||
return MyCourseModel(data: [[]]);
|
||||
} else {
|
||||
print('getmycourse gagal');
|
||||
throw Exception('Data Kursus Saya, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<MyCourseModel> getSearchMyCourse(String courseName) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse(
|
||||
'$baseUrl/users/course/my_course_keyword_search?keyword=$courseName');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
if (response.statusCode == 200) {
|
||||
print(response.body);
|
||||
return MyCourseModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Kursus Saya, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List> postingReviewCourse(
|
||||
String review, int courseId, int valueRating) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/review');
|
||||
var body = jsonEncode(
|
||||
{"rating": valueRating, "course_id": courseId, "review": review});
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return [true, response.statusCode];
|
||||
} else {
|
||||
return [false, 400];
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<CourseModel>> getTopCourse() async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/courses?top_course=1');
|
||||
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> course = [];
|
||||
for (var item in data) {
|
||||
course.add(CourseModel.fromJson(item));
|
||||
}
|
||||
|
||||
return course;
|
||||
} else {
|
||||
throw Exception('Data Kursus Teratas Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<CourseModel>> getPromoCourse() async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/promo-courses');
|
||||
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> course = [];
|
||||
print("Berhasil data promo${response.body}");
|
||||
for (var item in data) {
|
||||
course.add(CourseModel.fromJson(item));
|
||||
}
|
||||
|
||||
return course;
|
||||
}else if (response.statusCode == 404) {
|
||||
print("Promo kosong, tidak ada promo. ${response.body}");
|
||||
return [];
|
||||
} else {
|
||||
throw Exception('Data Kursus Promo Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<CourseModel>> getLatestCourse() async {
|
||||
Uri url = Uri.parse('$baseUrl/mobile/newcourse');
|
||||
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> course = [];
|
||||
for (var item in data) {
|
||||
course.add(CourseModel.fromJson(item));
|
||||
}
|
||||
return course;
|
||||
} else {
|
||||
throw Exception('Data Kursus Teratas Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
27
lib/services/current_lesson_service.dart
Normal file
27
lib/services/current_lesson_service.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/lesson_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CurrentLessonService {
|
||||
Future<LessonModel> getCurrentLesson(String lessonId) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
print(
|
||||
"Ini Current Lesson ID ----------------------------------> : $lessonId");
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/users/course/my/lesson/$lessonId');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
print("Ini Current Lesson ------------------------> : ${response.body}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return LessonModel.fromJson(jsonDecode(response.body)["data"][0]);
|
||||
} else {
|
||||
throw Exception('Data Lesson Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
32
lib/services/detail_invoice_service.dart
Normal file
32
lib/services/detail_invoice_service.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/detail_invoice_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class DetailInvoiceService {
|
||||
Future<List<DataDetailInvoiceModel>> detailInvoice(String? orderId) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/payment/invoice-detail/$orderId');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
List<DataDetailInvoiceModel> detailOrder = [];
|
||||
if (response.statusCode == 200) {
|
||||
print("BERHASIL COKKKK");
|
||||
var data = jsonDecode(response.body);
|
||||
print("Ini response berhasil get detail transaksi ${response.body}");
|
||||
|
||||
var list = data['data'] as List;
|
||||
detailOrder =
|
||||
list.map((item) => DataDetailInvoiceModel.fromJson(item)).toList();
|
||||
|
||||
return detailOrder;
|
||||
} else {
|
||||
print("GAGAL COKKKK");
|
||||
throw Exception('Data Transaksi Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
22
lib/services/forgot_password_service.dart
Normal file
22
lib/services/forgot_password_service.dart
Normal file
@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../base_service.dart';
|
||||
import '../models/forgot_password_model.dart';
|
||||
|
||||
class ForgotService {
|
||||
Future<ForgotPasswordModel> forgotPassword({
|
||||
required String email,
|
||||
}) async {
|
||||
Uri url = Uri.parse('$baseUrl/auth/mobile/forgot-password');
|
||||
var body = jsonEncode({
|
||||
'email': email,
|
||||
});
|
||||
|
||||
var response = await http.post(url, headers: baseHeader, body: body);
|
||||
if (response.statusCode == 200) {
|
||||
return ForgotPasswordModel.fromJson(jsonDecode(response.body)['data']);
|
||||
} else {
|
||||
throw response.body;
|
||||
}
|
||||
}
|
||||
}
|
53
lib/services/history_transactions_service.dart
Normal file
53
lib/services/history_transactions_service.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/history_transaction_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class HistoryTransactionService {
|
||||
Future<List<HistoryTransactionModel>> historyTransactions() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/payment/history');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
List<HistoryTransactionModel> history = [];
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
print("Data riwayat transaksi ${data}");
|
||||
int i = 0;
|
||||
|
||||
for (var item in data) {
|
||||
history.add(HistoryTransactionModel.fromJson(item));
|
||||
i++;
|
||||
}
|
||||
print("Berhasil riwayat transaksi ${response.body}");
|
||||
return history;
|
||||
} else {
|
||||
print("Gagal riwayat transaksi ${response.body}");
|
||||
throw Exception('Data Transaksi Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
// Fungsi cek expired
|
||||
Future<bool> checkTransactionExpiration(String orderId) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
if (token == null) {
|
||||
throw Exception('Token tidak ditemukan. Silakan login kembali.');
|
||||
}
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/payment/check-expiration/$orderId');
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token));
|
||||
|
||||
if (response.statusCode == 210) {
|
||||
print('transaksi SUDAH KEDALUARSA');
|
||||
return false;
|
||||
} else {
|
||||
print("Error memeriksa masa berlaku transaksi: ${response.body}");
|
||||
throw Exception('Gagal memeriksa status transaksi');
|
||||
}
|
||||
}
|
||||
}
|
18
lib/services/instructor_service.dart
Normal file
18
lib/services/instructor_service.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/instructor_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class InstructorService {
|
||||
Future<InstructorModel> getInstructorProfile(id) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/course/detail/instructor/$id');
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
print('instructor' + response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return InstructorModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Profile Instruktur Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
67
lib/services/lesson_course_service.dart
Normal file
67
lib/services/lesson_course_service.dart
Normal file
@ -0,0 +1,67 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/lesson_course_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/section_model.dart';
|
||||
|
||||
class LessonCourseService {
|
||||
Future<LessonCourseModel> getLessonCourse(int id) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
|
||||
// Uri url =
|
||||
// Uri.parse('$baseUrl/users/course/my/lesson?course=$id&user=$idUser');
|
||||
Uri url = Uri.parse('$baseUrl/users/course/my/lesson?course=$id');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
print(token);
|
||||
print("disiiniii les ---->" + response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return LessonCourseModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Lesson Kursus Saya, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future<SectionModel> getSectionCourse(int id) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
|
||||
Uri url = Uri.parse(
|
||||
'$baseUrl/users/course/my/lesson?course=$id&user=$idUser&is_mobile_request=1');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
print("disiiniii sect ---->" + response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return SectionModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
print('masuk sini juga');
|
||||
throw Exception('Data Lesson Kursus Saya, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future updateLessonCourse(lessonId, {progress = 1}) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
var body = jsonEncode({
|
||||
"id_user": idUser,
|
||||
"lesson_id": lessonId,
|
||||
"progress": progress,
|
||||
});
|
||||
Uri url = Uri.parse('$baseUrl/users/lesson/update/progress');
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return response.statusCode;
|
||||
} else {
|
||||
print(response.statusCode);
|
||||
print('TERJADI ERROR DALAM UPDATE CEKLIS');
|
||||
// throw Exception('Gagal Update');
|
||||
}
|
||||
}
|
||||
}
|
32
lib/services/local_notification_service.dart
Normal file
32
lib/services/local_notification_service.dart
Normal file
@ -0,0 +1,32 @@
|
||||
// import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
// import 'package:rxdart/rxdart.dart';
|
||||
//
|
||||
// class LocalNotification {
|
||||
// static final _notification = FlutterLocalNotificationsPlugin();
|
||||
// static final onNotification = BehaviorSubject<String?>();
|
||||
// static Future _notificationDetails() async{
|
||||
// return NotificationDetails(
|
||||
// android: AndroidNotificationDetails(
|
||||
// 'channel id',
|
||||
// 'channel name',
|
||||
// 'channel description',
|
||||
// importance: Importance.max
|
||||
// )
|
||||
// ,iOS: IOSNotificationDetails()
|
||||
// );
|
||||
// }
|
||||
// static Future init({bool initScheduled = false}) async{
|
||||
// final android = AndroidInitializationSettings('@mipmap/ic_launcher');
|
||||
// final iOS = IOSInitializationSettings();
|
||||
// final settings = InitializationSettings(android: android ,iOS: iOS);
|
||||
//
|
||||
// await _notification.initialize(settings, onSelectNotification: (payload) async{onNotification.add(payload);});
|
||||
// }
|
||||
// static Future showNotification({
|
||||
// int id = 0,
|
||||
// String? title,
|
||||
// String? body,
|
||||
// String? payload,
|
||||
// }) async =>
|
||||
// _notification.show(id, title, body, await _notificationDetails(), payload: payload);
|
||||
// }
|
70
lib/services/notification_service.dart
Normal file
70
lib/services/notification_service.dart
Normal file
@ -0,0 +1,70 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/notification.dart';
|
||||
import '../base_service.dart';
|
||||
|
||||
class NotificationServices {
|
||||
Future getNotification() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse("$baseUrl/homepage/list_notification");
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
if (response.statusCode == 200) {
|
||||
var dataUsersQNA = jsonDecode(response.body)['data']['users']['qna'];
|
||||
var dataUsersCourses =
|
||||
jsonDecode(response.body)['data']['users']['courses'];
|
||||
var dataUsersAnnouncement =
|
||||
jsonDecode(response.body)['data']['users']['announcement'];
|
||||
var dataInstructorQNA =
|
||||
jsonDecode(response.body)['data']['instructur']['qna'];
|
||||
var dataInstructorCourses =
|
||||
jsonDecode(response.body)['data']['instructur']['courses_added'];
|
||||
var dataInstructorAnnouncement =
|
||||
jsonDecode(response.body)['data']['instructur']['announcement'];
|
||||
List<NotificationData> data = [];
|
||||
List<NotificationDataAnnouncementUser> dataAnnouncement = [];
|
||||
for (var item in dataUsersQNA) {
|
||||
data.add(NotificationData.qnaFromJson(item));
|
||||
}
|
||||
for (var item in dataUsersCourses) {
|
||||
data.add(NotificationData.coursesFromJson(item));
|
||||
}
|
||||
// for (var item in dataUsersAnnouncement) {
|
||||
// data.add(NotificationData.announcementFromJson(item));
|
||||
// }
|
||||
for (var item in dataInstructorQNA) {
|
||||
data.add(NotificationData.qnaFromJson(item));
|
||||
}
|
||||
for (var item in dataInstructorCourses) {
|
||||
data.add(NotificationData.coursesFromJson(item));
|
||||
}
|
||||
// for (var item in dataInstructorAnnouncement) {
|
||||
// data.add(NotificationData.announcementFromJson(item));
|
||||
// }
|
||||
return [data, dataAnnouncement];
|
||||
} else {
|
||||
throw Exception('Data Kursus Teratas Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future readAllNotification() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse("$baseUrl/homepage/mark_as_read");
|
||||
var response = await http.patch(url, headers: headerWithToken(token));
|
||||
}
|
||||
|
||||
Future readNotification(String idRead, String ket) async {
|
||||
Uri url =
|
||||
Uri.parse("$baseUrl/homepage/read/notification?id=$idRead&ket=$ket");
|
||||
// var body = jsonEncode({"id": int.parse(idRead), "ket": ket});
|
||||
var response = await http.patch(url);
|
||||
}
|
||||
|
||||
Future countNotification() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse("$baseUrl/homepage/list_notification");
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
return jsonDecode(response.body)['data']['count_is_read'];
|
||||
}
|
||||
}
|
117
lib/services/payment_service.dart
Normal file
117
lib/services/payment_service.dart
Normal file
@ -0,0 +1,117 @@
|
||||
import 'dart:convert';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/zero_price_model.dart';
|
||||
|
||||
class PaymentServices {
|
||||
Uri _freeUrl = Uri.parse('$baseUrl/users/payment/free-course');
|
||||
Uri _freeUrlCoupon = Uri.parse('$baseUrl/users/coupon-payment-free');
|
||||
Uri _paidurl = Uri.parse("$baseUrl/payment/charge");
|
||||
Uri _zeroPay = Uri.parse("$baseUrl/payment/zero-price-payment");
|
||||
|
||||
Future<Map<String, String>> getSnapTransactionToken({
|
||||
required String orderId,
|
||||
required int grossAmount,
|
||||
required List<Map<String, dynamic>> dataInvoice,
|
||||
}) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
};
|
||||
|
||||
var body = jsonEncode({
|
||||
"code_coupon": null,
|
||||
"code_referal": null,
|
||||
"data_invoice": dataInvoice,
|
||||
"total_payment": grossAmount,
|
||||
});
|
||||
|
||||
print("Request Body: $body");
|
||||
|
||||
var response = await http.post(_paidurl, headers: headers, body: body);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
String transactionToken = responseData['token'];
|
||||
String redirectUrl = responseData['redirect_url'];
|
||||
|
||||
return {
|
||||
'transactionToken': transactionToken,
|
||||
'redirect_url': redirectUrl,
|
||||
};
|
||||
} else {
|
||||
print("Gagal mendapatkan token transaksi: ${response.body}");
|
||||
throw Exception('Gagal mendapatkan token transaksi');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> freeCoure(int idCourse) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
var body = jsonEncode({
|
||||
"course_id": idCourse,
|
||||
});
|
||||
|
||||
http.Response response = await http.post(_freeUrl, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
print("Berhasil bayar kursus gratis: ${response.body}");
|
||||
return true;
|
||||
} else if (response.statusCode == 400) {
|
||||
print("Gagal bayar gratis: ${response.body}");
|
||||
return false;
|
||||
} else {
|
||||
throw Exception('Gagal Membeli kursus');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> freeCoureCoupon(int idCourse, String coupon) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
var body = jsonEncode({
|
||||
"course_id": idCourse,
|
||||
"coupon": coupon,
|
||||
});
|
||||
|
||||
http.Response response = await http.post(_freeUrlCoupon, headers: headerWithToken(token!), body: body);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
print("Berhasil bayar kupon gratis: ${response.body}");
|
||||
return true;
|
||||
} else if (response.statusCode == 400) {
|
||||
print("Gagal bayar kupon gratis: ${response.body}");
|
||||
return false;
|
||||
} else {
|
||||
throw Exception('Gagal bayar kupon gratis');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ZeroPrice>> zeroPayment({
|
||||
required List<Map<String, String>> dataInvoice,
|
||||
required String totalPayment,
|
||||
}) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
var body = jsonEncode({
|
||||
"data_invoice": dataInvoice,
|
||||
"total_payment": totalPayment,
|
||||
});
|
||||
|
||||
http.Response response = await http.post(_zeroPay, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
|
||||
List<ZeroPrice> zeroPrice = [];
|
||||
if (response.statusCode == 201) {
|
||||
zeroPrice.add(ZeroPrice.fromJson(jsonDecode(response.body)));
|
||||
return zeroPrice;
|
||||
} else if (response.statusCode == 404) {
|
||||
return [];
|
||||
} else {
|
||||
throw Exception('Gagal Mendapatkan kursus');
|
||||
}
|
||||
}
|
||||
}
|
30
lib/services/profile_image_service.dart
Normal file
30
lib/services/profile_image_service.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/profile_image_post_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class ProfileImageService {
|
||||
Future<ProfileImagePostModel> addProfileImage({required File pckFile}) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
Uri url = Uri.parse('$baseUrl/users/profile/user-photo/$idUser');
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
var req = http.MultipartRequest('POST', url);
|
||||
req.headers.addAll(headerWithToken(token!));
|
||||
req.files.add(http.MultipartFile(
|
||||
'foto_profile', pckFile.readAsBytes().asStream(), pckFile.lengthSync(),
|
||||
filename: pckFile.path.split("/").last));
|
||||
|
||||
var streamed = await req.send();
|
||||
var response = await http.Response.fromStream(streamed);
|
||||
print('Ini file gambar nya ${pckFile.path.split("/").last}');
|
||||
print(response.body);
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return ProfileImagePostModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Mengganti Foto Profil');
|
||||
}
|
||||
}
|
||||
}
|
229
lib/services/qna_service.dart
Normal file
229
lib/services/qna_service.dart
Normal file
@ -0,0 +1,229 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/counter_qna_comment_model.dart';
|
||||
import 'package:initial_folder/models/counter_qna_like_model.dart';
|
||||
import 'package:initial_folder/models/qna_model.dart';
|
||||
|
||||
class QnaService {
|
||||
//get QNA user
|
||||
Future<QnaModel> getMyQna(String idCourse) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
};
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/$idCourse');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
// print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return QnaModel.fromJson(jsonDecode(response.body));
|
||||
} else if (response.statusCode == 404) {
|
||||
return QnaModel(status: 404, error: true, data: [[]]);
|
||||
} else {
|
||||
throw Exception('Data QNA, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
// Post QNA User
|
||||
Future<bool> postingQna(
|
||||
String title,
|
||||
String quest,
|
||||
String idCourse,
|
||||
String idLesson,
|
||||
) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna');
|
||||
var body = jsonEncode({
|
||||
"sender": idUser.toString(),
|
||||
"title": title,
|
||||
"quest": quest,
|
||||
"id_lesson": idLesson,
|
||||
"id_course": idCourse,
|
||||
});
|
||||
print(body);
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update QNA User
|
||||
Future<bool> updateQna(String idCourse, String quest, int id_qna, String title, String idLesson) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/$id_qna');
|
||||
var body = jsonEncode({
|
||||
// "sender": idUser.toString(),
|
||||
"sender": idUser,
|
||||
"quest": quest,
|
||||
"title": title,
|
||||
"id_lesson": idLesson,
|
||||
"id_course": idCourse,
|
||||
});
|
||||
print("ini Request Body update qna: $body");
|
||||
http.Response response =
|
||||
await http.put(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(response.body);
|
||||
print('berhasil update');
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Post Reply QNA User
|
||||
Future<bool> postQnaReply(String text_rep, String id_qna) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/reply');
|
||||
var body = jsonEncode({
|
||||
// "sender": idUser.toString(),
|
||||
"text_rep": text_rep,
|
||||
"id_qna": id_qna,
|
||||
});
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.statusCode);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Edit Reply QNA User
|
||||
Future<bool> editQnaReply(int id_rep, String text_rep, String id_qna) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/reply/$id_rep');
|
||||
var body = jsonEncode({
|
||||
// "sender": idUser.toString(),
|
||||
"text_rep": text_rep,
|
||||
"id_qna": id_qna,
|
||||
});
|
||||
http.Response response =
|
||||
await http.put(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Qna (Pertanyaan User)
|
||||
Future<bool> deleteQna(
|
||||
int id_qna,
|
||||
) async {
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/$id_qna');
|
||||
String? token = await UsersInfo().getToken();
|
||||
print(token);
|
||||
|
||||
http.Response response = await http.delete(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Reply Qna User
|
||||
Future<bool> deleteReplyQna(
|
||||
int id_rep,
|
||||
) async {
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/reply/$id_rep');
|
||||
String? token = await UsersInfo().getToken();
|
||||
print(token);
|
||||
|
||||
http.Response response = await http.delete(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//get counter comment qna
|
||||
Future<CounterCommentModel> getCounterComment(String idQna) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/count/$idQna');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return CounterCommentModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Counter Comment QNA, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
// Like or Unlike
|
||||
Future<bool> likeOrLike(int idQna) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/up/$idQna');
|
||||
// var body = jsonEncode({"user_id": idUser.toString()});
|
||||
// http.Response response =
|
||||
// await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!));
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else if (response.statusCode == 400) {
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/unup/$idQna');
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//get counter comment qna
|
||||
Future<CounterLikeModel> getCounterLike(String idQna) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/qna/like/$idQna');
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return CounterLikeModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Counter Like QNA, Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
78
lib/services/quiz_service.dart
Normal file
78
lib/services/quiz_service.dart
Normal file
@ -0,0 +1,78 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/quiz_model.dart';
|
||||
import 'package:initial_folder/models/quiz_perquestion_result_model.dart';
|
||||
import 'package:initial_folder/models/quiz_question_model.dart';
|
||||
import 'package:initial_folder/models/quiz_question_result_model.dart';
|
||||
|
||||
class quiz_service {
|
||||
Future get_quiz_info(String id) async {
|
||||
Uri url = Uri.parse('$baseUrl/users/quiz/question/$id');
|
||||
String? token = await UsersInfo().getToken();
|
||||
var response;
|
||||
if (token == null) {
|
||||
response = await http.get(url, headers: baseHeader);
|
||||
} else {
|
||||
response = await http.get(url, headers: headerWithToken(token));
|
||||
}
|
||||
log(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
final data = quizModelFromJson(response.body);
|
||||
return data;
|
||||
} else {
|
||||
throw Exception('Data Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future get_result_quiz(String resultArr) async {
|
||||
Uri url = Uri.parse('$baseUrl/users/quiz/question/check-answer');
|
||||
String? token = await UsersInfo().getToken();
|
||||
var response;
|
||||
// print(resultArr + "ini pas ngambil");
|
||||
if (token == null) {
|
||||
response = await http.get(url, headers: baseHeader);
|
||||
} else {
|
||||
print("disaodji" + resultArr);
|
||||
response = await http.post(url,
|
||||
headers: headerWithToken(token), body: resultArr);
|
||||
}
|
||||
if (response.statusCode == 200) {
|
||||
final data = quizQuestionResultFromJson(response.body);
|
||||
log(data.toString());
|
||||
return data;
|
||||
|
||||
// return jsonData;
|
||||
} else {
|
||||
print("errrorr---------" + response.statusCode);
|
||||
throw Exception('Data Detail jawaban Gagal Diambil');
|
||||
}
|
||||
}
|
||||
|
||||
Future get_result_quiz_pernumber(int quizId, int index) async {
|
||||
Uri url =
|
||||
Uri.parse('$baseUrl/users/quiz/question/${quizId}?slice=${index}');
|
||||
String? token = await UsersInfo().getToken();
|
||||
var response;
|
||||
// print(resultArr + "ini pas ngambil");
|
||||
if (token == null) {
|
||||
response = await http.get(url, headers: baseHeader);
|
||||
} else {
|
||||
// print("disaodji" + resultArr);
|
||||
response = await http.get(url, headers: headerWithToken(token));
|
||||
}
|
||||
if (response.statusCode == 200) {
|
||||
final data = quizPerQuestionResultFromJson(response.body);
|
||||
log(data.data.first.toString());
|
||||
return data;
|
||||
|
||||
// return jsonData;
|
||||
} else {
|
||||
print("errrorr---------" + response.statusCode);
|
||||
throw Exception('Data Detail jawaban Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
34
lib/services/reset_service.dart
Normal file
34
lib/services/reset_service.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/reset_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class ResetService {
|
||||
Future<ResetModel> kirimEmail({
|
||||
required String email,
|
||||
}) async {
|
||||
Uri url = Uri.parse('$baseUrl/auth/web/forgot-password');
|
||||
var body = jsonEncode({
|
||||
'email': email,
|
||||
});
|
||||
|
||||
print('Request URL: $url');
|
||||
print('Request Headers: $baseHeader');
|
||||
print('Request Body: $body');
|
||||
|
||||
var response = await http.post(url, headers: baseHeader, body: body);
|
||||
if (response.statusCode == 200) {
|
||||
print('Berhasil kirim link reset password ke email nih :');
|
||||
print(response.statusCode);
|
||||
return ResetModel.fromJson(jsonDecode(response.body)['data']);
|
||||
} else {
|
||||
print(response.statusCode);
|
||||
print(response.request);
|
||||
print(response.reasonPhrase);
|
||||
throw Exception('Gagal Kirim Email');
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
70
lib/services/search_service.dart
Normal file
70
lib/services/search_service.dart
Normal file
@ -0,0 +1,70 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:developer';
|
||||
|
||||
class SearchService {
|
||||
Future<List<CourseModel>> search(String? judul) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/filter?keyword=$judul');
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
log(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> course = [];
|
||||
for (var item in data) {
|
||||
course.add(CourseModel.fromJson(item));
|
||||
}
|
||||
|
||||
return course;
|
||||
} else {
|
||||
throw Exception('Gagal');
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> filter({
|
||||
String price = '',
|
||||
String level = '',
|
||||
String language = '',
|
||||
String rating = '',
|
||||
String keyword = '',
|
||||
}) async {
|
||||
Map<String, dynamic> queryParams = {
|
||||
if (keyword != '') 'keyword': keyword,
|
||||
if (price != '') 'price': price,
|
||||
if (level != '') 'level': level,
|
||||
if (language != '') 'language': language,
|
||||
if (rating != '') 'rating': rating,
|
||||
};
|
||||
print("Isi Query Form ---------> $queryParams");
|
||||
Uri url = Uri.parse('$baseUrl/homepage/course/search').replace(
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
if (queryParams.containsKey('keyword')) {
|
||||
url = Uri.parse('$baseUrl/homepage/course/search').replace(
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
} else if (price != '') {
|
||||
url = Uri.parse('$baseUrl/homepage/course/search').replace(
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
}
|
||||
|
||||
print("Url to API ----> $url");
|
||||
var response =
|
||||
await http.get(Uri.parse(Uri.decodeComponent(url.toString())));
|
||||
if (response.statusCode == 200) {
|
||||
print("berhasil fitlter search ${response.body}");
|
||||
var data = jsonDecode(response.body)['data'][0];
|
||||
List<CourseModel> courses = [];
|
||||
for (var item in data) {
|
||||
courses.add(CourseModel.fromJson(item));
|
||||
}
|
||||
return courses;
|
||||
} else {
|
||||
print("gagal fitlter search ${response.body}");
|
||||
throw Exception('Gagal');
|
||||
}
|
||||
}
|
||||
}
|
18
lib/services/section_lesson_service.dart
Normal file
18
lib/services/section_lesson_service.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/section_lesson_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class SectionLessonService {
|
||||
Future<SectionLessonModel> getSectionLessonCourse(String id) async {
|
||||
Uri url = Uri.parse('$baseUrl/homepage/section/$id');
|
||||
http.Response response = await http.get(url, headers: baseHeader);
|
||||
print(response.statusCode);
|
||||
if (response.statusCode == 200) {
|
||||
return SectionLessonModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Data Detail Kursus Gagal Diambil');
|
||||
}
|
||||
}
|
||||
}
|
195
lib/services/user_info_service.dart
Normal file
195
lib/services/user_info_service.dart
Normal file
@ -0,0 +1,195 @@
|
||||
import 'dart:convert';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/update_incomplete_profile_model.dart';
|
||||
import 'package:initial_folder/models/update_data_diri_model.dart';
|
||||
import 'package:initial_folder/models/user_info_incomplete_model.dart';
|
||||
import 'package:initial_folder/models/user_info_model.dart';
|
||||
import 'package:initial_folder/models/data_diri_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class UserInfoService {
|
||||
Future<UserInfoModel> getUserInfo(email) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/auth/me?email=$email');
|
||||
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
UserInfoModel userInfoModel = UserInfoModel.fromJson(data);
|
||||
await UsersInfo()
|
||||
.setIdUser(int.tryParse(userInfoModel.data[0].idUser ?? ''));
|
||||
return userInfoModel;
|
||||
} else if (response.statusCode == 202) {
|
||||
var data = jsonDecode(response.body);
|
||||
UserInfoModel userInfoModel = UserInfoModel.fromJson(data);
|
||||
await UsersInfo()
|
||||
.setIdUser(int.tryParse(userInfoModel.data[0].idUser ?? ''));
|
||||
return userInfoModel;
|
||||
} else {
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<DataDiriModel> getDataDiri() async {
|
||||
int? id = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/users-info/$id');
|
||||
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return DataDiriModel.fromJson(jsonDecode(response.body));
|
||||
} else if (response.statusCode == 202) {
|
||||
return DataDiriModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future getDataDiriADMIN() async {
|
||||
int? id = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/users-info/$id');
|
||||
|
||||
var response;
|
||||
|
||||
if (token != null) {
|
||||
response = await http.get(url, headers: headerWithToken(token));
|
||||
} else {
|
||||
response = await http.get(url);
|
||||
}
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
return response.statusCode;
|
||||
} else if (response.statusCode == 200) {
|
||||
return response.statusCode;
|
||||
} else {
|
||||
return response.statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
Future<UpdateDataDiriModel> updateDataDiri({
|
||||
String? fullname,
|
||||
String? biograph,
|
||||
String? phone,
|
||||
String? email,
|
||||
String? twitter,
|
||||
String? facebook,
|
||||
String? linkedin,
|
||||
String? instagram,
|
||||
String? datebirth,
|
||||
String? gender,
|
||||
String? headline,
|
||||
}) async {
|
||||
int? id = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/profile/user-profile/$id');
|
||||
|
||||
var body = jsonEncode({
|
||||
"full_name": fullname,
|
||||
"biography": biograph,
|
||||
"phone": phone,
|
||||
"email": email,
|
||||
// "datebirth": datebirth,
|
||||
// "jenis_kel": gender,
|
||||
"headline": headline,
|
||||
"social_link": {
|
||||
"twitter": twitter,
|
||||
"facebook": facebook,
|
||||
"linkedin": linkedin,
|
||||
"instagram": instagram
|
||||
}
|
||||
});
|
||||
var response =
|
||||
await http.put(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 200) {
|
||||
return UpdateDataDiriModel.fromJson(jsonDecode(response.body));
|
||||
} else if (response.statusCode == 403) {
|
||||
return UpdateDataDiriModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal update data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<UpdateIncompleteProfileModel> updateIncompleteProfile({
|
||||
String? fullname,
|
||||
String? phone,
|
||||
String? email,
|
||||
String? newPassword,
|
||||
String? newConfirmPassword,
|
||||
}) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/profile-completion');
|
||||
|
||||
var body = jsonEncode({
|
||||
"phone": phone,
|
||||
"password": newPassword,
|
||||
"confirm_password": newConfirmPassword,
|
||||
});
|
||||
var response =
|
||||
await http.put(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 200 ||
|
||||
response.statusCode == 400 ||
|
||||
response.statusCode == 404) {
|
||||
return UpdateIncompleteProfileModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception(
|
||||
'Gagal update data: update incomplete profile: ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<UserInfoIncompleteModel> getUserInfoIncomplete() async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/users-info');
|
||||
|
||||
var response = await http.get(url, headers: headerWithToken(token!));
|
||||
if (response.statusCode == 200) {
|
||||
UserInfoIncompleteModel userInfoIncompleteModel =
|
||||
UserInfoIncompleteModel.fromJson(jsonDecode(response.body));
|
||||
return userInfoIncompleteModel;
|
||||
} else if (response.statusCode == 202) {
|
||||
UserInfoIncompleteModel userInfoIncompleteModel =
|
||||
UserInfoIncompleteModel.fromJson(jsonDecode(response.body));
|
||||
|
||||
return userInfoIncompleteModel;
|
||||
} else {
|
||||
throw Exception('Gagal ambil data');
|
||||
}
|
||||
}
|
||||
|
||||
Future updatePassword(
|
||||
{required idUser,
|
||||
required String? email,
|
||||
required String? oldPassword,
|
||||
required String? password,
|
||||
required String? newPasswordConfirm}) async {
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/profile/user-credentials/$idUser');
|
||||
|
||||
var body = jsonEncode({
|
||||
'email': email,
|
||||
'old_password': oldPassword,
|
||||
"password": password,
|
||||
"new_password_confirm": newPasswordConfirm,
|
||||
});
|
||||
|
||||
var response =
|
||||
await http.put(url, headers: headerWithToken(token!), body: body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
var status = data['status'];
|
||||
if (status == 200) {
|
||||
return;
|
||||
} else {
|
||||
throw Exception('Gagal update password');
|
||||
}
|
||||
} else {
|
||||
throw Exception('Gagal update password');
|
||||
}
|
||||
}
|
||||
}
|
62
lib/services/voucher_service.dart
Normal file
62
lib/services/voucher_service.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:initial_folder/models/voucher_model.dart';
|
||||
|
||||
class VoucherService {
|
||||
Future<VoucherModel> radeemVoucher(int? idCourse, String voucher) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse(
|
||||
'$baseUrl/users/coupon-payment?voucher=$voucher&course_id=$idCourse');
|
||||
|
||||
http.Response response =
|
||||
await http.get(url, headers: headerWithToken(token!));
|
||||
print("Ini API nya ${url}");
|
||||
if (response.statusCode == 200) {
|
||||
print("Berhasil kupon ${response.body}");
|
||||
return VoucherModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
print("gagal kupon ${response.body}");
|
||||
throw Exception('Gagal redeem voucher');
|
||||
}
|
||||
}
|
||||
|
||||
Future<VoucherModel> redeemVoucherCart(
|
||||
List<String> idCourse, String voucher) async {
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$baseUrl/users/voucher-cart');
|
||||
var body = jsonEncode({
|
||||
// "user_id": idUser,
|
||||
"courses_id": idCourse,
|
||||
"voucher": voucher,
|
||||
});
|
||||
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
if (response.statusCode == 201) {
|
||||
print("radeem voucher cart ${response.body}");
|
||||
return VoucherModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
print("gagal radeem voucher cart ${response.body}");
|
||||
throw Exception('Gagal redeem voucher');
|
||||
}
|
||||
}
|
||||
|
||||
Future<VoucherModel> cancelCoupon(coupon) async {
|
||||
Uri url = Uri.parse('$baseUrl/users/cancel-redeem-voucher/$coupon');
|
||||
String? token = await UsersInfo().getToken();
|
||||
http.Response response =
|
||||
await http.delete(url, headers: headerWithToken(token!));
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
print("cancel coupon ${response.body}");
|
||||
return VoucherModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Cancel Coupon');
|
||||
}
|
||||
}
|
||||
}
|
66
lib/services/wishlist_service.dart
Normal file
66
lib/services/wishlist_service.dart
Normal file
@ -0,0 +1,66 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/wishlist_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class WishlistService {
|
||||
var _baseUrl = '$baseUrl/users/wishlist';
|
||||
Future<WishlistPostModel> addWishlist(
|
||||
int wishlistItem,
|
||||
) async {
|
||||
Uri url = Uri.parse(_baseUrl);
|
||||
String? token = await UsersInfo().getToken();
|
||||
int? idUser = await UsersInfo().getIdUser();
|
||||
|
||||
var body = jsonEncode({
|
||||
// 'id_user': idUser,
|
||||
'wishlist_item': wishlistItem,
|
||||
});
|
||||
http.Response response =
|
||||
await http.post(url, headers: headerWithToken(token!), body: body);
|
||||
print(response.body);
|
||||
if (response.statusCode == 201 || response.statusCode == 200) {
|
||||
return WishlistPostModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Menambahkan Wishlist');
|
||||
}
|
||||
}
|
||||
|
||||
Future<WishlistPostModel> deleteWishlist(
|
||||
int wishlistItem,
|
||||
) async {
|
||||
Uri url = Uri.parse('$_baseUrl/delete/$wishlistItem');
|
||||
String? token = await UsersInfo().getToken();
|
||||
print(token);
|
||||
|
||||
http.Response response = await http.delete(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return WishlistPostModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Menghapus Wishlist');
|
||||
}
|
||||
}
|
||||
|
||||
Future<WishlistModel> getWishlist() async {
|
||||
int? id = await UsersInfo().getIdUser();
|
||||
String? token = await UsersInfo().getToken();
|
||||
Uri url = Uri.parse('$_baseUrl?users=$id');
|
||||
|
||||
http.Response response = await http.get(
|
||||
url,
|
||||
headers: headerWithToken(token!),
|
||||
);
|
||||
print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
return WishlistModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Gagal Mendapatkan Wishlist');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user