128 lines
4.5 KiB
Dart
128 lines
4.5 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// Holds API endpoints with a runtime-overridable base URL to simplify debugging.
|
|
class ApiConstant {
|
|
// static const domain = 'https://gibbon-direct-neatly.ngrok-free.app';
|
|
static const domain = 'http://presensiku.site';
|
|
// static const domain = 'http://192.168.1.6:8000';
|
|
static const _defaultBaseURL = '$domain/api';
|
|
static const _prefsKeyBaseUrl = 'api_base_url_override';
|
|
|
|
|
|
static String? _runtimeBaseURL;
|
|
|
|
/// Current base URL. Falls back to [_defaultBaseURL] if no override is set.
|
|
// debug mode
|
|
// static String get baseURL =>
|
|
// (_runtimeBaseURL != null && _runtimeBaseURL!.trim().isNotEmpty)
|
|
// ? _runtimeBaseURL!
|
|
// : _defaultBaseURL;
|
|
|
|
// prod mode
|
|
static String get baseURL => _defaultBaseURL;
|
|
|
|
/// Load persisted override from SharedPreferences. Call once on app startup.
|
|
// static Future<void> loadBaseUrl() async {
|
|
// final prefs = await SharedPreferences.getInstance();
|
|
// _runtimeBaseURL = prefs.getString(_prefsKeyBaseUrl);
|
|
// }
|
|
|
|
/// Set (or clear) a runtime base URL override and persist it for future runs.
|
|
static Future<void> setBaseUrlOverride(String? value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final normalized = value?.trim();
|
|
|
|
if (normalized == null || normalized.isEmpty) {
|
|
_runtimeBaseURL = null;
|
|
await prefs.remove(_prefsKeyBaseUrl);
|
|
return;
|
|
}
|
|
|
|
_runtimeBaseURL = normalized;
|
|
await prefs.setString(_prefsKeyBaseUrl, normalized);
|
|
}
|
|
|
|
static String get testConnection => '$baseURL/ping';
|
|
|
|
/// general
|
|
|
|
// login
|
|
static String get loginURL => '$baseURL/login';
|
|
// register
|
|
static String get registerURL => '$baseURL/register';
|
|
// store fcm token
|
|
static String get storeFcmTokenURL => '$baseURL/store-fcm';
|
|
// get all class
|
|
static String get allClass => '$baseURL/classes';
|
|
// link url for permission
|
|
// http://192.168.1.4:8000/storage/permission/evidence/1_mudy-brembo_1772988841.jpg
|
|
static String get permissionEvidenceURL =>
|
|
'$domain/storage/permission/evidence';
|
|
// link url for profile picture
|
|
static String getProfilePictureURL(String filename, String role) {
|
|
return '$domain/storage/profile_pictures/$role/$filename';
|
|
}
|
|
|
|
/// student features
|
|
|
|
/// dashboard
|
|
// attendance qrcode
|
|
static String get qrcodeAttendance => '$baseURL/qrattendance';
|
|
// attendance user
|
|
static String get attendanceReport => '$baseURL/attendance/report';
|
|
static String get attendanceReportClass => '$baseURL/attendance/report/class';
|
|
|
|
// permission
|
|
static String get studentPermission => '$baseURL/attendance/permission';
|
|
static String get studentPermissionReport =>
|
|
'$baseURL/attendance/permission/report';
|
|
|
|
/// teacher features
|
|
|
|
// schedule
|
|
static String get teacherSchedulePersonal => '$baseURL/teacher/schedules/day';
|
|
static String get teacherScheduleWeeklyPersonal =>
|
|
'$baseURL/teacher/schedules';
|
|
static String get teacherScheduleClass => '$baseURL/schedules';
|
|
static String get detailInformationClass =>
|
|
'$baseURL/info/class'; // class id as query parameter
|
|
static String get reportStudentAttendanceByClass =>
|
|
'$baseURL/teacher/attendance/class'; // class id as query parameter, date include in payload
|
|
static String get reportStudentAttendanceDailyByClass =>
|
|
'$baseURL/teacher/attendance/daily/class/'; // class id as query parameter, date include in payload
|
|
|
|
// anouncement feature
|
|
static String get sendAnnouncement => '$baseURL/fcm/send-announcement';
|
|
|
|
// teacher activity
|
|
static String get teacherActivity => '$baseURL/teacher/activity';
|
|
|
|
// permission feature
|
|
static String get permissionReportByClass =>
|
|
'$baseURL/teacher/attendance/permission/report'; // class id as query parameter, date include in payload
|
|
static String get permissionAccept =>
|
|
'$baseURL/teacher/attendance/permission/accept'; // permission id include in payload
|
|
static String get permissionReject =>
|
|
'$baseURL/teacher/attendance/permission/reject'; // permission id include in payload
|
|
|
|
// disrepancy report feature
|
|
static String get discrepancyReport =>
|
|
'$baseURL/teacher/attendance/disrepancy/report';
|
|
|
|
|
|
// link URL Schedule QR Feature
|
|
static String get scheduleQrURL => '$baseURL/teacher/attendance/qr/generate';
|
|
|
|
/// notes example for login
|
|
// {
|
|
// "email": "mudy@example.com",
|
|
// "password": "password123"
|
|
// }
|
|
|
|
/// exapmple for login teacher
|
|
/// {
|
|
/// "email": "alvian@guru.com"
|
|
/// "password": "alvianguru123"
|
|
/// }
|
|
}
|