mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
feat: add template id to AvailibityModel to indicate if a template was used for creation
This commit is contained in:
parent
6748a2440c
commit
61bc0a8b53
3 changed files with 20 additions and 2 deletions
|
@ -8,6 +8,7 @@ class AvailabilityModel {
|
|||
required this.endDate,
|
||||
required this.breaks,
|
||||
this.id,
|
||||
this.templateId,
|
||||
});
|
||||
|
||||
/// the identifier for this availability
|
||||
|
@ -16,6 +17,10 @@ class AvailabilityModel {
|
|||
/// The uniquely identifiable string for who or what the
|
||||
final String userId;
|
||||
|
||||
/// The identifier of the [AvailabilityTemplateModel] that this availability
|
||||
/// is associated with if any.
|
||||
final String? templateId;
|
||||
|
||||
/// The from date of this availability.
|
||||
///
|
||||
/// [startDate] will always have to be before the end date.
|
||||
|
@ -34,6 +39,7 @@ class AvailabilityModel {
|
|||
AvailabilityModel copyWith({
|
||||
String? id,
|
||||
String? userId,
|
||||
String? templateId,
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
List<AvailabilityBreakModel>? breaks,
|
||||
|
@ -41,6 +47,7 @@ class AvailabilityModel {
|
|||
AvailabilityModel(
|
||||
id: id ?? this.id,
|
||||
userId: userId ?? this.userId,
|
||||
templateId: templateId ?? this.templateId,
|
||||
startDate: startDate ?? this.startDate,
|
||||
endDate: endDate ?? this.endDate,
|
||||
breaks: breaks ?? this.breaks,
|
||||
|
|
|
@ -70,7 +70,12 @@ class AvailabilityTemplateModel {
|
|||
|
||||
/// applies the template to a range of dates
|
||||
List<AvailabilityModel> apply(DateTime start, DateTime end) =>
|
||||
templateData.apply(userId: userId, start: start, end: end);
|
||||
templateData.apply(
|
||||
userId: userId,
|
||||
start: start,
|
||||
end: end,
|
||||
templateId: id,
|
||||
);
|
||||
}
|
||||
|
||||
/// Used as the key for defining week-based templates
|
||||
|
@ -124,6 +129,7 @@ abstract interface class TemplateData {
|
|||
required String userId,
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
required String? templateId,
|
||||
});
|
||||
|
||||
/// Serialize the template to representational data
|
||||
|
@ -199,9 +205,9 @@ class WeekTemplateData implements TemplateData {
|
|||
required String userId,
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
String? templateId,
|
||||
}) {
|
||||
var dates = _getDatesBetween(start, end);
|
||||
|
||||
return [
|
||||
for (var date in dates)
|
||||
if (data.containsKey(WeekDay.fromDateTime(date)))
|
||||
|
@ -209,6 +215,7 @@ class WeekTemplateData implements TemplateData {
|
|||
start: date,
|
||||
end: date,
|
||||
userId: userId,
|
||||
templateId: templateId,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -266,6 +273,7 @@ class DayTemplateData implements TemplateData {
|
|||
required String userId,
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
String? templateId,
|
||||
}) {
|
||||
var dates = _getDatesBetween(start, end);
|
||||
|
||||
|
@ -273,6 +281,7 @@ class DayTemplateData implements TemplateData {
|
|||
for (var date in dates) ...[
|
||||
AvailabilityModel(
|
||||
userId: userId,
|
||||
templateId: templateId,
|
||||
startDate: date.mergeTime(startTime),
|
||||
endDate: date.mergeTime(endTime),
|
||||
breaks: [
|
||||
|
|
|
@ -30,6 +30,7 @@ void main() {
|
|||
var sunday = createTemplate(7);
|
||||
|
||||
var sut = AvailabilityTemplateModel(
|
||||
id: "",
|
||||
userId: "",
|
||||
name: "",
|
||||
color: 0,
|
||||
|
@ -142,6 +143,7 @@ void main() {
|
|||
}
|
||||
|
||||
var weektemplate = AvailabilityTemplateModel(
|
||||
id: "id",
|
||||
userId: "1",
|
||||
name: "test",
|
||||
color: 0xFFAABBCC,
|
||||
|
|
Loading…
Reference in a new issue