마스터 고객/제품/창고 테스트 및 UI 구현
This commit is contained in:
70
lib/features/masters/uom/data/dtos/uom_dto.dart
Normal file
70
lib/features/masters/uom/data/dtos/uom_dto.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/uom.dart';
|
||||
|
||||
class UomDto {
|
||||
UomDto({
|
||||
this.id,
|
||||
required this.uomName,
|
||||
this.isDefault = false,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String uomName;
|
||||
final bool isDefault;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory UomDto.fromJson(Map<String, dynamic> json) {
|
||||
return UomDto(
|
||||
id: json['id'] as int?,
|
||||
uomName: json['uom_name'] as String,
|
||||
isDefault: (json['is_default'] as bool?) ?? false,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
Uom toEntity() => Uom(
|
||||
id: id,
|
||||
uomName: uomName,
|
||||
isDefault: isDefault,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Uom> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(UomDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Uom>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/uom.dart';
|
||||
import '../../domain/repositories/uom_repository.dart';
|
||||
import '../dtos/uom_dto.dart';
|
||||
|
||||
class UomRepositoryRemote implements UomRepository {
|
||||
UomRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/uoms';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<Uom>> list({
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return UomDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
}
|
||||
43
lib/features/masters/uom/domain/entities/uom.dart
Normal file
43
lib/features/masters/uom/domain/entities/uom.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
class Uom {
|
||||
Uom({
|
||||
this.id,
|
||||
required this.uomName,
|
||||
this.isDefault = false,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String uomName;
|
||||
final bool isDefault;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Uom copyWith({
|
||||
int? id,
|
||||
String? uomName,
|
||||
bool? isDefault,
|
||||
bool? isActive,
|
||||
bool? isDeleted,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Uom(
|
||||
id: id ?? this.id,
|
||||
uomName: uomName ?? this.uomName,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/uom.dart';
|
||||
|
||||
/// 단위(UOM) 조회 리포지토리
|
||||
abstract class UomRepository {
|
||||
Future<PaginatedResult<Uom>> list({
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user