주석화 진행상황 정리하고 핵심 모듈에 한글 주석 추가
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:superport_v2/core/common/utils/json_utils.dart';
|
||||
|
||||
import '../../domain/entities/product.dart';
|
||||
|
||||
/// 제품(Product) API 응답을 표현하는 DTO.
|
||||
class ProductDto {
|
||||
ProductDto({
|
||||
this.id,
|
||||
@@ -28,6 +29,7 @@ class ProductDto {
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
/// JSON에서 제품 정보를 파싱한다.
|
||||
factory ProductDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductDto(
|
||||
id: json['id'] as int?,
|
||||
@@ -47,6 +49,7 @@ class ProductDto {
|
||||
);
|
||||
}
|
||||
|
||||
/// DTO를 JSON 맵으로 직렬화한다.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
@@ -62,6 +65,7 @@ class ProductDto {
|
||||
};
|
||||
}
|
||||
|
||||
/// DTO를 도메인 [Product] 엔티티로 변환한다.
|
||||
Product toEntity() => Product(
|
||||
id: id,
|
||||
productCode: productCode,
|
||||
@@ -75,6 +79,7 @@ class ProductDto {
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
/// 엔티티 값을 DTO로 역변환한다.
|
||||
static ProductDto fromEntity(Product entity) => ProductDto(
|
||||
id: entity.id,
|
||||
productCode: entity.productCode,
|
||||
@@ -96,6 +101,7 @@ class ProductDto {
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
|
||||
/// 페이징 응답을 [PaginatedResult]로 변환한다.
|
||||
static PaginatedResult<Product> parsePaginated(Map<String, dynamic>? json) {
|
||||
final rawItems = JsonUtils.extractList(json, keys: const ['items']);
|
||||
final items = rawItems
|
||||
@@ -111,6 +117,7 @@ class ProductDto {
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품에 연결된 공급업체 정보를 담는 DTO.
|
||||
class ProductVendorDto {
|
||||
ProductVendorDto({
|
||||
required this.id,
|
||||
@@ -122,6 +129,7 @@ class ProductVendorDto {
|
||||
final String vendorCode;
|
||||
final String vendorName;
|
||||
|
||||
/// JSON에서 공급업체 정보를 파싱한다.
|
||||
factory ProductVendorDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductVendorDto(
|
||||
id: json['id'] as int,
|
||||
@@ -130,20 +138,24 @@ class ProductVendorDto {
|
||||
);
|
||||
}
|
||||
|
||||
/// DTO를 JSON 맵으로 직렬화한다.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'vendor_code': vendorCode, 'vendor_name': vendorName};
|
||||
}
|
||||
|
||||
/// DTO를 [ProductVendor] 엔티티로 변환한다.
|
||||
ProductVendor toEntity() =>
|
||||
ProductVendor(id: id, vendorCode: vendorCode, vendorName: vendorName);
|
||||
}
|
||||
|
||||
/// 제품의 단위(UOM) 정보를 담는 DTO.
|
||||
class ProductUomDto {
|
||||
ProductUomDto({required this.id, required this.uomName});
|
||||
|
||||
final int id;
|
||||
final String uomName;
|
||||
|
||||
/// JSON에서 단위 정보를 파싱한다.
|
||||
factory ProductUomDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductUomDto(
|
||||
id: json['id'] as int,
|
||||
@@ -151,13 +163,16 @@ class ProductUomDto {
|
||||
);
|
||||
}
|
||||
|
||||
/// DTO를 JSON 맵으로 직렬화한다.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'uom_name': uomName};
|
||||
}
|
||||
|
||||
/// DTO를 [ProductUom] 엔티티로 변환한다.
|
||||
ProductUom toEntity() => ProductUom(id: id, uomName: uomName);
|
||||
}
|
||||
|
||||
/// 문자열/DateTime을 파싱해 [DateTime]으로 변환한다.
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
@@ -165,6 +180,7 @@ DateTime? _parseDate(Object? value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 제품 입력 모델을 API 요청 바디로 변환한다.
|
||||
Map<String, dynamic> productInputToJson(ProductInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
import '../dtos/product_dto.dart';
|
||||
|
||||
/// 제품 마스터 API를 호출하는 원격 저장소.
|
||||
class ProductRepositoryRemote implements ProductRepository {
|
||||
ProductRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
@@ -13,6 +14,7 @@ class ProductRepositoryRemote implements ProductRepository {
|
||||
|
||||
static const _basePath = '/products';
|
||||
|
||||
/// 제품 목록을 조회한다.
|
||||
@override
|
||||
Future<PaginatedResult<Product>> list({
|
||||
int page = 1,
|
||||
@@ -38,6 +40,7 @@ class ProductRepositoryRemote implements ProductRepository {
|
||||
return ProductDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
|
||||
/// 제품을 생성한다.
|
||||
@override
|
||||
Future<Product> create(ProductInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
@@ -49,6 +52,7 @@ class ProductRepositoryRemote implements ProductRepository {
|
||||
return ProductDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
/// 제품 정보를 수정한다.
|
||||
@override
|
||||
Future<Product> update(int id, ProductInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
@@ -60,11 +64,13 @@ class ProductRepositoryRemote implements ProductRepository {
|
||||
return ProductDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
/// 제품을 삭제한다.
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
|
||||
/// 삭제된 제품을 복구한다.
|
||||
@override
|
||||
Future<Product> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
|
||||
Reference in New Issue
Block a user