changing a way of search my shifts
This commit is contained in:
@@ -83,55 +83,22 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper method to map Data Connect application to domain Shift using ShiftAdapter.
|
|
||||||
Shift _mapApplicationToShift(
|
|
||||||
dynamic app,
|
|
||||||
String status, {
|
|
||||||
bool hasApplied = true,
|
|
||||||
}) {
|
|
||||||
return ShiftAdapter.fromApplicationData(
|
|
||||||
shiftId: app.shift.id,
|
|
||||||
roleId: app.shiftRole.roleId,
|
|
||||||
roleName: app.shiftRole.role.name,
|
|
||||||
businessName: app.shift.order.business.businessName,
|
|
||||||
companyLogoUrl: app.shift.order.business.companyLogoUrl,
|
|
||||||
costPerHour: app.shiftRole.role.costPerHour,
|
|
||||||
shiftLocation: app.shift.location,
|
|
||||||
teamHubName: app.shift.order.teamHub.hubName,
|
|
||||||
shiftDate: _toDateTime(app.shift.date),
|
|
||||||
startTime: _toDateTime(app.shiftRole.startTime),
|
|
||||||
endTime: _toDateTime(app.shiftRole.endTime),
|
|
||||||
createdAt: _toDateTime(app.createdAt),
|
|
||||||
status: status,
|
|
||||||
description: app.shift.description,
|
|
||||||
durationDays: app.shift.durationDays,
|
|
||||||
count: app.shiftRole.count,
|
|
||||||
assigned: app.shiftRole.assigned,
|
|
||||||
eventName: app.shift.order.eventName,
|
|
||||||
hasApplied: hasApplied,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Shift>> getMyShifts({
|
Future<List<Shift>> getMyShifts({
|
||||||
required DateTime start,
|
required DateTime start,
|
||||||
required DateTime end,
|
required DateTime end,
|
||||||
}) async {
|
}) async {
|
||||||
return _fetchApplications(
|
return _fetchApplications(start: start, end: end);
|
||||||
[dc.ApplicationStatus.ACCEPTED, dc.ApplicationStatus.CONFIRMED],
|
|
||||||
start: start,
|
|
||||||
end: end,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Shift>> getPendingAssignments() async {
|
Future<List<Shift>> getPendingAssignments() async {
|
||||||
return _fetchApplications([dc.ApplicationStatus.PENDING]);
|
return <Shift>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Shift>> getCancelledShifts() async {
|
Future<List<Shift>> getCancelledShifts() async {
|
||||||
return _fetchApplications([dc.ApplicationStatus.REJECTED]);
|
return <Shift>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -147,10 +114,37 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
_shiftToAppIdMap[app.shift.id] = app.id;
|
_shiftToAppIdMap[app.shift.id] = app.id;
|
||||||
_appToRoleIdMap[app.id] = app.shiftRole.id;
|
_appToRoleIdMap[app.id] = app.shiftRole.id;
|
||||||
|
|
||||||
|
final String roleName = app.shiftRole.role.name;
|
||||||
|
final String orderName =
|
||||||
|
(app.shift.order.eventName ?? '').trim().isNotEmpty
|
||||||
|
? app.shift.order.eventName!
|
||||||
|
: app.shift.order.business.businessName;
|
||||||
|
final String title = '$roleName - $orderName';
|
||||||
|
final DateTime? shiftDate = _toDateTime(app.shift.date);
|
||||||
|
final DateTime? startDt = _toDateTime(app.shiftRole.startTime);
|
||||||
|
final DateTime? endDt = _toDateTime(app.shiftRole.endTime);
|
||||||
|
final DateTime? createdDt = _toDateTime(app.createdAt);
|
||||||
|
|
||||||
shifts.add(
|
shifts.add(
|
||||||
_mapApplicationToShift(
|
Shift(
|
||||||
app,
|
id: app.shift.id,
|
||||||
_mapStatus(dc.ApplicationStatus.CHECKED_OUT),
|
roleId: app.shiftRole.roleId,
|
||||||
|
title: title,
|
||||||
|
clientName: app.shift.order.business.businessName,
|
||||||
|
logoUrl: app.shift.order.business.companyLogoUrl,
|
||||||
|
hourlyRate: app.shiftRole.role.costPerHour,
|
||||||
|
location: app.shift.location ?? '',
|
||||||
|
locationAddress: app.shift.order.teamHub.hubName,
|
||||||
|
date: shiftDate?.toIso8601String() ?? '',
|
||||||
|
startTime: startDt != null ? DateFormat('HH:mm').format(startDt) : '',
|
||||||
|
endTime: endDt != null ? DateFormat('HH:mm').format(endDt) : '',
|
||||||
|
createdDate: createdDt?.toIso8601String() ?? '',
|
||||||
|
status: _mapStatus(dc.ApplicationStatus.CHECKED_OUT),
|
||||||
|
description: app.shift.description,
|
||||||
|
durationDays: app.shift.durationDays,
|
||||||
|
requiredSlots: app.shiftRole.count,
|
||||||
|
filledSlots: app.shiftRole.assigned ?? 0,
|
||||||
|
hasApplied: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -160,8 +154,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Shift>> _fetchApplications(
|
Future<List<Shift>> _fetchApplications({
|
||||||
List<dc.ApplicationStatus> statuses, {
|
|
||||||
DateTime? start,
|
DateTime? start,
|
||||||
DateTime? end,
|
DateTime? end,
|
||||||
}) async {
|
}) async {
|
||||||
@@ -175,10 +168,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
}
|
}
|
||||||
final response = await query.execute();
|
final response = await query.execute();
|
||||||
|
|
||||||
final statusNames = statuses.map((s) => s.name).toSet();
|
final apps = response.data.applications;
|
||||||
final apps = response.data.applications.where(
|
|
||||||
(app) => statusNames.contains(app.status.stringValue),
|
|
||||||
);
|
|
||||||
final List<Shift> shifts = [];
|
final List<Shift> shifts = [];
|
||||||
|
|
||||||
for (final app in apps) {
|
for (final app in apps) {
|
||||||
@@ -199,8 +189,15 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
// Override status to reflect the application state (e.g., CHECKED_OUT, ACCEPTED)
|
// Override status to reflect the application state (e.g., CHECKED_OUT, ACCEPTED)
|
||||||
final bool hasCheckIn = app.checkInTime != null;
|
final bool hasCheckIn = app.checkInTime != null;
|
||||||
final bool hasCheckOut = app.checkOutTime != null;
|
final bool hasCheckOut = app.checkOutTime != null;
|
||||||
final String mappedStatus =
|
dc.ApplicationStatus? appStatus;
|
||||||
hasCheckOut ? 'completed' : hasCheckIn ? 'checked_in' : _mapStatus(status);
|
if (app.status is dc.Known<dc.ApplicationStatus>) {
|
||||||
|
appStatus = (app.status as dc.Known<dc.ApplicationStatus>).value;
|
||||||
|
}
|
||||||
|
final String mappedStatus = hasCheckOut
|
||||||
|
? 'completed'
|
||||||
|
: hasCheckIn
|
||||||
|
? 'checked_in'
|
||||||
|
: _mapStatus(appStatus ?? dc.ApplicationStatus.ACCEPTED);
|
||||||
shifts.add(
|
shifts.add(
|
||||||
Shift(
|
Shift(
|
||||||
id: app.shift.id,
|
id: app.shift.id,
|
||||||
@@ -516,7 +513,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
shiftId: shiftId,
|
shiftId: shiftId,
|
||||||
staffId: staffId,
|
staffId: staffId,
|
||||||
roleId: targetRoleId,
|
roleId: targetRoleId,
|
||||||
status: dc.ApplicationStatus.CONFIRMED,
|
status: dc.ApplicationStatus.ACCEPTED,
|
||||||
origin: dc.ApplicationOrigin.STAFF,
|
origin: dc.ApplicationOrigin.STAFF,
|
||||||
)
|
)
|
||||||
// TODO: this should be PENDING so a vendor can accept it.
|
// TODO: this should be PENDING so a vendor can accept it.
|
||||||
@@ -550,7 +547,7 @@ class ShiftsRepositoryImpl implements ShiftsRepositoryInterface {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> acceptShift(String shiftId) async {
|
Future<void> acceptShift(String shiftId) async {
|
||||||
await _updateApplicationStatus(shiftId, dc.ApplicationStatus.CONFIRMED);
|
await _updateApplicationStatus(shiftId, dc.ApplicationStatus.ACCEPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -51,13 +51,11 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
|||||||
final myShiftsResult = await getMyShifts(
|
final myShiftsResult = await getMyShifts(
|
||||||
GetMyShiftsArguments(start: days.first, end: days.last),
|
GetMyShiftsArguments(start: days.first, end: days.last),
|
||||||
);
|
);
|
||||||
final pendingResult = await getPendingAssignments();
|
|
||||||
final cancelledResult = await getCancelledShifts();
|
|
||||||
|
|
||||||
emit(ShiftsLoaded(
|
emit(ShiftsLoaded(
|
||||||
myShifts: myShiftsResult,
|
myShifts: myShiftsResult,
|
||||||
pendingShifts: pendingResult,
|
pendingShifts: const [],
|
||||||
cancelledShifts: cancelledResult,
|
cancelledShifts: const [],
|
||||||
availableShifts: const [],
|
availableShifts: const [],
|
||||||
historyShifts: const [],
|
historyShifts: const [],
|
||||||
availableLoading: false,
|
availableLoading: false,
|
||||||
@@ -130,13 +128,10 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final pendingResult = await getPendingAssignments();
|
|
||||||
final cancelledResult = await getCancelledShifts();
|
|
||||||
|
|
||||||
emit(ShiftsLoaded(
|
emit(ShiftsLoaded(
|
||||||
myShifts: myShiftsResult,
|
myShifts: myShiftsResult,
|
||||||
pendingShifts: pendingResult,
|
pendingShifts: const [],
|
||||||
cancelledShifts: cancelledResult,
|
cancelledShifts: const [],
|
||||||
availableShifts: const [],
|
availableShifts: const [],
|
||||||
historyShifts: const [],
|
historyShifts: const [],
|
||||||
availableLoading: false,
|
availableLoading: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user