feat: API 연동 개선 및 라이선스 모델 확장
- 라이선스 모델 전면 개편 (상세 필드 추가, 계산 필드 구현) - API 응답 처리 개선 (HTTP 상태 코드 기반) - 장비 출고 폼 컨트롤러 추가 - 회사 지점 정보 모델 추가 - 공통 데이터 모델 구조 추가 - 전체 서비스 레이어 API 호출 방식 통일 - UI 컴포넌트 마이너 개선
This commit is contained in:
@@ -29,12 +29,12 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
||||
data: request.toJson(),
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
final loginResponse = LoginResponse.fromJson(response.data);
|
||||
return Right(loginResponse);
|
||||
} else {
|
||||
return Left(ServerFailure(
|
||||
message: response.error?.message ?? '로그인 실패',
|
||||
message: response.statusMessage ?? '로그인 실패',
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -58,11 +58,11 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
||||
data: request.toJson(),
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
if (response.statusCode == 200) {
|
||||
return const Right(null);
|
||||
} else {
|
||||
return Left(ServerFailure(
|
||||
message: response.error?.message ?? '로그아웃 실패',
|
||||
message: response.statusMessage ?? '로그아웃 실패',
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -81,12 +81,12 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
||||
data: request.toJson(),
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
final tokenResponse = TokenResponse.fromJson(response.data);
|
||||
return Right(tokenResponse);
|
||||
} else {
|
||||
return Left(ServerFailure(
|
||||
message: response.error?.message ?? '토큰 갱신 실패',
|
||||
message: response.statusMessage ?? '토큰 갱신 실패',
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:superport/core/constants/api_endpoints.dart';
|
||||
import 'package:superport/core/errors/exceptions.dart';
|
||||
@@ -80,11 +79,11 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
final apiResponse = ApiResponse<PaginatedResponse<CompanyListDto>>.fromJson(
|
||||
response.data,
|
||||
(json) => PaginatedResponse<CompanyListDto>.fromJson(
|
||||
json,
|
||||
(item) => CompanyListDto.fromJson(item),
|
||||
json as Map<String, dynamic>,
|
||||
(item) => CompanyListDto.fromJson(item as Map<String, dynamic>),
|
||||
),
|
||||
);
|
||||
return apiResponse.data;
|
||||
return apiResponse.data!;
|
||||
} else {
|
||||
throw ApiException(
|
||||
message: 'Failed to load companies',
|
||||
@@ -108,9 +107,9 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
if (response.statusCode == 201) {
|
||||
final apiResponse = ApiResponse<CompanyResponse>.fromJson(
|
||||
response.data,
|
||||
(json) => CompanyResponse.fromJson(json),
|
||||
(json) => CompanyResponse.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return apiResponse.data;
|
||||
return apiResponse.data!;
|
||||
} else {
|
||||
throw ApiException(
|
||||
message: 'Failed to create company',
|
||||
@@ -134,7 +133,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to fetch company detail',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +149,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to fetch company with branches',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +166,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to update company',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -181,7 +180,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to delete company',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -198,7 +197,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to fetch company names',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +215,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to create branch',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -232,7 +231,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to fetch branch detail',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -249,7 +248,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to update branch',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +262,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to delete branch',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -280,7 +279,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
} on DioException catch (e) {
|
||||
throw ServerException(
|
||||
message: e.response?.data['message'] ?? 'Failed to fetch company branches',
|
||||
code: e.response?.statusCode,
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -297,7 +296,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
.map((item) => CompanyWithBranches.fromJson(item))
|
||||
.toList(),
|
||||
);
|
||||
return apiResponse.data;
|
||||
return apiResponse.data!;
|
||||
} else {
|
||||
throw ApiException(
|
||||
message: 'Failed to load companies with branches',
|
||||
@@ -321,9 +320,9 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
if (response.statusCode == 200) {
|
||||
final apiResponse = ApiResponse<Map<String, dynamic>>.fromJson(
|
||||
response.data,
|
||||
(json) => json,
|
||||
(json) => json as Map<String, dynamic>,
|
||||
);
|
||||
return apiResponse.data['exists'] ?? false;
|
||||
return apiResponse.data?['exists'] ?? false;
|
||||
} else {
|
||||
throw ApiException(
|
||||
message: 'Failed to check duplicate',
|
||||
@@ -351,7 +350,7 @@ class CompanyRemoteDataSourceImpl implements CompanyRemoteDataSource {
|
||||
.map((item) => CompanyListDto.fromJson(item))
|
||||
.toList(),
|
||||
);
|
||||
return apiResponse.data;
|
||||
return apiResponse.data!;
|
||||
} else {
|
||||
throw ApiException(
|
||||
message: 'Failed to search companies',
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:superport/core/constants/api_endpoints.dart';
|
||||
import 'package:superport/core/errors/exceptions.dart';
|
||||
import 'package:superport/core/errors/failures.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/data/models/dashboard/equipment_status_distribution.dart';
|
||||
@@ -32,12 +30,12 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
final stats = OverviewStats.fromJson(response.data);
|
||||
return Right(stats);
|
||||
} else {
|
||||
return Left(ServerFailure('응답 데이터가 없습니다'));
|
||||
return Left(ServerFailure(message: '응답 데이터가 없습니다'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure('통계 데이터를 가져오는 중 오류가 발생했습니다'));
|
||||
return Left(ServerFailure(message: '통계 데이터를 가져오는 중 오류가 발생했습니다'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +50,12 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
.toList();
|
||||
return Right(activities);
|
||||
} else {
|
||||
return Left(ServerFailure('응답 데이터가 올바르지 않습니다'));
|
||||
return Left(ServerFailure(message: '응답 데이터가 올바르지 않습니다'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure('최근 활동을 가져오는 중 오류가 발생했습니다'));
|
||||
return Left(ServerFailure(message: '최근 활동을 가져오는 중 오류가 발생했습니다'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,12 +68,12 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
final distribution = EquipmentStatusDistribution.fromJson(response.data);
|
||||
return Right(distribution);
|
||||
} else {
|
||||
return Left(ServerFailure('응답 데이터가 없습니다'));
|
||||
return Left(ServerFailure(message: '응답 데이터가 없습니다'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure('장비 상태 분포를 가져오는 중 오류가 발생했습니다'));
|
||||
return Left(ServerFailure(message: '장비 상태 분포를 가져오는 중 오류가 발생했습니다'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +91,12 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
.toList();
|
||||
return Right(licenses);
|
||||
} else {
|
||||
return Left(ServerFailure('응답 데이터가 올바르지 않습니다'));
|
||||
return Left(ServerFailure(message: '응답 데이터가 올바르지 않습니다'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure('만료 예정 라이선스를 가져오는 중 오류가 발생했습니다'));
|
||||
return Left(ServerFailure(message: '만료 예정 라이선스를 가져오는 중 오류가 발생했습니다'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,26 +105,26 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return NetworkFailure('네트워크 연결 시간이 초과되었습니다');
|
||||
return NetworkFailure(message: '네트워크 연결 시간이 초과되었습니다');
|
||||
case DioExceptionType.connectionError:
|
||||
return NetworkFailure('서버에 연결할 수 없습니다');
|
||||
return NetworkFailure(message: '서버에 연결할 수 없습니다');
|
||||
case DioExceptionType.badResponse:
|
||||
final statusCode = error.response?.statusCode ?? 0;
|
||||
final message = error.response?.data?['message'] ?? '서버 오류가 발생했습니다';
|
||||
|
||||
if (statusCode == 401) {
|
||||
return AuthFailure('인증이 만료되었습니다');
|
||||
return AuthenticationFailure(message: '인증이 만료되었습니다');
|
||||
} else if (statusCode == 403) {
|
||||
return AuthFailure('접근 권한이 없습니다');
|
||||
return AuthenticationFailure(message: '접근 권한이 없습니다');
|
||||
} else if (statusCode >= 400 && statusCode < 500) {
|
||||
return ServerFailure(message);
|
||||
return ServerFailure(message: message);
|
||||
} else {
|
||||
return ServerFailure('서버 오류가 발생했습니다 ($statusCode)');
|
||||
return ServerFailure(message: '서버 오류가 발생했습니다 ($statusCode)');
|
||||
}
|
||||
case DioExceptionType.cancel:
|
||||
return ServerFailure('요청이 취소되었습니다');
|
||||
return ServerFailure(message: '요청이 취소되었습니다');
|
||||
default:
|
||||
return ServerFailure('알 수 없는 오류가 발생했습니다');
|
||||
return ServerFailure(message: '알 수 없는 오류가 발생했습니다');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:superport/core/errors/exceptions.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/data/models/license/license_dto.dart';
|
||||
import 'package:superport/data/models/license/license_request_dto.dart';
|
||||
import 'package:superport/data/models/license/license_query_dto.dart';
|
||||
|
||||
abstract class LicenseRemoteDataSource {
|
||||
Future<LicenseListResponseDto> getLicenses({
|
||||
|
||||
20
lib/data/models/common/api_response.dart
Normal file
20
lib/data/models/common/api_response.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'api_response.freezed.dart';
|
||||
part 'api_response.g.dart';
|
||||
|
||||
@Freezed(genericArgumentFactories: true)
|
||||
class ApiResponse<T> with _$ApiResponse<T> {
|
||||
const factory ApiResponse({
|
||||
required bool success,
|
||||
required String message,
|
||||
T? data,
|
||||
String? error,
|
||||
}) = _ApiResponse<T>;
|
||||
|
||||
factory ApiResponse.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object?) fromJsonT,
|
||||
) =>
|
||||
_$ApiResponseFromJson<T>(json, fromJsonT);
|
||||
}
|
||||
221
lib/data/models/common/api_response.freezed.dart
Normal file
221
lib/data/models/common/api_response.freezed.dart
Normal file
@@ -0,0 +1,221 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'api_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
ApiResponse<T> _$ApiResponseFromJson<T>(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) {
|
||||
return _ApiResponse<T>.fromJson(json, fromJsonT);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ApiResponse<T> {
|
||||
bool get success => throw _privateConstructorUsedError;
|
||||
String get message => throw _privateConstructorUsedError;
|
||||
T? get data => throw _privateConstructorUsedError;
|
||||
String? get error => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ApiResponse to a JSON map.
|
||||
Map<String, dynamic> toJson(Object? Function(T) toJsonT) =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ApiResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ApiResponseCopyWith<T, ApiResponse<T>> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ApiResponseCopyWith<T, $Res> {
|
||||
factory $ApiResponseCopyWith(
|
||||
ApiResponse<T> value, $Res Function(ApiResponse<T>) then) =
|
||||
_$ApiResponseCopyWithImpl<T, $Res, ApiResponse<T>>;
|
||||
@useResult
|
||||
$Res call({bool success, String message, T? data, String? error});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ApiResponseCopyWithImpl<T, $Res, $Val extends ApiResponse<T>>
|
||||
implements $ApiResponseCopyWith<T, $Res> {
|
||||
_$ApiResponseCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ApiResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? success = null,
|
||||
Object? message = null,
|
||||
Object? data = freezed,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
success: null == success
|
||||
? _value.success
|
||||
: success // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as T?,
|
||||
error: freezed == error
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ApiResponseImplCopyWith<T, $Res>
|
||||
implements $ApiResponseCopyWith<T, $Res> {
|
||||
factory _$$ApiResponseImplCopyWith(_$ApiResponseImpl<T> value,
|
||||
$Res Function(_$ApiResponseImpl<T>) then) =
|
||||
__$$ApiResponseImplCopyWithImpl<T, $Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({bool success, String message, T? data, String? error});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ApiResponseImplCopyWithImpl<T, $Res>
|
||||
extends _$ApiResponseCopyWithImpl<T, $Res, _$ApiResponseImpl<T>>
|
||||
implements _$$ApiResponseImplCopyWith<T, $Res> {
|
||||
__$$ApiResponseImplCopyWithImpl(
|
||||
_$ApiResponseImpl<T> _value, $Res Function(_$ApiResponseImpl<T>) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of ApiResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? success = null,
|
||||
Object? message = null,
|
||||
Object? data = freezed,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(_$ApiResponseImpl<T>(
|
||||
success: null == success
|
||||
? _value.success
|
||||
: success // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
message: null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as T?,
|
||||
error: freezed == error
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable(genericArgumentFactories: true)
|
||||
class _$ApiResponseImpl<T> implements _ApiResponse<T> {
|
||||
const _$ApiResponseImpl(
|
||||
{required this.success, required this.message, this.data, this.error});
|
||||
|
||||
factory _$ApiResponseImpl.fromJson(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) =>
|
||||
_$$ApiResponseImplFromJson(json, fromJsonT);
|
||||
|
||||
@override
|
||||
final bool success;
|
||||
@override
|
||||
final String message;
|
||||
@override
|
||||
final T? data;
|
||||
@override
|
||||
final String? error;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ApiResponse<$T>(success: $success, message: $message, data: $data, error: $error)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ApiResponseImpl<T> &&
|
||||
(identical(other.success, success) || other.success == success) &&
|
||||
(identical(other.message, message) || other.message == message) &&
|
||||
const DeepCollectionEquality().equals(other.data, data) &&
|
||||
(identical(other.error, error) || other.error == error));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, success, message,
|
||||
const DeepCollectionEquality().hash(data), error);
|
||||
|
||||
/// Create a copy of ApiResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ApiResponseImplCopyWith<T, _$ApiResponseImpl<T>> get copyWith =>
|
||||
__$$ApiResponseImplCopyWithImpl<T, _$ApiResponseImpl<T>>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson(Object? Function(T) toJsonT) {
|
||||
return _$$ApiResponseImplToJson<T>(this, toJsonT);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ApiResponse<T> implements ApiResponse<T> {
|
||||
const factory _ApiResponse(
|
||||
{required final bool success,
|
||||
required final String message,
|
||||
final T? data,
|
||||
final String? error}) = _$ApiResponseImpl<T>;
|
||||
|
||||
factory _ApiResponse.fromJson(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) =
|
||||
_$ApiResponseImpl<T>.fromJson;
|
||||
|
||||
@override
|
||||
bool get success;
|
||||
@override
|
||||
String get message;
|
||||
@override
|
||||
T? get data;
|
||||
@override
|
||||
String? get error;
|
||||
|
||||
/// Create a copy of ApiResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ApiResponseImplCopyWith<T, _$ApiResponseImpl<T>> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
41
lib/data/models/common/api_response.g.dart
Normal file
41
lib/data/models/common/api_response.g.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'api_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$ApiResponseImpl<T> _$$ApiResponseImplFromJson<T>(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object? json) fromJsonT,
|
||||
) =>
|
||||
_$ApiResponseImpl<T>(
|
||||
success: json['success'] as bool,
|
||||
message: json['message'] as String,
|
||||
data: _$nullableGenericFromJson(json['data'], fromJsonT),
|
||||
error: json['error'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ApiResponseImplToJson<T>(
|
||||
_$ApiResponseImpl<T> instance,
|
||||
Object? Function(T value) toJsonT,
|
||||
) =>
|
||||
<String, dynamic>{
|
||||
'success': instance.success,
|
||||
'message': instance.message,
|
||||
'data': _$nullableGenericToJson(instance.data, toJsonT),
|
||||
'error': instance.error,
|
||||
};
|
||||
|
||||
T? _$nullableGenericFromJson<T>(
|
||||
Object? input,
|
||||
T Function(Object? json) fromJson,
|
||||
) =>
|
||||
input == null ? null : fromJson(input);
|
||||
|
||||
Object? _$nullableGenericToJson<T>(
|
||||
T? input,
|
||||
Object? Function(T value) toJson,
|
||||
) =>
|
||||
input == null ? null : toJson(input);
|
||||
23
lib/data/models/common/paginated_response.dart
Normal file
23
lib/data/models/common/paginated_response.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'paginated_response.freezed.dart';
|
||||
part 'paginated_response.g.dart';
|
||||
|
||||
@Freezed(genericArgumentFactories: true)
|
||||
class PaginatedResponse<T> with _$PaginatedResponse<T> {
|
||||
const factory PaginatedResponse({
|
||||
required List<T> items,
|
||||
required int page,
|
||||
required int size,
|
||||
required int totalElements,
|
||||
required int totalPages,
|
||||
required bool first,
|
||||
required bool last,
|
||||
}) = _PaginatedResponse<T>;
|
||||
|
||||
factory PaginatedResponse.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object?) fromJsonT,
|
||||
) =>
|
||||
_$PaginatedResponseFromJson<T>(json, fromJsonT);
|
||||
}
|
||||
310
lib/data/models/common/paginated_response.freezed.dart
Normal file
310
lib/data/models/common/paginated_response.freezed.dart
Normal file
@@ -0,0 +1,310 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'paginated_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
PaginatedResponse<T> _$PaginatedResponseFromJson<T>(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) {
|
||||
return _PaginatedResponse<T>.fromJson(json, fromJsonT);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaginatedResponse<T> {
|
||||
List<T> get items => throw _privateConstructorUsedError;
|
||||
int get page => throw _privateConstructorUsedError;
|
||||
int get size => throw _privateConstructorUsedError;
|
||||
int get totalElements => throw _privateConstructorUsedError;
|
||||
int get totalPages => throw _privateConstructorUsedError;
|
||||
bool get first => throw _privateConstructorUsedError;
|
||||
bool get last => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this PaginatedResponse to a JSON map.
|
||||
Map<String, dynamic> toJson(Object? Function(T) toJsonT) =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaginatedResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaginatedResponseCopyWith<T, PaginatedResponse<T>> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaginatedResponseCopyWith<T, $Res> {
|
||||
factory $PaginatedResponseCopyWith(PaginatedResponse<T> value,
|
||||
$Res Function(PaginatedResponse<T>) then) =
|
||||
_$PaginatedResponseCopyWithImpl<T, $Res, PaginatedResponse<T>>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{List<T> items,
|
||||
int page,
|
||||
int size,
|
||||
int totalElements,
|
||||
int totalPages,
|
||||
bool first,
|
||||
bool last});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaginatedResponseCopyWithImpl<T, $Res,
|
||||
$Val extends PaginatedResponse<T>>
|
||||
implements $PaginatedResponseCopyWith<T, $Res> {
|
||||
_$PaginatedResponseCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaginatedResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? items = null,
|
||||
Object? page = null,
|
||||
Object? size = null,
|
||||
Object? totalElements = null,
|
||||
Object? totalPages = null,
|
||||
Object? first = null,
|
||||
Object? last = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
items: null == items
|
||||
? _value.items
|
||||
: items // ignore: cast_nullable_to_non_nullable
|
||||
as List<T>,
|
||||
page: null == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
size: null == size
|
||||
? _value.size
|
||||
: size // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
totalElements: null == totalElements
|
||||
? _value.totalElements
|
||||
: totalElements // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
totalPages: null == totalPages
|
||||
? _value.totalPages
|
||||
: totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
first: null == first
|
||||
? _value.first
|
||||
: first // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
last: null == last
|
||||
? _value.last
|
||||
: last // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaginatedResponseImplCopyWith<T, $Res>
|
||||
implements $PaginatedResponseCopyWith<T, $Res> {
|
||||
factory _$$PaginatedResponseImplCopyWith(_$PaginatedResponseImpl<T> value,
|
||||
$Res Function(_$PaginatedResponseImpl<T>) then) =
|
||||
__$$PaginatedResponseImplCopyWithImpl<T, $Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{List<T> items,
|
||||
int page,
|
||||
int size,
|
||||
int totalElements,
|
||||
int totalPages,
|
||||
bool first,
|
||||
bool last});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaginatedResponseImplCopyWithImpl<T, $Res>
|
||||
extends _$PaginatedResponseCopyWithImpl<T, $Res, _$PaginatedResponseImpl<T>>
|
||||
implements _$$PaginatedResponseImplCopyWith<T, $Res> {
|
||||
__$$PaginatedResponseImplCopyWithImpl(_$PaginatedResponseImpl<T> _value,
|
||||
$Res Function(_$PaginatedResponseImpl<T>) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of PaginatedResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? items = null,
|
||||
Object? page = null,
|
||||
Object? size = null,
|
||||
Object? totalElements = null,
|
||||
Object? totalPages = null,
|
||||
Object? first = null,
|
||||
Object? last = null,
|
||||
}) {
|
||||
return _then(_$PaginatedResponseImpl<T>(
|
||||
items: null == items
|
||||
? _value._items
|
||||
: items // ignore: cast_nullable_to_non_nullable
|
||||
as List<T>,
|
||||
page: null == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
size: null == size
|
||||
? _value.size
|
||||
: size // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
totalElements: null == totalElements
|
||||
? _value.totalElements
|
||||
: totalElements // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
totalPages: null == totalPages
|
||||
? _value.totalPages
|
||||
: totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
first: null == first
|
||||
? _value.first
|
||||
: first // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
last: null == last
|
||||
? _value.last
|
||||
: last // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable(genericArgumentFactories: true)
|
||||
class _$PaginatedResponseImpl<T> implements _PaginatedResponse<T> {
|
||||
const _$PaginatedResponseImpl(
|
||||
{required final List<T> items,
|
||||
required this.page,
|
||||
required this.size,
|
||||
required this.totalElements,
|
||||
required this.totalPages,
|
||||
required this.first,
|
||||
required this.last})
|
||||
: _items = items;
|
||||
|
||||
factory _$PaginatedResponseImpl.fromJson(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) =>
|
||||
_$$PaginatedResponseImplFromJson(json, fromJsonT);
|
||||
|
||||
final List<T> _items;
|
||||
@override
|
||||
List<T> get items {
|
||||
if (_items is EqualUnmodifiableListView) return _items;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_items);
|
||||
}
|
||||
|
||||
@override
|
||||
final int page;
|
||||
@override
|
||||
final int size;
|
||||
@override
|
||||
final int totalElements;
|
||||
@override
|
||||
final int totalPages;
|
||||
@override
|
||||
final bool first;
|
||||
@override
|
||||
final bool last;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaginatedResponse<$T>(items: $items, page: $page, size: $size, totalElements: $totalElements, totalPages: $totalPages, first: $first, last: $last)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaginatedResponseImpl<T> &&
|
||||
const DeepCollectionEquality().equals(other._items, _items) &&
|
||||
(identical(other.page, page) || other.page == page) &&
|
||||
(identical(other.size, size) || other.size == size) &&
|
||||
(identical(other.totalElements, totalElements) ||
|
||||
other.totalElements == totalElements) &&
|
||||
(identical(other.totalPages, totalPages) ||
|
||||
other.totalPages == totalPages) &&
|
||||
(identical(other.first, first) || other.first == first) &&
|
||||
(identical(other.last, last) || other.last == last));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_items),
|
||||
page,
|
||||
size,
|
||||
totalElements,
|
||||
totalPages,
|
||||
first,
|
||||
last);
|
||||
|
||||
/// Create a copy of PaginatedResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaginatedResponseImplCopyWith<T, _$PaginatedResponseImpl<T>>
|
||||
get copyWith =>
|
||||
__$$PaginatedResponseImplCopyWithImpl<T, _$PaginatedResponseImpl<T>>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson(Object? Function(T) toJsonT) {
|
||||
return _$$PaginatedResponseImplToJson<T>(this, toJsonT);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _PaginatedResponse<T> implements PaginatedResponse<T> {
|
||||
const factory _PaginatedResponse(
|
||||
{required final List<T> items,
|
||||
required final int page,
|
||||
required final int size,
|
||||
required final int totalElements,
|
||||
required final int totalPages,
|
||||
required final bool first,
|
||||
required final bool last}) = _$PaginatedResponseImpl<T>;
|
||||
|
||||
factory _PaginatedResponse.fromJson(
|
||||
Map<String, dynamic> json, T Function(Object?) fromJsonT) =
|
||||
_$PaginatedResponseImpl<T>.fromJson;
|
||||
|
||||
@override
|
||||
List<T> get items;
|
||||
@override
|
||||
int get page;
|
||||
@override
|
||||
int get size;
|
||||
@override
|
||||
int get totalElements;
|
||||
@override
|
||||
int get totalPages;
|
||||
@override
|
||||
bool get first;
|
||||
@override
|
||||
bool get last;
|
||||
|
||||
/// Create a copy of PaginatedResponse
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaginatedResponseImplCopyWith<T, _$PaginatedResponseImpl<T>>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
35
lib/data/models/common/paginated_response.g.dart
Normal file
35
lib/data/models/common/paginated_response.g.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'paginated_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$PaginatedResponseImpl<T> _$$PaginatedResponseImplFromJson<T>(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object? json) fromJsonT,
|
||||
) =>
|
||||
_$PaginatedResponseImpl<T>(
|
||||
items: (json['items'] as List<dynamic>).map(fromJsonT).toList(),
|
||||
page: (json['page'] as num).toInt(),
|
||||
size: (json['size'] as num).toInt(),
|
||||
totalElements: (json['totalElements'] as num).toInt(),
|
||||
totalPages: (json['totalPages'] as num).toInt(),
|
||||
first: json['first'] as bool,
|
||||
last: json['last'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PaginatedResponseImplToJson<T>(
|
||||
_$PaginatedResponseImpl<T> instance,
|
||||
Object? Function(T value) toJsonT,
|
||||
) =>
|
||||
<String, dynamic>{
|
||||
'items': instance.items.map(toJsonT).toList(),
|
||||
'page': instance.page,
|
||||
'size': instance.size,
|
||||
'totalElements': instance.totalElements,
|
||||
'totalPages': instance.totalPages,
|
||||
'first': instance.first,
|
||||
'last': instance.last,
|
||||
};
|
||||
Reference in New Issue
Block a user