feat(breaks): Implement break functionality with Break entity and adapter
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import '../../../entities/shifts/break/break.dart';
|
||||
|
||||
/// Adapter for Break related data.
|
||||
class BreakAdapter {
|
||||
/// Maps break data to a Break entity.
|
||||
///
|
||||
/// [isPaid] whether the break is paid.
|
||||
/// [breakTime] the string representation of the break duration (e.g., 'MIN_10', 'MIN_30').
|
||||
static Break fromData({
|
||||
required bool isPaid,
|
||||
required String? breakTime,
|
||||
}) {
|
||||
return Break(
|
||||
isBreakPaid: isPaid,
|
||||
duration: _parseDuration(breakTime),
|
||||
);
|
||||
}
|
||||
|
||||
static BreakDuration _parseDuration(String? breakTime) {
|
||||
if (breakTime == null) return BreakDuration.none;
|
||||
|
||||
switch (breakTime.toUpperCase()) {
|
||||
case 'MIN_10':
|
||||
return BreakDuration.ten;
|
||||
case 'MIN_15':
|
||||
return BreakDuration.fifteen;
|
||||
case 'MIN_20':
|
||||
return BreakDuration.twenty;
|
||||
case 'MIN_30':
|
||||
return BreakDuration.thirty;
|
||||
case 'MIN_45':
|
||||
return BreakDuration.fortyFive;
|
||||
case 'MIN_60':
|
||||
return BreakDuration.sixty;
|
||||
default:
|
||||
return BreakDuration.none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// Enum representing common break durations in minutes.
|
||||
enum BreakDuration {
|
||||
/// No break.
|
||||
none(0),
|
||||
|
||||
/// 10 minutes break.
|
||||
ten(10),
|
||||
|
||||
/// 15 minutes break.
|
||||
fifteen(15),
|
||||
|
||||
/// 20 minutes break.
|
||||
twenty(20),
|
||||
|
||||
/// 30 minutes break.
|
||||
thirty(30),
|
||||
|
||||
/// 45 minutes break.
|
||||
fortyFive(45),
|
||||
|
||||
/// 60 minutes break.
|
||||
sixty(60);
|
||||
|
||||
/// The duration in minutes.
|
||||
final int minutes;
|
||||
|
||||
const BreakDuration(this.minutes);
|
||||
}
|
||||
|
||||
/// Represents a break configuration for a shift.
|
||||
class Break extends Equatable {
|
||||
const Break({
|
||||
required this.duration,
|
||||
required this.isBreakPaid,
|
||||
});
|
||||
|
||||
/// The duration of the break.
|
||||
final BreakDuration duration;
|
||||
|
||||
/// Whether the break is paid or unpaid.
|
||||
final bool isBreakPaid;
|
||||
|
||||
@override
|
||||
List<Object?> get props => <Object?>[duration, isBreakPaid];
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:krow_domain/src/entities/shifts/break/break.dart';
|
||||
|
||||
class Shift extends Equatable {
|
||||
final String id;
|
||||
@@ -29,6 +30,7 @@ class Shift extends Equatable {
|
||||
final String? roleId;
|
||||
final bool? hasApplied;
|
||||
final double? totalValue;
|
||||
final Break? breakInfo;
|
||||
|
||||
const Shift({
|
||||
required this.id,
|
||||
@@ -59,48 +61,49 @@ class Shift extends Equatable {
|
||||
this.roleId,
|
||||
this.hasApplied,
|
||||
this.totalValue,
|
||||
this.breakInfo,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
title,
|
||||
clientName,
|
||||
logoUrl,
|
||||
hourlyRate,
|
||||
location,
|
||||
locationAddress,
|
||||
date,
|
||||
startTime,
|
||||
endTime,
|
||||
createdDate,
|
||||
tipsAvailable,
|
||||
travelTime,
|
||||
mealProvided,
|
||||
parkingAvailable,
|
||||
gasCompensation,
|
||||
description,
|
||||
instructions,
|
||||
managers,
|
||||
latitude,
|
||||
longitude,
|
||||
status,
|
||||
durationDays,
|
||||
requiredSlots,
|
||||
filledSlots,
|
||||
roleId,
|
||||
hasApplied,
|
||||
totalValue,
|
||||
];
|
||||
List<Object?> get props => <Object?>[
|
||||
id,
|
||||
title,
|
||||
clientName,
|
||||
logoUrl,
|
||||
hourlyRate,
|
||||
location,
|
||||
locationAddress,
|
||||
date,
|
||||
startTime,
|
||||
endTime,
|
||||
createdDate,
|
||||
tipsAvailable,
|
||||
travelTime,
|
||||
mealProvided,
|
||||
parkingAvailable,
|
||||
gasCompensation,
|
||||
description,
|
||||
instructions,
|
||||
managers,
|
||||
latitude,
|
||||
longitude,
|
||||
status,
|
||||
durationDays,
|
||||
requiredSlots,
|
||||
filledSlots,
|
||||
roleId,
|
||||
hasApplied,
|
||||
totalValue,
|
||||
breakInfo,
|
||||
];
|
||||
}
|
||||
|
||||
class ShiftManager extends Equatable {
|
||||
const ShiftManager({required this.name, required this.phone, this.avatar});
|
||||
|
||||
final String name;
|
||||
final String phone;
|
||||
final String? avatar;
|
||||
|
||||
const ShiftManager({required this.name, required this.phone, this.avatar});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [name, phone, avatar];
|
||||
List<Object?> get props => <Object?>[name, phone, avatar];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user