Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Booking.cs #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System;

namespace CodelyTv.Booking
{
public sealed class Booking
{
private readonly BookingId id;
private readonly DateRange dateRange;
private readonly Customer customer;
private readonly BookingType bookingType;
private readonly Discount discount;
private readonly Tax tax;
public BookingId Id { get; }
public DateRange DateRange { get; }
public Customer Customer { get; }
public BookingType BookingType { get; }
public Discount Discount { get; }
public Tax Tax { get; }

public Booking(
BookingId id,
Expand All @@ -20,30 +20,25 @@ public Booking(
Tax tax
)
{
this.id = id;
this.dateRange = dateRange;
this.customer = customer;
this.bookingType = bookingType;
this.discount = discount;
this.tax = tax;
Id = id ?? throw new ArgumentNullException(nameof(id), "Booking ID cannot be null.");
DateRange = dateRange ?? throw new ArgumentNullException(nameof(dateRange), "Date range cannot be null.");
Customer = customer ?? throw new ArgumentNullException(nameof(customer), "Customer cannot be null.");
BookingType = bookingType;
Discount = discount ?? throw new ArgumentNullException(nameof(discount), "Discount cannot be null.");
Tax = tax ?? throw new ArgumentNullException(nameof(tax), "Tax cannot be null.");
}

public BookingStatus StatusFor(DateTime date)
{
if (date < dateRange.StartDate)
if (date < DateRange.StartDate)
{
return BookingStatus.NOT_STARTED;
}

if (IsBetween(date, dateRange))
{
return BookingStatus.ACTIVE;
}

return BookingStatus.FINISHED;
return IsBetween(date, DateRange) ? BookingStatus.ACTIVE : BookingStatus.FINISHED;
}

private bool IsBetween(DateTime date, DateRange dateRange)
private static bool IsBetween(DateTime date, DateRange dateRange)
{
return date > dateRange.StartDate && date < dateRange.EndDate;
}
Expand Down