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,29 @@
import 'package:dio/dio.dart';
import 'package:frontend_eccp_mobile/app/core/constants/dio_constant.dart';
import 'package:frontend_eccp_mobile/app/core/network/api_endpoint.dart';
import 'package:frontend_eccp_mobile/app/core/network/dio_client.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_request.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_response.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class LoginRemoteDataSource {
final Dio _dio = DioClient.getInstance();
Future<LoginResponse> login(LoginRequest request) async {
final response = await _dio.post<Map<String, dynamic>>(
ApiEndpoint.login,
data: request.toJson(),
options: Options(
extra: {DioExtraKey.noAuth: true},
),
);
final data = response.data;
if (data == null) {
throw Exception('EMPTY_RESPONSE');
}
return LoginResponse.fromJson(data);
}
}

View File

@@ -0,0 +1,29 @@
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_user.dart';
class LoginData {
LoginData({
required this.accessToken,
required this.refreshToken,
required this.tokenType,
required this.expiresIn,
required this.user,
});
factory LoginData.fromJson(Map<String, dynamic> json) {
return LoginData(
accessToken: json['access_token']?.toString() ?? '',
refreshToken: json['refresh_token']?.toString() ?? '',
tokenType: json['token_type']?.toString() ?? '',
expiresIn: int.tryParse(json['expires_in']?.toString() ?? '0') ?? 0,
user: LoginUser.fromJson(
json['user'] as Map<String, dynamic>? ?? {},
),
);
}
final String accessToken;
final String refreshToken;
final String tokenType;
final int expiresIn;
final LoginUser user;
}

View File

@@ -0,0 +1,16 @@
class LoginRequest {
LoginRequest({
required this.nrp,
required this.password,
});
final String nrp;
final String password;
Map<String, dynamic> toJson() {
return {
'nrp': nrp,
'password': password,
};
}
}

View File

@@ -0,0 +1,23 @@
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_data.dart';
class LoginResponse {
LoginResponse({
required this.status,
required this.message,
required this.data,
});
factory LoginResponse.fromJson(Map<String, dynamic> json) {
return LoginResponse(
status: json['status']?.toString() ?? '',
message: json['message']?.toString() ?? '',
data: LoginData.fromJson(
json['data'] as Map<String, dynamic>? ?? {},
),
);
}
final String status;
final String message;
final LoginData data;
}

View File

@@ -0,0 +1,16 @@
class LoginUser {
LoginUser({
required this.name,
required this.nrp,
});
factory LoginUser.fromJson(Map<String, dynamic> json) {
return LoginUser(
name: json['name']?.toString() ?? '',
nrp: json['nrp']?.toString() ?? '',
);
}
final String name;
final String nrp;
}

View File

@@ -0,0 +1,14 @@
class UserSession {
String? token;
Map<String, dynamic>? user;
bool get isLoggedIn => token != null && token!.isNotEmpty;
String get name => user?['name']?.toString() ?? '';
String get nrp => user?['nrp']?.toString() ?? '';
void clear() {
token = null;
user = null;
}
}

View File

@@ -0,0 +1,15 @@
import 'package:frontend_eccp_mobile/modules/auth/login/data/datasources/login_remote_datasource.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_request.dart';
import 'package:frontend_eccp_mobile/modules/auth/login/data/model/login_response.dart';
import 'package:injectable/injectable.dart';
@lazySingleton
class LoginRepository {
LoginRepository(this._remoteDatasource);
final LoginRemoteDataSource _remoteDatasource;
Future<LoginResponse> login(LoginRequest request) async {
return _remoteDatasource.login(request);
}
}