마스터 고객/제품/창고 테스트 및 UI 구현
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/vendor.dart';
|
||||
|
||||
/// 벤더 DTO (JSON 직렬화/역직렬화)
|
||||
@@ -49,26 +51,40 @@ class VendorDto {
|
||||
}
|
||||
|
||||
Vendor toEntity() => Vendor(
|
||||
id: id,
|
||||
vendorCode: vendorCode,
|
||||
vendorName: vendorName,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
id: id,
|
||||
vendorCode: vendorCode,
|
||||
vendorName: vendorName,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static VendorDto fromEntity(Vendor entity) => VendorDto(
|
||||
id: entity.id,
|
||||
vendorCode: entity.vendorCode,
|
||||
vendorName: entity.vendorName,
|
||||
isActive: entity.isActive,
|
||||
isDeleted: entity.isDeleted,
|
||||
note: entity.note,
|
||||
createdAt: entity.createdAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
id: entity.id,
|
||||
vendorCode: entity.vendorCode,
|
||||
vendorName: entity.vendorName,
|
||||
isActive: entity.isActive,
|
||||
isDeleted: entity.isDeleted,
|
||||
note: entity.note,
|
||||
createdAt: entity.createdAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Vendor> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(VendorDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Vendor>(
|
||||
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) {
|
||||
@@ -78,3 +94,8 @@ DateTime? _parseDate(Object? value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> vendorInputToJson(VendorInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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/vendor.dart';
|
||||
import '../../domain/repositories/vendor_repository.dart';
|
||||
import '../dtos/vendor_dto.dart';
|
||||
import '../../../../../core/network/api_client.dart';
|
||||
|
||||
/// 원격 구현체: 공통 ApiClient(Dio) 사용
|
||||
class VendorRepositoryRemote implements VendorRepository {
|
||||
@@ -14,57 +16,60 @@ class VendorRepositoryRemote implements VendorRepository {
|
||||
static const _basePath = '/vendors'; // TODO: 백엔드 경로 확정 시 수정
|
||||
|
||||
@override
|
||||
Future<List<Vendor>> list({
|
||||
Future<PaginatedResult<Vendor>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool includeInactive = true,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<List<dynamic>>(
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (includeInactive) 'include': 'inactive',
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = response.data ?? [];
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map((e) => VendorDto.fromJson(e).toEntity())
|
||||
.toList();
|
||||
final map = response.data ?? const <String, dynamic>{};
|
||||
return VendorDto.parsePaginated(map);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> create(Vendor vendor) async {
|
||||
final dto = VendorDto.fromEntity(vendor);
|
||||
Future<Vendor> create(VendorInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: dto.toJson(),
|
||||
data: vendorInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return VendorDto.fromJson(response.data ?? {}).toEntity();
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> update(Vendor vendor) async {
|
||||
if (vendor.id == null) {
|
||||
throw ArgumentError('id가 없는 엔티티는 수정할 수 없습니다.');
|
||||
}
|
||||
final dto = VendorDto.fromEntity(vendor);
|
||||
Future<Vendor> update(int id, VendorInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/${vendor.id}',
|
||||
data: dto.toJson(),
|
||||
'$_basePath/$id',
|
||||
data: vendorInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return VendorDto.fromJson(response.data ?? {}).toEntity();
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user