first commit

This commit is contained in:
2026-04-29 12:53:22 +07:00
commit e6a30eddd3
394 changed files with 16408 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import 'package:dio/dio.dart';
import 'package:frontend_eccp_mobile/app/core/config/app_environment.dart';
import 'package:frontend_eccp_mobile/app/core/network/api_endpoint.dart';
import 'package:frontend_eccp_mobile/app/core/utils/session_manager.dart';
import 'package:frontend_eccp_mobile/modules/auth/refresh_token/data/model/refresh_token_response.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class AuthRemoteDataSource {
final Dio _dio = Dio(
BaseOptions(
baseUrl: AppEnvironment.baseUrl,
),
);
Future<RefreshTokenResponse> refreshToken() async {
final token = await SessionManager.getRefreshToken();
final response = await _dio.post<Map<String, dynamic>>(
ApiEndpoint.refreshToken,
data: {'refresh_token': token},
);
final data = response.data;
if (data == null) {
throw Exception('EMPTY_RESPONSE');
}
return RefreshTokenResponse.fromJson(data);
}
}

View File

@@ -0,0 +1,30 @@
class RefreshTokenResponse {
RefreshTokenResponse({
required this.status,
required this.message,
required this.accessToken,
required this.refreshToken,
required this.tokenType,
required this.expiresIn,
});
factory RefreshTokenResponse.fromJson(Map<String, dynamic> json) {
final data = json['data'] as Map<String, dynamic>? ?? {};
return RefreshTokenResponse(
status: json['status']?.toString() ?? '',
message: json['message']?.toString() ?? '',
accessToken: data['access_token']?.toString() ?? '',
refreshToken: data['refresh_token']?.toString() ?? '',
tokenType: data['token_type']?.toString() ?? '',
expiresIn: int.tryParse(data['expires_in']?.toString() ?? '0') ?? 0,
);
}
final String status;
final String message;
final String accessToken;
final String refreshToken;
final String tokenType;
final int expiresIn;
}

View File

@@ -0,0 +1,20 @@
import 'package:frontend_eccp_mobile/modules/auth/refresh_token/data/datasources/auth_remote_datasource.dart';
import 'package:frontend_eccp_mobile/modules/auth/refresh_token/data/model/refresh_token_response.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class AuthRepository {
AuthRepository(this._remoteDatasource);
final AuthRemoteDataSource _remoteDatasource;
Future<RefreshTokenResponse> refreshToken() async {
final response = await _remoteDatasource.refreshToken();
if (response.status != 'success') {
throw Exception(response.message);
}
return response;
}
}

View File

@@ -0,0 +1,14 @@
import 'package:frontend_eccp_mobile/modules/auth/refresh_token/data/model/refresh_token_response.dart';
import 'package:frontend_eccp_mobile/modules/auth/refresh_token/data/repositories/auth_repository.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class AuthService {
AuthService(this._repository);
final AuthRepository _repository;
Future<RefreshTokenResponse> refreshToken() async {
return _repository.refreshToken();
}
}