Skip to content

Commit

Permalink
removed custom enumeration type in Ordering service (#478)
Browse files Browse the repository at this point in the history
* removed custom enumeration type

* update CardTypeEntityTypeConfiguration.cs to require card type name

* updataed Duende version

* add Duende to list of suppressed assemblies due to current known issue with v7.0.6

* set NU3042 to NoWarn

* revert nowarn change

* update CartType to use required / init-only properties
  • Loading branch information
erinnmclaughlin authored Dec 17, 2024
1 parent 1c77175 commit 633dd1a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 96 deletions.
10 changes: 1 addition & 9 deletions src/Ordering.API/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
global using Asp.Versioning;
global using Asp.Versioning.Conventions;
global using System.Data.Common;
global using Npgsql;
global using Asp.Versioning.Conventions;
global using System.Runtime.Serialization;
global using FluentValidation;
global using MediatR;
Expand All @@ -10,9 +7,7 @@
global using eShop.EventBus.Abstractions;
global using eShop.EventBus.Events;
global using eShop.EventBus.Extensions;
global using eShop.IntegrationEventLogEF;
global using eShop.IntegrationEventLogEF.Services;
global using eShop.Ordering.API;
global using eShop.Ordering.API.Application.Behaviors;
global using eShop.Ordering.API.Application.Commands;
global using eShop.Ordering.API.Application.IntegrationEvents;
Expand All @@ -32,7 +27,4 @@
global using eShop.Ordering.Infrastructure;
global using eShop.Ordering.Infrastructure.Idempotency;
global using eShop.Ordering.Infrastructure.Repositories;
global using Microsoft.Extensions.Options;
global using Polly;
global using Polly.Retry;
global using eShop.ServiceDefaults;
5 changes: 3 additions & 2 deletions src/Ordering.API/Infrastructure/OrderingContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class OrderingContextSeed: IDbSeeder<OrderingContext>
{
public async Task SeedAsync(OrderingContext context)
{

if (!context.CardTypes.Any())
{
context.CardTypes.AddRange(GetPredefinedCardTypes());
Expand All @@ -19,6 +18,8 @@ public async Task SeedAsync(OrderingContext context)

private static IEnumerable<CardType> GetPredefinedCardTypes()
{
return Enumeration.GetAll<CardType>();
yield return new CardType { Id = 1, Name = "Amex" };
yield return new CardType { Id = 2, Name = "Visa" };
yield return new CardType { Id = 3, Name = "MasterCard" };
}
}
21 changes: 4 additions & 17 deletions src/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
using eShop.Ordering.Domain.SeedWork;
namespace eShop.Ordering.Domain.AggregatesModel.BuyerAggregate;

namespace eShop.Ordering.Domain.AggregatesModel.BuyerAggregate;

/// <remarks>
/// Card type class should be marked as abstract with protected constructor to encapsulate known enum types
/// this is currently not possible as OrderingContextSeed uses this constructor to load cardTypes from csv file
/// </remarks>
public class CardType
: Enumeration
public sealed class CardType
{
public static CardType Amex = new(1, nameof(Amex));
public static CardType Visa = new(2, nameof(Visa));
public static CardType MasterCard = new(3, nameof(MasterCard));

public CardType(int id, string name)
: base(id, name)
{
}
public int Id { get; init; }
public required string Name { get; init; }
}
67 changes: 0 additions & 67 deletions src/Ordering.Domain/SeedWork/Enumeration.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public void Configure(EntityTypeBuilder<CardType> cardTypesConfiguration)
.ValueGeneratedNever();

cardTypesConfiguration.Property(ct => ct.Name)
.HasMaxLength(200);
.HasMaxLength(200)
.IsRequired();
}
}

0 comments on commit 633dd1a

Please sign in to comment.