feat: add entities for staff personal info, reports, shifts, and user sessions
- Implemented StaffPersonalInfo entity for staff profile data. - Created ReportSummary entity for summarizing report metrics. - Added SpendReport and SpendDataPoint entities for spend reporting. - Introduced AssignedShift, CancelledShift, CompletedShift, OpenShift, PendingAssignment, ShiftDetail, TodayShift entities for shift management. - Developed ClientSession and StaffSession entities for user session management.
This commit is contained in:
@@ -67,6 +67,84 @@ If any of these files are missing or unreadable, notify the user before proceedi
|
||||
}
|
||||
```
|
||||
|
||||
## V2 API Migration Rules (Active Migration)
|
||||
|
||||
The mobile apps are migrating from Firebase Data Connect (direct DB) to V2 REST API. Follow these rules for ALL new and migrated features:
|
||||
|
||||
### Backend Access
|
||||
- **Use `ApiService.get/post/put/delete`** for ALL backend calls — NEVER use Data Connect connectors
|
||||
- Import `ApiService` from `package:krow_core/core.dart`
|
||||
- Use `V2ApiEndpoints` from `package:krow_core/core.dart` for endpoint URLs
|
||||
- V2 API docs are at `docs/BACKEND/API_GUIDES/V2/` — check response shapes before writing code
|
||||
|
||||
### Domain Entities
|
||||
- Domain entities live in `packages/domain/lib/src/entities/` with `fromJson`/`toJson` directly on the class
|
||||
- No separate DTO or adapter layer — entities are self-serializing
|
||||
- Entities are shared across all features via `package:krow_domain/krow_domain.dart`
|
||||
- When migrating: check if the entity already exists and update its `fromJson` to match V2 API response shape
|
||||
|
||||
### Feature Structure
|
||||
- **RepoImpl lives in the feature package** at `data/repositories/`
|
||||
- **Feature-level domain layer is optional** — only add `domain/` when the feature has use cases, validators, or feature-specific interfaces
|
||||
- **Simple features** (read-only, no business logic) = just `data/` + `presentation/`
|
||||
- Do NOT import from `packages/data_connect/` — it is deprecated
|
||||
|
||||
### Status & Type Enums
|
||||
All status/type fields from the V2 API must use Dart enums, NOT raw strings. Parse at the `fromJson` boundary with a safe fallback:
|
||||
```dart
|
||||
enum ShiftStatus {
|
||||
open, assigned, active, completed, cancelled;
|
||||
|
||||
static ShiftStatus fromJson(String value) {
|
||||
switch (value) {
|
||||
case 'OPEN': return ShiftStatus.open;
|
||||
case 'ASSIGNED': return ShiftStatus.assigned;
|
||||
case 'ACTIVE': return ShiftStatus.active;
|
||||
case 'COMPLETED': return ShiftStatus.completed;
|
||||
case 'CANCELLED': return ShiftStatus.cancelled;
|
||||
default: return ShiftStatus.open;
|
||||
}
|
||||
}
|
||||
|
||||
String toJson() {
|
||||
switch (this) {
|
||||
case ShiftStatus.open: return 'OPEN';
|
||||
case ShiftStatus.assigned: return 'ASSIGNED';
|
||||
case ShiftStatus.active: return 'ACTIVE';
|
||||
case ShiftStatus.completed: return 'COMPLETED';
|
||||
case ShiftStatus.cancelled: return 'CANCELLED';
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Place shared enums (used by multiple entities) in `packages/domain/lib/src/entities/enums/`. Feature-specific enums can live in the entity file.
|
||||
|
||||
### RepoImpl Pattern
|
||||
```dart
|
||||
class FeatureRepositoryImpl implements FeatureRepositoryInterface {
|
||||
FeatureRepositoryImpl({required ApiService apiService})
|
||||
: _apiService = apiService;
|
||||
|
||||
final ApiService _apiService;
|
||||
|
||||
Future<List<Shift>> getShifts() async {
|
||||
final ApiResponse response = await _apiService.get(V2ApiEndpoints.staffShiftsAssigned);
|
||||
final List<dynamic> items = response.data['shifts'] as List<dynamic>;
|
||||
return items.map((dynamic json) => Shift.fromJson(json as Map<String, dynamic>)).toList();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### DI Registration
|
||||
```dart
|
||||
// Inject ApiService (available from CoreModule)
|
||||
i.add<FeatureRepositoryImpl>(() => FeatureRepositoryImpl(
|
||||
apiService: i.get<ApiService>(),
|
||||
));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Standard Workflow
|
||||
|
||||
Follow these steps in order for every feature implementation:
|
||||
@@ -91,8 +169,8 @@ Follow these steps in order for every feature implementation:
|
||||
- Create barrel file exporting the domain public API
|
||||
|
||||
### 4. Data Layer
|
||||
- Create models with `fromJson`/`toJson` methods
|
||||
- Implement repository classes using `DataConnectService`
|
||||
- Implement repository classes using `ApiService` with `V2ApiEndpoints` — NOT DataConnectService
|
||||
- Parse V2 API JSON responses into domain entities via `Entity.fromJson()`
|
||||
- Map errors to domain `Failure` types
|
||||
- Create barrel file for data layer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user