This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7230bda
commit 90f963b
Showing
15 changed files
with
246 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:librarian_app/src/features/borrowers/models/borrower_model.dart'; | ||
|
||
import 'thing_summary_model.dart'; | ||
|
||
class LoanDetailsModel { | ||
final String id; | ||
final int number; | ||
final ThingSummaryModel thing; | ||
final BorrowerModel borrower; | ||
final DateTime checkedOutDate; | ||
final String? notes; | ||
final int remindersSent; | ||
DateTime dueDate; | ||
DateTime? checkedInDate; | ||
|
||
bool get isOverdue { | ||
final now = DateTime.now(); | ||
return DateUtils.dateOnly(dueDate).isBefore(DateUtils.dateOnly(now)); | ||
} | ||
|
||
bool get isDueToday => DateUtils.isSameDay(DateTime.now(), dueDate); | ||
|
||
LoanDetailsModel({ | ||
required this.id, | ||
required this.number, | ||
required this.thing, | ||
required this.borrower, | ||
required this.checkedOutDate, | ||
required this.dueDate, | ||
required this.remindersSent, | ||
this.checkedInDate, | ||
this.notes, | ||
}); | ||
|
||
factory LoanDetailsModel.fromJson(Map<String, dynamic> json) { | ||
return LoanDetailsModel( | ||
id: json['id'] as String? ?? '?', | ||
number: json['number'] as int, | ||
thing: ThingSummaryModel.fromJson(json['thing'] as Map<String, dynamic>), | ||
borrower: BorrowerModel( | ||
id: json['borrower']?['id'] as String? ?? '?', | ||
name: json['borrower']?['name'] as String? ?? '???', | ||
email: json['borrower']?['contact']['email'] as String?, | ||
phone: json['borrower']?['contact']['phone'] as String?, | ||
issues: [], | ||
), | ||
notes: json['notes'] as String?, | ||
checkedOutDate: json['checkedOutDate'] != null | ||
? DateTime.parse(json['checkedOutDate'] as String) | ||
: DateTime.now(), | ||
checkedInDate: json['checkedInDate'] != null | ||
? DateTime.parse(json['checkedInDate'] as String) | ||
: null, | ||
dueDate: json['dueBackDate'] != null | ||
? DateTime.parse(json['dueBackDate']) | ||
: DateTime.now(), | ||
remindersSent: json['remindersSent'] as int, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
lib/src/features/loans/providers/loan_details_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/src/features/loans/providers/loans_repository_provider.dart'; | ||
import 'package:librarian_app/src/features/loans/providers/selected_loan_provider.dart'; | ||
|
||
import '../models/loan_model.dart'; | ||
import '../models/loan_details_model.dart'; | ||
|
||
final loanDetailsProvider = Provider<Future<LoanModel?>>((ref) async { | ||
final loanDetailsProvider = Provider<Future<LoanDetailsModel?>>((ref) async { | ||
ref.watch(loansRepositoryProvider); | ||
final selectedLoan = ref.watch(selectedLoanProvider); | ||
if (selectedLoan == null) { | ||
return null; | ||
} | ||
|
||
final loans = await ref.watch(loansRepositoryProvider); | ||
return loans.firstWhereOrNull((loan) => | ||
loan.id == selectedLoan.id && loan.thing.id == selectedLoan.thing.id); | ||
return await ref | ||
.read(loansRepositoryProvider.notifier) | ||
.getLoan(id: selectedLoan.id, thingId: selectedLoan.thing.id); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.