환경 초기화 및 벤더 리포지토리 스켈레톤 도입

This commit is contained in:
JiWoong Sul
2025-09-22 17:38:51 +09:00
commit 5c9de2594a
171 changed files with 13304 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
import '../../domain/entities/vendor.dart';
/// 벤더 DTO (JSON 직렬화/역직렬화)
class VendorDto {
VendorDto({
this.id,
required this.vendorCode,
required this.vendorName,
this.isActive = true,
this.isDeleted = false,
this.note,
this.createdAt,
this.updatedAt,
});
final int? id;
final String vendorCode;
final String vendorName;
final bool isActive;
final bool isDeleted;
final String? note;
final DateTime? createdAt;
final DateTime? updatedAt;
factory VendorDto.fromJson(Map<String, dynamic> json) {
return VendorDto(
id: json['id'] as int?,
vendorCode: json['vendor_code'] as String,
vendorName: json['vendor_name'] as String,
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']),
);
}
Map<String, dynamic> toJson() {
return {
if (id != null) 'id': id,
'vendor_code': vendorCode,
'vendor_name': vendorName,
'is_active': isActive,
'is_deleted': isDeleted,
'note': note,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
Vendor toEntity() => Vendor(
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,
);
}
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;
}

View File

@@ -0,0 +1,70 @@
import 'package:dio/dio.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 {
VendorRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
final ApiClient _api;
static const _basePath = '/vendors'; // TODO: 백엔드 경로 확정 시 수정
@override
Future<List<Vendor>> list({
int page = 1,
int pageSize = 20,
String? query,
bool includeInactive = true,
}) async {
final response = await _api.get<List<dynamic>>(
_basePath,
query: {
'page': page,
'page_size': pageSize,
if (query != null && query.isNotEmpty) 'q': query,
if (includeInactive) 'include': 'inactive',
},
options: Options(responseType: ResponseType.json),
);
final data = response.data ?? [];
return data
.whereType<Map<String, dynamic>>()
.map((e) => VendorDto.fromJson(e).toEntity())
.toList();
}
@override
Future<Vendor> create(Vendor vendor) async {
final dto = VendorDto.fromEntity(vendor);
final response = await _api.post<Map<String, dynamic>>(
_basePath,
data: dto.toJson(),
options: Options(responseType: ResponseType.json),
);
return VendorDto.fromJson(response.data ?? {}).toEntity();
}
@override
Future<Vendor> update(Vendor vendor) async {
if (vendor.id == null) {
throw ArgumentError('id가 없는 엔티티는 수정할 수 없습니다.');
}
final dto = VendorDto.fromEntity(vendor);
final response = await _api.patch<Map<String, dynamic>>(
'$_basePath/${vendor.id}',
data: dto.toJson(),
options: Options(responseType: ResponseType.json),
);
return VendorDto.fromJson(response.data ?? {}).toEntity();
}
@override
Future<void> delete(int id) async {
await _api.delete<void>('$_basePath/$id');
}
}