프로젝트 최초 커밋
This commit is contained in:
57
lib/screens/license/controllers/license_form_controller.dart
Normal file
57
lib/screens/license/controllers/license_form_controller.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/license_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
|
||||
// 라이센스 폼의 상태 및 비즈니스 로직을 담당하는 컨트롤러
|
||||
class LicenseFormController {
|
||||
final MockDataService dataService;
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
bool isEditMode = false;
|
||||
int? licenseId;
|
||||
String name = '';
|
||||
int durationMonths = 12; // 기본값: 12개월
|
||||
String visitCycle = '미방문'; // 기본값: 미방문
|
||||
|
||||
LicenseFormController({required this.dataService, this.licenseId});
|
||||
|
||||
// 라이센스 정보 로드 (수정 모드)
|
||||
void loadLicense() {
|
||||
if (licenseId == null) return;
|
||||
final license = dataService.getLicenseById(licenseId!);
|
||||
if (license != null) {
|
||||
name = license.name;
|
||||
durationMonths = license.durationMonths;
|
||||
visitCycle = license.visitCycle;
|
||||
}
|
||||
}
|
||||
|
||||
// 라이센스 저장 (UI에서 호출)
|
||||
void saveLicense(Function() onSuccess) {
|
||||
if (formKey.currentState?.validate() != true) return;
|
||||
formKey.currentState?.save();
|
||||
if (isEditMode && licenseId != null) {
|
||||
final license = dataService.getLicenseById(licenseId!);
|
||||
if (license != null) {
|
||||
final updatedLicense = License(
|
||||
id: license.id,
|
||||
companyId: license.companyId,
|
||||
name: name,
|
||||
durationMonths: durationMonths,
|
||||
visitCycle: visitCycle,
|
||||
);
|
||||
dataService.updateLicense(updatedLicense);
|
||||
}
|
||||
} else {
|
||||
// 라이센스 추가 시 임시 회사 ID 사용 또는 나중에 설정하도록 변경
|
||||
final newLicense = License(
|
||||
companyId: 1, // 기본값 또는 필요에 따라 수정
|
||||
name: name,
|
||||
durationMonths: durationMonths,
|
||||
visitCycle: visitCycle,
|
||||
);
|
||||
dataService.addLicense(newLicense);
|
||||
}
|
||||
onSuccess();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user