Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<PackageVersion Include="Flurl" Version="3.0.7" />
<PackageVersion Include="Flurl.Http" Version="3.2.4" />
<PackageVersion Include="GoogleReCaptcha.V3" Version="1.3.1" />
<PackageVersion Include="ISO3166" Version="1.0.4" />
<PackageVersion Include="Markdig" Version="0.33.0" />
<PackageVersion Include="MediaInfo.Wrapper.Core" Version="21.9.3" />
<PackageVersion Include="MediatR" Version="12.1.1" />
Expand Down
30 changes: 11 additions & 19 deletions src/DevBetterWeb.Core/Entities/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ internal Member(string userId, string firstName, string lastName)
public string? LastName { get; private set; }
public Birthday? Birthday { get; private set; }
public string? AboutInfo { get; private set; }
public string? Address { get; private set; }
public Address? ShippingAddress { get; private set; }
public Geolocation? CityLocation { get; private set; }

Expand All @@ -64,6 +63,9 @@ internal Member(string userId, string firstName, string lastName)
public string? DiscordUsername { get; private set; }
public string? MastodonUrl { get; private set; } // added and deployed 5 Jan 2022 but site broke

private readonly List<MemberAddressHistory> _addressHistory = new();
public IReadOnlyList<MemberAddressHistory> AddressHistory => _addressHistory.AsReadOnly();

public List<Book> BooksRead { get; set; } = new List<Book>();
public List<Book> UploadedBooks { get; set; } = new List<Book>();
public List<MemberVideoProgress> MemberVideosProgress { get; set; } = new List<MemberVideoProgress>();
Expand Down Expand Up @@ -123,21 +125,6 @@ public void UpdateName(string? firstName, string? lastName, bool isEvent = true)
}
}

public void UpdateAddress(string? address, bool isEvent = true)
{
var isUpdate = false;
if (Address != address)
{
Address = address;
isUpdate = true;
}

if (isEvent && isUpdate)
{
CreateOrUpdateAddressUpdateEvent(nameof(Address));
}
}

public void UpdateBirthday(int? day, int? month, bool isEvent = true)
{
if (day == Birthday?.Day && month == Birthday?.Month) return;
Expand Down Expand Up @@ -197,10 +184,15 @@ public void UpdateShippingAddress(string street, string city, string state, stri
isUpdated = ShippingAddress.Update(street, city, state, postalCode, country);
}

if (isEvent && isUpdated)
if (isUpdated)
{
var addressUpdatedEvent = new MemberAddressUpdatedEvent(this, ShippingAddress);
Events.Add(addressUpdatedEvent);
_addressHistory.Add(new MemberAddressHistory(Id, ShippingAddress));

if (isEvent)
{
var addressUpdatedEvent = new MemberAddressUpdatedEvent(this, ShippingAddress);
Events.Add(addressUpdatedEvent);
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/DevBetterWeb.Core/Entities/MemberAddressHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using DevBetterWeb.Core.Interfaces;
using DevBetterWeb.Core.SharedKernel;
using DevBetterWeb.Core.ValueObjects;

namespace DevBetterWeb.Core.Entities;
public class MemberAddressHistory : BaseEntity, IAggregateRoot
{
public int MemberId { get; private set; }
public Address? Address { get; private set; }
public DateTimeOffset UpdatedOn { get; private set; }

public MemberAddressHistory(int memberId, Address address)
{
MemberId = memberId;
Address = address;
UpdatedOn = DateTime.UtcNow;
}

private MemberAddressHistory()
{
// EF
}
}
4 changes: 3 additions & 1 deletion src/DevBetterWeb.Core/Specs/MemberByUserIdSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class MemberByUserIdSpec : Specification<Member>,
{
public MemberByUserIdSpec(string userId)
{
Query.Where(member => member.UserId == userId);
Query
Comment thread Fixed
.Include(member => member.AddressHistory)
.Where(member => member.UserId == userId);
}
}
6 changes: 5 additions & 1 deletion src/DevBetterWeb.Core/ValueObjects/Address.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using CSharpFunctionalExtensions;

namespace DevBetterWeb.Core.ValueObjects;
Expand Down Expand Up @@ -87,4 +86,9 @@ public bool Update(string street, string city, string state, string postalCode,

return isUpdated;
}

public override string ToString()
{
return $"{Street}, {City}, {State} {PostalCode}, {Country}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using DevBetterWeb.Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace DevBetterWeb.Infrastructure.Data.Config;

public class MemberAddressHistoryConfig : IEntityTypeConfiguration<MemberAddressHistory>
{
public void Configure(EntityTypeBuilder<MemberAddressHistory> builder)
{
builder.Property(i => i.MemberId).IsRequired();
builder.Property(i => i.UpdatedOn).IsRequired();

builder.OwnsOne(x => x.Address, sa =>
{
sa.Property(p => p!.Street).HasMaxLength(500).HasDefaultValue("");
sa.Property(p => p!.City).HasMaxLength(DataConfigConstants.NAME_COLUMN_WIDTH).HasDefaultValue("");
sa.Property(p => p!.State).HasMaxLength(DataConfigConstants.NAME_COLUMN_WIDTH).HasDefaultValue("");
sa.Property(p => p!.PostalCode).HasMaxLength(12).HasDefaultValue("");
sa.Property(p => p!.Country).HasMaxLength(DataConfigConstants.NAME_COLUMN_WIDTH).HasDefaultValue("");
});
}
}
8 changes: 6 additions & 2 deletions src/DevBetterWeb.Infrastructure/Data/Config/MemberConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class MemberConfig : IEntityTypeConfiguration<Member>
public void Configure(EntityTypeBuilder<Member> builder)
{
builder.Property(x => x.UserId).HasMaxLength(500);
builder.Property(x => x.Address).HasMaxLength(500);
builder.Property(x => x.BlogUrl).HasMaxLength(DataConfigConstants.URL_COLUMN_WIDTH);
builder.Property(x => x.CodinGameUrl).HasMaxLength(DataConfigConstants.URL_COLUMN_WIDTH);
builder.Property(x => x.GitHubUrl).HasMaxLength(DataConfigConstants.URL_COLUMN_WIDTH);
Expand Down Expand Up @@ -49,5 +48,10 @@ public void Configure(EntityTypeBuilder<Member> builder)
});

builder.HasMany(x => x.FavoriteArchiveVideos);
}

builder.HasMany(x => x.AddressHistory)
.WithOne()
.HasForeignKey(ah => ah.MemberId)
.OnDelete(DeleteBehavior.Cascade);
}
}
Loading