Files
superport/lib/data/models/user/user_dto.dart
JiWoong Sul df7dd8dacb
Some checks failed
Flutter Test & Quality Check / Test on macos-latest (push) Has been cancelled
Flutter Test & Quality Check / Test on ubuntu-latest (push) Has been cancelled
Flutter Test & Quality Check / Build APK (push) Has been cancelled
feat: 대규모 코드베이스 개선 - 백엔드 통합성 강화 및 UI 일관성 완성
- CLAUDE.md 대폭 개선: 개발 가이드라인 및 프로젝트 상태 문서화
- 백엔드 API 통합: 모든 엔티티 간 Foreign Key 관계 완벽 구현
- UI 일관성 강화: shadcn_ui 컴포넌트 표준화 적용
- 데이터 모델 개선: DTO 및 모델 클래스 백엔드 스키마와 100% 일치
- 사용자 관리: 회사 연결, 중복 검사, 입력 검증 기능 추가
- 창고 관리: 우편번호 연결, 중복 검사 기능 강화
- 회사 관리: 우편번호 연결, 중복 검사 로직 구현
- 장비 관리: 불필요한 카테고리 필드 제거, 벤더-모델 관계 정리
- 우편번호 시스템: 검색 다이얼로그 Provider 버그 수정

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 15:49:05 +09:00

124 lines
3.5 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:superport/data/models/company/company_dto.dart';
import 'package:superport/models/user_model.dart';
part 'user_dto.freezed.dart';
part 'user_dto.g.dart';
@freezed
class UserDto with _$UserDto {
const UserDto._(); // Private constructor for getters
const factory UserDto({
int? id,
required String name,
String? phone,
String? email,
@JsonKey(name: 'companies_id') required int companiesId,
// Nested data (optional, populated in GET requests)
@JsonKey(name: 'company') CompanyNameDto? company,
}) = _UserDto;
factory UserDto.fromJson(Map<String, dynamic> json) => _$UserDtoFromJson(json);
// 도메인 모델로 변환
User toDomainModel() {
return User(
id: id,
name: name,
email: email,
phone: phone,
);
}
}
@freezed
class UserRequestDto with _$UserRequestDto {
const factory UserRequestDto({
required String name,
String? phone,
String? email,
@JsonKey(name: 'companies_id') required int companiesId,
}) = _UserRequestDto;
factory UserRequestDto.fromJson(Map<String, dynamic> json) =>
_$UserRequestDtoFromJson(json);
}
@freezed
class UserUpdateRequestDto with _$UserUpdateRequestDto {
const factory UserUpdateRequestDto({
String? name,
String? phone,
String? email,
@JsonKey(name: 'companies_id') int? companiesId,
}) = _UserUpdateRequestDto;
factory UserUpdateRequestDto.fromJson(Map<String, dynamic> json) =>
_$UserUpdateRequestDtoFromJson(json);
// 도메인 모델에서 생성
factory UserUpdateRequestDto.fromDomain(User user, {String? newPassword}) {
return UserUpdateRequestDto(
name: user.name,
phone: user.phone,
email: user.email,
companiesId: null, // companiesId는 업데이트에서 처리하지 않음
);
}
}
@freezed
class UserListResponse with _$UserListResponse {
const factory UserListResponse({
@JsonKey(name: 'data') required List<UserDto> 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,
}) = _UserListResponse;
factory UserListResponse.fromJson(Map<String, dynamic> json) =>
_$UserListResponseFromJson(json);
}
// UserListDto (legacy support)
@freezed
class UserListDto with _$UserListDto {
const UserListDto._(); // Private constructor for methods
const factory UserListDto({
@JsonKey(name: 'users') required List<UserDto> users,
@JsonKey(name: 'total') required int total,
@JsonKey(name: 'page') required int page,
@JsonKey(name: 'per_page') required int perPage,
@JsonKey(name: 'total_pages') required int totalPages,
}) = _UserListDto;
factory UserListDto.fromJson(Map<String, dynamic> json) =>
_$UserListDtoFromJson(json);
// 도메인 모델 리스트로 변환
List<User> toDomainModels() {
return users.map((dto) => dto.toDomainModel()).toList();
}
// 페이지네이션 정보 접근을 위한 getter들
int get first => page;
int get last => totalPages;
}
// CheckUsernameResponse (legacy support)
@freezed
class CheckUsernameResponse with _$CheckUsernameResponse {
const factory CheckUsernameResponse({
@JsonKey(name: 'available') required bool available,
String? message,
}) = _CheckUsernameResponse;
factory CheckUsernameResponse.fromJson(Map<String, dynamic> json) =>
_$CheckUsernameResponseFromJson(json);
}