Updated the domain model with entities, repos and domain services. Looks good. I think I addressed all the user stories however if I fell short we'll revise as needed.

This commit was merged in pull request #6.
This commit is contained in:
2026-04-10 17:43:58 +05:00
parent 57040bc656
commit 8eb8cd4fbf
14 changed files with 621 additions and 6 deletions
+72
View File
@@ -0,0 +1,72 @@
namespace LibraryApp.Domain.Entities;
public class LendRecord
{
public LendRecordId Id { get; private set; }
public BookInstanceId BookInstanceId { get; private set; }
public MemberId MemberId { get; private set; }
public LendCode Code { get; private set; }
public DateTime LendDate { get; private set; }
public DateTime? ReturnDate { get; private set; }
public LendRecord(BookInstanceId bookInstanceId, MemberId memberId, LendCode code)
: this(new LendRecordId(string.Empty), bookInstanceId, memberId, code, DateTime.UtcNow, null)
{ }
public LendRecord(LendRecordId id, BookInstanceId bookInstanceId, MemberId memberId, LendCode code, DateTime lendDate, DateTime? returnDate)
{
Id = id;
BookInstanceId = bookInstanceId;
MemberId = memberId;
Code = code;
LendDate = lendDate;
ReturnDate = returnDate;
}
public LendRecord MarkAsReturned()
{
if(ReturnDate != null)
throw new InvalidOperationException("This lend record is already marked as returned.");
ReturnDate = DateTime.UtcNow;
return this;
}
public LendRecord UpdateLendDate(DateTime newLendDate)
{
if(ReturnDate != null)
throw new InvalidOperationException("Cannot update lend date for a record that is already marked as returned.");
LendDate = newLendDate;
return this;
}
public LendRecord UnmarkAsReturned()
{
if(ReturnDate == null)
throw new InvalidOperationException("This lend record is not marked as returned.");
ReturnDate = null;
return this;
}
}
public record LendRecordId : DbId
{
public LendRecordId(string id) : base(id) {}
}
/// <summary>
/// A short, human-friendly code written on the physical lend slip alongside the member's name.
/// Must be unique per lend record and no longer than 8 characters.
/// </summary>
public record LendCode
{
public string Code { get; init; }
public LendCode(string code)
{
if (string.IsNullOrWhiteSpace(code))
throw new ArgumentException("Lend code cannot be empty.");
if (code.Length > 8)
throw new ArgumentException("Lend code cannot exceed 8 characters.");
Code = code.ToUpperInvariant();
}
}