56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'zipcode_dto.freezed.dart';
|
|
part 'zipcode_dto.g.dart';
|
|
|
|
@freezed
|
|
class ZipcodeDto with _$ZipcodeDto {
|
|
const ZipcodeDto._(); // Private constructor for getters
|
|
|
|
const factory ZipcodeDto({
|
|
required String zipcode,
|
|
required String sido,
|
|
required String gu,
|
|
@JsonKey(name: 'Etc') required String etc,
|
|
@JsonKey(name: 'is_deleted')
|
|
@Default(false) bool isDeleted,
|
|
@JsonKey(name: 'created_at')
|
|
DateTime? createdAt,
|
|
@JsonKey(name: 'updated_at')
|
|
DateTime? updatedAt,
|
|
}) = _ZipcodeDto;
|
|
|
|
// isActive 계산 속성 (is_deleted의 반대)
|
|
bool get isActive => !isDeleted;
|
|
|
|
// 전체 주소 문자열 생성
|
|
String get fullAddress => '$sido $gu $etc';
|
|
|
|
// 축약된 주소 (시도 + 구)
|
|
String get shortAddress => '$sido $gu';
|
|
|
|
// 검색용 문자열 (모든 필드 결합)
|
|
String get searchableText => '$zipcode $sido $gu $etc';
|
|
|
|
factory ZipcodeDto.fromJson(Map<String, dynamic> json) => _$ZipcodeDtoFromJson(json);
|
|
}
|
|
|
|
// API 응답 래퍼
|
|
@freezed
|
|
class ZipcodeListResponse with _$ZipcodeListResponse {
|
|
const factory ZipcodeListResponse({
|
|
@JsonKey(name: 'data')
|
|
required List<ZipcodeDto> items,
|
|
@JsonKey(name: 'total')
|
|
required int totalCount,
|
|
@JsonKey(name: 'page')
|
|
required int currentPage,
|
|
@JsonKey(name: 'total_pages')
|
|
required int totalPages,
|
|
@JsonKey(name: 'page_size')
|
|
int? pageSize,
|
|
}) = _ZipcodeListResponse;
|
|
|
|
factory ZipcodeListResponse.fromJson(Map<String, dynamic> json) =>
|
|
_$ZipcodeListResponseFromJson(json);
|
|
} |