From a9b12dffa9da458b1a05a79a88f852ef4fe4805e Mon Sep 17 00:00:00 2001 From: Jason Regnier Date: Sun, 29 Nov 2020 01:03:16 -0500 Subject: [PATCH] Refactored models to only be read-only through abstraction with an interface --- README.md | 2 +- src/MtgApiManager.Lib.Test/Model/CardTest.cs | 2 +- .../MainViewModel.cs | 26 +- src/MtgApiManager.Lib/Model/Card/Card.cs | 336 +++++++----------- .../Model/Card/ForeignName.cs | 24 +- src/MtgApiManager.Lib/Model/Card/ICard.cs | 216 +++++++++++ .../Model/Card/IForeignName.cs | 23 ++ src/MtgApiManager.Lib/Model/Card/ILegality.cs | 18 + src/MtgApiManager.Lib/Model/Card/IRuling.cs | 18 + src/MtgApiManager.Lib/Model/Card/Legality.cs | 14 +- src/MtgApiManager.Lib/Model/Card/Ruling.cs | 14 +- src/MtgApiManager.Lib/Model/IModelMapper.cs | 10 +- src/MtgApiManager.Lib/Model/ISet.cs | 70 ++++ src/MtgApiManager.Lib/Model/ModelMapper.cs | 14 +- src/MtgApiManager.Lib/Model/Set.cs | 74 ++-- .../MtgApiManager.Lib.csproj | 6 +- src/MtgApiManager.Lib/MtgApiManager.Lib.xml | 335 +++++++++++++---- src/MtgApiManager.Lib/Service/CardService.cs | 21 +- src/MtgApiManager.Lib/Service/ICardService.cs | 10 +- src/MtgApiManager.Lib/Service/ISetService.cs | 6 +- src/MtgApiManager.Lib/Service/SetService.cs | 24 +- 21 files changed, 843 insertions(+), 420 deletions(-) create mode 100644 src/MtgApiManager.Lib/Model/Card/ICard.cs create mode 100644 src/MtgApiManager.Lib/Model/Card/IForeignName.cs create mode 100644 src/MtgApiManager.Lib/Model/Card/ILegality.cs create mode 100644 src/MtgApiManager.Lib/Model/Card/IRuling.cs create mode 100644 src/MtgApiManager.Lib/Model/ISet.cs diff --git a/README.md b/README.md index 5fa6ea6..87d2a25 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ IMtgServiceProvider serviceProvider = new MtgServiceProvider(); The result of all service calls resturns a generic **Exception Monad** containing the results of the call. ```cs CardService service = serviceProvider.GetCardService(); -Exceptional> result = service.AllAsync(); +Exceptional> result = service.AllAsync(); if (result.IsSuccess) { var value = result.Value; diff --git a/src/MtgApiManager.Lib.Test/Model/CardTest.cs b/src/MtgApiManager.Lib.Test/Model/CardTest.cs index 09f5a00..4d374eb 100644 --- a/src/MtgApiManager.Lib.Test/Model/CardTest.cs +++ b/src/MtgApiManager.Lib.Test/Model/CardTest.cs @@ -62,7 +62,7 @@ public void MapCardTest() Watermark = "watermark" }; - Card model = _modelMapper.MapCard(dto); + var model = _modelMapper.MapCard(dto); Assert.Equal(dto.Artist, model.Artist); Assert.Equal(dto.Border, model.Border); diff --git a/src/MtgApiManager.Lib.TestApp/MainViewModel.cs b/src/MtgApiManager.Lib.TestApp/MainViewModel.cs index 1973621..b5e6150 100644 --- a/src/MtgApiManager.Lib.TestApp/MainViewModel.cs +++ b/src/MtgApiManager.Lib.TestApp/MainViewModel.cs @@ -9,22 +9,22 @@ namespace MtgApiManager.Lib.TestApp public class MainViewModel : ViewModelBase { private readonly IMtgServiceProvider _serviceProvider; - private ObservableCollection _cardsCollection = null; + private ObservableCollection _cardsCollection = null; private RelayCommand _cardSearchCommand; private string _cardSearchString = null; private RelayCommand _findSelectedCardCommand; private RelayCommand _findSelectedSetCommand; private RelayCommand _generateBoosterCommand; - private ObservableCollection _generatedBoosterCollection = null; + private ObservableCollection _generatedBoosterCollection = null; private RelayCommand _getCardSubTypesCommand; private RelayCommand _getCardSuperTypesCommand; private RelayCommand _getCardTypesCommand; private bool _isLoading = false; - private Card _selectedCard = null; + private ICard _selectedCard = null; private string _selectedCardId = null; - private Set _selectedSet = null; + private ISet _selectedSet = null; private string _selectedSetCode = null; - private ObservableCollection _setsCollection = null; + private ObservableCollection _setsCollection = null; private RelayCommand _setSearchCommand; private string _setSearchString = null; @@ -32,12 +32,12 @@ public class MainViewModel : ViewModelBase public MainViewModel() { - _cardsCollection = new ObservableCollection(); - _setsCollection = new ObservableCollection(); + _cardsCollection = new ObservableCollection(); + _setsCollection = new ObservableCollection(); _serviceProvider = new MtgServiceProvider(); } - public ObservableCollection CardsCollection + public ObservableCollection CardsCollection { get => _cardsCollection; set => Set(() => CardsCollection, ref _cardsCollection, value); @@ -143,7 +143,7 @@ public RelayCommand GenerateBoosterCommand if (result.IsSuccess) { - GeneratedBoosterCollection = new ObservableCollection(result.Value); + GeneratedBoosterCollection = new ObservableCollection(result.Value); } IsLoading = false; @@ -152,7 +152,7 @@ public RelayCommand GenerateBoosterCommand } } - public ObservableCollection GeneratedBoosterCollection + public ObservableCollection GeneratedBoosterCollection { get => _generatedBoosterCollection; set => Set(() => GeneratedBoosterCollection, ref _generatedBoosterCollection, value); @@ -230,7 +230,7 @@ public bool IsLoading set => Set(() => IsLoading, ref _isLoading, value); } - public Card SelectedCard + public ICard SelectedCard { get => _selectedCard; set => Set(() => SelectedCard, ref _selectedCard, value); @@ -242,7 +242,7 @@ public string SelectedCardId set => Set(() => SelectedCardId, ref _selectedCardId, value); } - public Set SelectedSet + public ISet SelectedSet { get => _selectedSet; set => Set(() => SelectedSet, ref _selectedSet, value); @@ -254,7 +254,7 @@ public string SelectedSetCode set => Set(() => SelectedSetCode, ref _selectedSetCode, value); } - public ObservableCollection SetsCollection + public ObservableCollection SetsCollection { get => _setsCollection; set => Set(() => SetsCollection, ref _setsCollection, value); diff --git a/src/MtgApiManager.Lib/Model/Card/Card.cs b/src/MtgApiManager.Lib/Model/Card/Card.cs index 68cecb9..4502848 100644 --- a/src/MtgApiManager.Lib/Model/Card/Card.cs +++ b/src/MtgApiManager.Lib/Model/Card/Card.cs @@ -1,216 +1,132 @@ -namespace MtgApiManager.Lib.Model -{ - using System; - using System.Collections.Generic; +using System; +using System.Collections.Generic; - /// - /// Object representing a MTG card. - /// - public class Card +namespace MtgApiManager.Lib.Model +{ + /// + internal class Card : ICard { - /// - /// Gets the artist of the card. - /// - public string Artist { get; init; } - - /// - /// Gets the border of the card. If the border for this specific card is DIFFERENT than the border specified in the top level set JSON, then it will be specified here. (Example: Unglued has silver borders, except for the lands which are black bordered) - /// - public string Border { get; init; } - - /// - /// Gets the converted Mana cost. - /// - public float? Cmc { get; init; } - - /// - /// Gets the card colors by color code. [“Red”, “Blue”] becomes [“R”, “U”] - /// - public string[] ColorIdentity { get; init; } - - /// - /// Gets the card colors. Usually this is derived from the casting cost, but some cards are special (like the back of dual sided cards and Ghostfire). - /// - public string[] Colors { get; init; } - - /// - /// Gets the flavor text of the card. - /// - public string Flavor { get; init; } - - /// - /// Gets the foreign language names for the card, if this card in this set was printed in another language. Not available for all sets. - /// - public List ForeignNames { get; init; } - - /// - /// Gets the maximum hand size modifier. Only exists for Vanguard cards. - /// - public int? Hand { get; init; } - - /// - /// Gets the identifier of the card. - /// - public string Id { get; init; } - - /// - /// Gets the image URL for a card. Only exists if the card has a multiverse id. - /// - public Uri ImageUrl { get; init; } - - /// - /// Gets a value indicating whether the card has more than a single color. - /// + /// + public string Artist { get; set; } + + /// + public string Border { get; set; } + + /// + public float? Cmc { get; set; } + + /// + public string[] ColorIdentity { get; set; } + + /// + public string[] Colors { get; set; } + + /// + public string Flavor { get; set; } + + /// + public List ForeignNames { get; set; } + + /// + public int? Hand { get; set; } + + /// + public string Id { get; set; } + + /// + public Uri ImageUrl { get; set; } + + /// public bool IsMultiColor => Colors?.Length > 1; - /// - /// Gets the card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard - /// - public string Layout { get; init; } - - /// - /// Gets which formats this card is legal, restricted or banned - /// - public List Legalities { get; init; } - - /// - /// Gets the starting life total modifier. Only exists for Vanguard cards. - /// - public int? Life { get; init; } - - /// - /// Gets the loyalty of the card. This is only present for planeswalkers. - /// - public string Loyalty { get; init; } - - /// - /// Gets the mana cost of this card. Consists of one or more Mana symbols. - /// - public string ManaCost { get; init; } - - /// - /// Gets the multiverse identifier of the card on Wizard’s Gatherer web page. Cards from sets that do not exist on Gatherer will NOT have a multiverse identifier. Sets not on Gatherer are: ATH, ITP, DKM, RQS, DPA and all sets with a 4 letter code that starts with a lowercase 'p’. - /// - public int? MultiverseId { get; init; } - - /// - /// Gets the card name. For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record. - /// - public string Name { get; init; } - - /// - /// Gets the names of the card. Only used for split, flip and dual cards. Will contain all the names on this card, front or back. - /// - public string[] Names { get; init; } - - /// - /// Gets the card number. This is printed at the bottom-center of the card in small text.. - /// - public string Number { get; init; } - - /// - /// Gets the original text on the card at the time it was printed. This field is not available for promo cards. - /// - public string OriginalText { get; init; } - - /// - /// Gets the original type on the card at the time it was printed. This field is not available for promo cards. - /// - public string OriginalType { get; init; } - - /// - /// Gets the power of the card. This is only present for creatures. - /// - public string Power { get; init; } - - /// - /// Gets the sets that this card was printed in, expressed as an array of set codes. - /// - public string[] Printings { get; init; } - - /// - /// Gets the rarity of the card. Examples: Common, Uncommon, Rare, Mythic Rare, Special, Basic Land - /// - public string Rarity { get; init; } - - /// - /// Gets the date this card was released. This is only set for promo cards. The date may not be accurate to an exact day and month, thus only a partial date may be set (YYYY-MM-DD or YYYY-MM or YYYY). Some promo cards do not have a known release date. - /// - public string ReleaseDate { get; init; } - - /// - /// Gets a value indicating whether this card is reserved by Wizards Official Reprint Policy. - /// - public bool? Reserved { get; init; } - - /// - /// Gets the rulings for the card. - /// - public List Rulings { get; init; } - - /// - /// Gets the set the card belongs to (set code). - /// - public string Set { get; init; } - - /// - /// Gets the set the card belongs to. - /// - public string SetName { get; init; } - - /// - /// Gets where this card was originally obtained for promo cards. For box sets that are theme decks, this is which theme deck the card is from. - /// - public string Source { get; init; } - - /// - /// Gets a value indicating whether this card was only released as part of a core box set. These are technically part of the core sets and are tournament legal despite not being available in boosters. - /// - public bool? Starter { get; init; } - - /// - /// Gets the he subtypes of the card. These appear to the right of the dash in a card type. Usually each word is its own subtype. Example values: Trap, Arcane, Equipment, Aura, Human, Rat, Squirrel, etc. - /// - public string[] SubTypes { get; init; } - - /// - /// Gets the super types of the card. These appear to the far left of the card type. Example values: Basic, Legendary, Snow, World, Ongoing - /// - public string[] SuperTypes { get; init; } - - /// - /// Gets the oracle text of the card. May contain mana symbols and other symbols. - /// - public string Text { get; init; } - - /// - /// Gets the a value indicating whether this card was a time shifted card in the set. - /// - public bool? Timeshifted { get; init; } - - /// - /// Gets the toughness of the card. This is only present for creatures. - /// - public string Toughness { get; init; } - - /// - /// Gets the card type. This is the type you would see on the card if printed today. Note: The dash is a UTF8 'long dash’ as per the MTG rules - /// - public string Type { get; init; } - - /// - /// Gets the types of the card. These appear to the left of the dash in a card type. Example values: Instant, Sorcery, Artifact, Creature, Enchantment, Land, Planeswalker - /// - public string[] Types { get; init; } - - /// - /// Gets if a card has alternate art (for example, 4 different Forests, or the 2 Brothers Yamazaki) then each other variation’s multiverseid will be listed here, NOT including the current card’s multiverseid. - /// - public string[] Variations { get; init; } - - /// - /// Gets the watermark on the card. Note: Split cards don’t currently have this field set, despite having a watermark on each side of the split card. - /// - public string Watermark { get; init; } + /// + public string Layout { get; set; } + + /// + public List Legalities { get; set; } + + /// + public int? Life { get; set; } + + /// + public string Loyalty { get; set; } + + /// + public string ManaCost { get; set; } + + /// + public int? MultiverseId { get; set; } + + /// + public string Name { get; set; } + + /// + public string[] Names { get; set; } + + /// + public string Number { get; set; } + + /// + public string OriginalText { get; set; } + + /// + public string OriginalType { get; set; } + + /// + public string Power { get; set; } + + /// + public string[] Printings { get; set; } + + /// + public string Rarity { get; set; } + + /// + public string ReleaseDate { get; set; } + + /// + public bool? Reserved { get; set; } + + /// + public List Rulings { get; set; } + + /// + public string Set { get; set; } + + /// + public string SetName { get; set; } + + /// + public string Source { get; set; } + + /// + public bool? Starter { get; set; } + + /// + public string[] SubTypes { get; set; } + + /// + public string[] SuperTypes { get; set; } + + /// + public string Text { get; set; } + + /// + public bool? Timeshifted { get; set; } + + /// + public string Toughness { get; set; } + + /// + public string Type { get; set; } + + /// + public string[] Types { get; set; } + + /// + public string[] Variations { get; set; } + + /// + public string Watermark { get; set; } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/ForeignName.cs b/src/MtgApiManager.Lib/Model/Card/ForeignName.cs index 1cd30d2..3ecde29 100644 --- a/src/MtgApiManager.Lib/Model/Card/ForeignName.cs +++ b/src/MtgApiManager.Lib/Model/Card/ForeignName.cs @@ -1,23 +1,15 @@ namespace MtgApiManager.Lib.Model { - /// - /// Object representing a foreign name for an MTG card. - /// - public class ForeignName + /// + public class ForeignName : IForeignName { - /// - /// Gets the language it was printed in. - /// - public string Language { get; init; } + /// + public string Language { get; set; } - /// - /// Gets the multiverse identifier of the card for the foreign name. - /// - public int? MultiverseId { get; init; } + /// + public int? MultiverseId { get; set; } - /// - /// Gets the name of the card in the foreign language. - /// - public string Name { get; init; } + /// + public string Name { get; set; } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/ICard.cs b/src/MtgApiManager.Lib/Model/Card/ICard.cs new file mode 100644 index 0000000..7a11e17 --- /dev/null +++ b/src/MtgApiManager.Lib/Model/Card/ICard.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections.Generic; + +namespace MtgApiManager.Lib.Model +{ + /// + /// Object representing a MTG card. + /// + public interface ICard + { + /// + /// Gets the artist of the card. + /// + string Artist { get; set; } + + /// + /// Gets the border of the card. If the border for this specific card is DIFFERENT than the border specified in the top level set JSON, then it will be specified here. (Example: Unglued has silver borders, except for the lands which are black bordered) + /// + string Border { get; set; } + + /// + /// Gets the converted Mana cost. + /// + float? Cmc { get; set; } + + /// + /// Gets the card colors by color code. [“Red”, “Blue”] becomes [“R”, “U”] + /// + string[] ColorIdentity { get; set; } + + /// + /// Gets the card colors. Usually this is derived from the casting cost, but some cards are special (like the back of dual sided cards and Ghostfire). + /// + string[] Colors { get; set; } + + /// + /// Gets the flavor text of the card. + /// + string Flavor { get; set; } + + /// + /// Gets the foreign language names for the card, if this card in this set was printed in another language. Not available for all sets. + /// + List ForeignNames { get; set; } + + /// + /// Gets the maximum hand size modifier. Only exists for Vanguard cards. + /// + int? Hand { get; set; } + + /// + /// Gets the identifier of the card. + /// + string Id { get; set; } + + /// + /// Gets the image URL for a card. Only exists if the card has a multiverse id. + /// + Uri ImageUrl { get; set; } + + /// + /// Gets a value indicating whether the card has more than a single color. + /// + bool IsMultiColor => Colors?.Length > 1; + + /// + /// Gets the card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard + /// + string Layout { get; set; } + + /// + /// Gets which formats this card is legal, restricted or banned + /// + List Legalities { get; set; } + + /// + /// Gets the starting life total modifier. Only exists for Vanguard cards. + /// + int? Life { get; set; } + + /// + /// Gets the loyalty of the card. This is only present for planeswalkers. + /// + string Loyalty { get; set; } + + /// + /// Gets the mana cost of this card. Consists of one or more Mana symbols. + /// + string ManaCost { get; set; } + + /// + /// Gets the multiverse identifier of the card on Wizard’s Gatherer web page. Cards from sets that do not exist on Gatherer will NOT have a multiverse identifier. Sets not on Gatherer are: ATH, ITP, DKM, RQS, DPA and all sets with a 4 letter code that starts with a lowercase 'p’. + /// + int? MultiverseId { get; set; } + + /// + /// Gets the card name. For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record. + /// + string Name { get; set; } + + /// + /// Gets the names of the card. Only used for split, flip and dual cards. Will contain all the names on this card, front or back. + /// + string[] Names { get; set; } + + /// + /// Gets the card number. This is printed at the bottom-center of the card in small text.. + /// + string Number { get; set; } + + /// + /// Gets the original text on the card at the time it was printed. This field is not available for promo cards. + /// + string OriginalText { get; set; } + + /// + /// Gets the original type on the card at the time it was printed. This field is not available for promo cards. + /// + string OriginalType { get; set; } + + /// + /// Gets the power of the card. This is only present for creatures. + /// + string Power { get; set; } + + /// + /// Gets the sets that this card was printed in, expressed as an array of set codes. + /// + string[] Printings { get; set; } + + /// + /// Gets the rarity of the card. Examples: Common, Uncommon, Rare, Mythic Rare, Special, Basic Land + /// + string Rarity { get; set; } + + /// + /// Gets the date this card was released. This is only set for promo cards. The date may not be accurate to an exact day and month, thus only a partial date may be set (YYYY-MM-DD or YYYY-MM or YYYY). Some promo cards do not have a known release date. + /// + string ReleaseDate { get; set; } + + /// + /// Gets a value indicating whether this card is reserved by Wizards Official Reprint Policy. + /// + bool? Reserved { get; set; } + + /// + /// Gets the rulings for the card. + /// + List Rulings { get; set; } + + /// + /// Gets the set the card belongs to (set code). + /// + string Set { get; set; } + + /// + /// Gets the set the card belongs to. + /// + string SetName { get; set; } + + /// + /// Gets where this card was originally obtained for promo cards. For box sets that are theme decks, this is which theme deck the card is from. + /// + string Source { get; set; } + + /// + /// Gets a value indicating whether this card was only released as part of a core box set. These are technically part of the core sets and are tournament legal despite not being available in boosters. + /// + bool? Starter { get; set; } + + /// + /// Gets the he subtypes of the card. These appear to the right of the dash in a card type. Usually each word is its own subtype. Example values: Trap, Arcane, Equipment, Aura, Human, Rat, Squirrel, etc. + /// + string[] SubTypes { get; set; } + + /// + /// Gets the super types of the card. These appear to the far left of the card type. Example values: Basic, Legendary, Snow, World, Ongoing + /// + string[] SuperTypes { get; set; } + + /// + /// Gets the oracle text of the card. May contain mana symbols and other symbols. + /// + string Text { get; set; } + + /// + /// Gets the a value indicating whether this card was a time shifted card in the set. + /// + bool? Timeshifted { get; set; } + + /// + /// Gets the toughness of the card. This is only present for creatures. + /// + string Toughness { get; set; } + + /// + /// Gets the card type. This is the type you would see on the card if printed today. Note: The dash is a UTF8 'long dash’ as per the MTG rules + /// + string Type { get; set; } + + /// + /// Gets the types of the card. These appear to the left of the dash in a card type. Example values: Instant, Sorcery, Artifact, Creature, Enchantment, Land, Planeswalker + /// + string[] Types { get; set; } + + /// + /// Gets if a card has alternate art (for example, 4 different Forests, or the 2 Brothers Yamazaki) then each other variation’s multiverseid will be listed here, NOT including the current card’s multiverseid. + /// + string[] Variations { get; set; } + + /// + /// Gets the watermark on the card. Note: Split cards don’t currently have this field set, despite having a watermark on each side of the split card. + /// + string Watermark { get; set; } + } +} \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/IForeignName.cs b/src/MtgApiManager.Lib/Model/Card/IForeignName.cs new file mode 100644 index 0000000..f7d1567 --- /dev/null +++ b/src/MtgApiManager.Lib/Model/Card/IForeignName.cs @@ -0,0 +1,23 @@ +namespace MtgApiManager.Lib.Model +{ + /// + /// Object representing a foreign name for an MTG card. + /// + public interface IForeignName + { + /// + /// Gets the language it was printed in. + /// + string Language { get; } + + /// + /// Gets the multiverse identifier of the card for the foreign name. + /// + int? MultiverseId { get; } + + /// + /// Gets the name of the card in the foreign language. + /// + string Name { get; } + } +} \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/ILegality.cs b/src/MtgApiManager.Lib/Model/Card/ILegality.cs new file mode 100644 index 0000000..3c8c0b2 --- /dev/null +++ b/src/MtgApiManager.Lib/Model/Card/ILegality.cs @@ -0,0 +1,18 @@ +namespace MtgApiManager.Lib.Model +{ + /// + /// Object representing the legality of a card. + /// + public interface ILegality + { + /// + /// Gets or sets the format of the legality. + /// + string Format { get; } + + /// + /// Gets or sets the name of the legality. + /// + string LegalityName { get; } + } +} \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/IRuling.cs b/src/MtgApiManager.Lib/Model/Card/IRuling.cs new file mode 100644 index 0000000..79864d4 --- /dev/null +++ b/src/MtgApiManager.Lib/Model/Card/IRuling.cs @@ -0,0 +1,18 @@ +namespace MtgApiManager.Lib.Model +{ + /// + /// Object representing a ruling for a card. + /// + public interface IRuling + { + /// + /// Gets or sets the date of the ruling. + /// + public string Date { get; } + + /// + /// Gets or sets the text of the ruling. + /// + public string Text { get; } + } +} \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/Legality.cs b/src/MtgApiManager.Lib/Model/Card/Legality.cs index 4d8008b..61bd324 100644 --- a/src/MtgApiManager.Lib/Model/Card/Legality.cs +++ b/src/MtgApiManager.Lib/Model/Card/Legality.cs @@ -3,16 +3,12 @@ /// /// Object representing the legality of a card. /// - public class Legality + internal class Legality : ILegality { - /// - /// Gets or sets the format of the legality. - /// - public string Format { get; init; } + /// + public string Format { get; set; } - /// - /// Gets or sets the name of the legality. - /// - public string LegalityName { get; init; } + /// + public string LegalityName { get; set; } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/Card/Ruling.cs b/src/MtgApiManager.Lib/Model/Card/Ruling.cs index aeee0cc..2061a91 100644 --- a/src/MtgApiManager.Lib/Model/Card/Ruling.cs +++ b/src/MtgApiManager.Lib/Model/Card/Ruling.cs @@ -3,16 +3,12 @@ /// /// Object representing a ruling for a card. /// - public class Ruling + internal class Ruling : IRuling { - /// - /// Gets or sets the date of the ruling. - /// - public string Date { get; init; } + /// + public string Date { get; set; } - /// - /// Gets or sets the text of the ruling. - /// - public string Text { get; init; } + /// + public string Text { get; set; } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/IModelMapper.cs b/src/MtgApiManager.Lib/Model/IModelMapper.cs index 65b89d5..cdb11cb 100644 --- a/src/MtgApiManager.Lib/Model/IModelMapper.cs +++ b/src/MtgApiManager.Lib/Model/IModelMapper.cs @@ -4,14 +4,14 @@ namespace MtgApiManager.Lib.Model { internal interface IModelMapper { - Card MapCard(CardDto cardDto); + ICard MapCard(CardDto cardDto); - Set MapSet(SetDto setDto); + IForeignName MapForeignName(ForeignNameDto foreignNameDto); - ForeignName MapForeignName(ForeignNameDto foreignNameDto); + ILegality MapLegality(LegalityDto legalityDto); - Legality MapLegality(LegalityDto legalityDto); + IRuling MapRuling(RulingDto rulingDto); - Ruling MapRuling(RulingDto rulingDto); + ISet MapSet(SetDto setDto); } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/ISet.cs b/src/MtgApiManager.Lib/Model/ISet.cs new file mode 100644 index 0000000..9f4033e --- /dev/null +++ b/src/MtgApiManager.Lib/Model/ISet.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; + +namespace MtgApiManager.Lib.Model +{ + /// + /// Object representing a MTG Set. + /// + public interface ISet + { + /// + /// Gets the block the set is in. + /// + string Block { get; } + + /// + /// Gets the booster contents for this set. + /// + List Booster { get; } + + /// + /// Gets the type of border on the cards, either “white”, “black” or “silver”. + /// + string Border { get; } + + /// + /// Gets the code name of the set. + /// + string Code { get; } + + /// + /// Gets the type of set. One of: “core”, “expansion”, “reprint”, “box”, “un”, “from the vault”, “premium deck”, “duel deck”, “starter”, “commander”, “planechase”, “archenemy”, “promo”, “vanguard”, “masters”. + /// + string Expansion { get; } + + /// + /// Gets the code that Gatherer uses for the set. Only present if different than . + /// + string GathererCode { get; } + + /// + /// Gets the code that magiccards.info uses for the set. Only present if magiccards.info has this set. + /// + string MagicCardsInfoCode { get; } + + /// + /// Gets the name of the set. + /// + string Name { get; } + + /// + /// Gets an old style code used by some Magic software. Only present if different than and . + /// + string OldCode { get; } + + /// + /// Gets a value indicating whether the set was only released on line. + /// + bool? OnlineOnly { get; } + + /// + /// Gets when the set was released. For promo sets, the date the first card was released. + /// + string ReleaseDate { get; } + + /// + /// Gets the set type. + /// + string Type { get; } + } +} \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Model/ModelMapper.cs b/src/MtgApiManager.Lib/Model/ModelMapper.cs index 6835ddc..71bb4e1 100644 --- a/src/MtgApiManager.Lib/Model/ModelMapper.cs +++ b/src/MtgApiManager.Lib/Model/ModelMapper.cs @@ -8,7 +8,7 @@ namespace MtgApiManager.Lib.Model { internal class ModelMapper : IModelMapper { - public Card MapCard(CardDto cardDto) + public ICard MapCard(CardDto cardDto) { if (cardDto == null) { @@ -62,7 +62,7 @@ public Card MapCard(CardDto cardDto) }; } - public ForeignName MapForeignName(ForeignNameDto foreignNameDto) + public IForeignName MapForeignName(ForeignNameDto foreignNameDto) { if (foreignNameDto == null) { @@ -77,7 +77,7 @@ public ForeignName MapForeignName(ForeignNameDto foreignNameDto) }; } - public Legality MapLegality(LegalityDto legalityDto) + public ILegality MapLegality(LegalityDto legalityDto) { if (legalityDto == null) { @@ -91,7 +91,7 @@ public Legality MapLegality(LegalityDto legalityDto) }; } - public Ruling MapRuling(RulingDto rulingDto) + public IRuling MapRuling(RulingDto rulingDto) { if (rulingDto == null) { @@ -105,14 +105,14 @@ public Ruling MapRuling(RulingDto rulingDto) }; } - public Set MapSet(SetDto setDto) + public ISet MapSet(SetDto setDto) { if (setDto == null) { throw new ArgumentNullException(nameof(setDto)); } - List booster = new(); + var booster = new List(); if (setDto.Booster.ValueKind == JsonValueKind.Array) { booster = setDto.Booster @@ -140,7 +140,7 @@ public Set MapSet(SetDto setDto) private static List GetBoosterAsArray(JsonElement jsonElement) { - List items = new(); + var items = new List(); foreach (var item in jsonElement.EnumerateArray()) { if (item.ValueKind == JsonValueKind.String) diff --git a/src/MtgApiManager.Lib/Model/Set.cs b/src/MtgApiManager.Lib/Model/Set.cs index 6402763..60ef038 100644 --- a/src/MtgApiManager.Lib/Model/Set.cs +++ b/src/MtgApiManager.Lib/Model/Set.cs @@ -5,66 +5,42 @@ namespace MtgApiManager.Lib.Model /// /// Object representing a MTG Set. /// - public class Set + internal class Set : ISet { - /// - /// Gets the block the set is in. - /// - public string Block { get; init; } + /// + public string Block { get; set; } - /// - /// Gets the booster contents for this set. - /// - public List Booster { get; init; } + /// + public List Booster { get; set; } - /// - /// Gets the type of border on the cards, either “white”, “black” or “silver”. - /// - public string Border { get; init; } + /// + public string Border { get; set; } - /// - /// Gets the code name of the set. - /// - public string Code { get; init; } + /// + public string Code { get; set; } - /// - /// Gets the type of set. One of: “core”, “expansion”, “reprint”, “box”, “un”, “from the vault”, “premium deck”, “duel deck”, “starter”, “commander”, “planechase”, “archenemy”, “promo”, “vanguard”, “masters”. - /// - public string Expansion { get; init; } + /// + public string Expansion { get; set; } - /// - /// Gets the code that Gatherer uses for the set. Only present if different than . - /// - public string GathererCode { get; init; } + /// + public string GathererCode { get; set; } - /// - /// Gets the code that magiccards.info uses for the set. Only present if magiccards.info has this set. - /// - public string MagicCardsInfoCode { get; init; } + /// + public string MagicCardsInfoCode { get; set; } - /// - /// Gets the name of the set. - /// - public string Name { get; init; } + /// + public string Name { get; set; } - /// - /// Gets an old style code used by some Magic software. Only present if different than and . - /// - public string OldCode { get; init; } + /// + public string OldCode { get; set; } - /// - /// Gets a value indicating whether the set was only released on line. - /// - public bool? OnlineOnly { get; init; } + /// + public bool? OnlineOnly { get; set; } - /// - /// Gets when the set was released. For promo sets, the date the first card was released. - /// - public string ReleaseDate { get; init; } + /// + public string ReleaseDate { get; set; } - /// - /// Gets the set type. - /// - public string Type { get; init; } + /// + public string Type { get; set; } } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/MtgApiManager.Lib.csproj b/src/MtgApiManager.Lib/MtgApiManager.Lib.csproj index 86c803c..9e048f4 100644 --- a/src/MtgApiManager.Lib/MtgApiManager.Lib.csproj +++ b/src/MtgApiManager.Lib/MtgApiManager.Lib.csproj @@ -1,7 +1,7 @@ - net5.0 + netstandard2.1;net5.0 MtgApiManager.Lib Jason Regnier Jason Regnier @@ -60,4 +60,8 @@ + + + + diff --git a/src/MtgApiManager.Lib/MtgApiManager.Lib.xml b/src/MtgApiManager.Lib/MtgApiManager.Lib.xml index 3d7aa63..c696caa 100644 --- a/src/MtgApiManager.Lib/MtgApiManager.Lib.xml +++ b/src/MtgApiManager.Lib/MtgApiManager.Lib.xml @@ -388,330 +388,529 @@ the delay in milliseconds. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Object representing a MTG card. - + Gets the artist of the card. - + Gets the border of the card. If the border for this specific card is DIFFERENT than the border specified in the top level set JSON, then it will be specified here. (Example: Unglued has silver borders, except for the lands which are black bordered) - + Gets the converted Mana cost. - + Gets the card colors by color code. [“Red”, “Blue”] becomes [“R”, “U”] - + Gets the card colors. Usually this is derived from the casting cost, but some cards are special (like the back of dual sided cards and Ghostfire). - + Gets the flavor text of the card. - + Gets the foreign language names for the card, if this card in this set was printed in another language. Not available for all sets. - + Gets the maximum hand size modifier. Only exists for Vanguard cards. - + Gets the identifier of the card. - + Gets the image URL for a card. Only exists if the card has a multiverse id. - + Gets a value indicating whether the card has more than a single color. - + Gets the card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard - + Gets which formats this card is legal, restricted or banned - + Gets the starting life total modifier. Only exists for Vanguard cards. - + Gets the loyalty of the card. This is only present for planeswalkers. - + Gets the mana cost of this card. Consists of one or more Mana symbols. - + Gets the multiverse identifier of the card on Wizard’s Gatherer web page. Cards from sets that do not exist on Gatherer will NOT have a multiverse identifier. Sets not on Gatherer are: ATH, ITP, DKM, RQS, DPA and all sets with a 4 letter code that starts with a lowercase 'p’. - + Gets the card name. For split, double-faced and flip cards, just the name of one side of the card. Basically each ‘sub-card’ has its own record. - + Gets the names of the card. Only used for split, flip and dual cards. Will contain all the names on this card, front or back. - + Gets the card number. This is printed at the bottom-center of the card in small text.. - + Gets the original text on the card at the time it was printed. This field is not available for promo cards. - + Gets the original type on the card at the time it was printed. This field is not available for promo cards. - + Gets the power of the card. This is only present for creatures. - + Gets the sets that this card was printed in, expressed as an array of set codes. - + Gets the rarity of the card. Examples: Common, Uncommon, Rare, Mythic Rare, Special, Basic Land - + Gets the date this card was released. This is only set for promo cards. The date may not be accurate to an exact day and month, thus only a partial date may be set (YYYY-MM-DD or YYYY-MM or YYYY). Some promo cards do not have a known release date. - + Gets a value indicating whether this card is reserved by Wizards Official Reprint Policy. - + Gets the rulings for the card. - + Gets the set the card belongs to (set code). - + Gets the set the card belongs to. - + Gets where this card was originally obtained for promo cards. For box sets that are theme decks, this is which theme deck the card is from. - + Gets a value indicating whether this card was only released as part of a core box set. These are technically part of the core sets and are tournament legal despite not being available in boosters. - + Gets the he subtypes of the card. These appear to the right of the dash in a card type. Usually each word is its own subtype. Example values: Trap, Arcane, Equipment, Aura, Human, Rat, Squirrel, etc. - + Gets the super types of the card. These appear to the far left of the card type. Example values: Basic, Legendary, Snow, World, Ongoing - + Gets the oracle text of the card. May contain mana symbols and other symbols. - + Gets the a value indicating whether this card was a time shifted card in the set. - + Gets the toughness of the card. This is only present for creatures. - + Gets the card type. This is the type you would see on the card if printed today. Note: The dash is a UTF8 'long dash’ as per the MTG rules - + Gets the types of the card. These appear to the left of the dash in a card type. Example values: Instant, Sorcery, Artifact, Creature, Enchantment, Land, Planeswalker - + Gets if a card has alternate art (for example, 4 different Forests, or the 2 Brothers Yamazaki) then each other variation’s multiverseid will be listed here, NOT including the current card’s multiverseid. - + Gets the watermark on the card. Note: Split cards don’t currently have this field set, despite having a watermark on each side of the split card. - + Object representing a foreign name for an MTG card. - + Gets the language it was printed in. - + Gets the multiverse identifier of the card for the foreign name. - + Gets the name of the card in the foreign language. - + Object representing the legality of a card. - + Gets or sets the format of the legality. - + Gets or sets the name of the legality. - + Object representing a ruling for a card. - + Gets or sets the date of the ruling. - + Gets or sets the text of the ruling. - + + + Object representing the legality of a card. + + + + + + + + + + + Object representing a ruling for a card. + + + + + + + + + Object representing a MTG Set. - + Gets the block the set is in. - + Gets the booster contents for this set. - + Gets the type of border on the cards, either “white”, “black” or “silver”. - + Gets the code name of the set. - + Gets the type of set. One of: “core”, “expansion”, “reprint”, “box”, “un”, “from the vault”, “premium deck”, “duel deck”, “starter”, “commander”, “planechase”, “archenemy”, “promo”, “vanguard”, “masters”. - + - Gets the code that Gatherer uses for the set. Only present if different than . + Gets the code that Gatherer uses for the set. Only present if different than . - + Gets the code that magiccards.info uses for the set. Only present if magiccards.info has this set. - + Gets the name of the set. - + - Gets an old style code used by some Magic software. Only present if different than and . + Gets an old style code used by some Magic software. Only present if different than and . - + Gets a value indicating whether the set was only released on line. - + Gets when the set was released. For promo sets, the date the first card was released. - + Gets the set type. + + + Object representing a MTG Set. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A strongly-typed resource class, for looking up localized strings, etc. @@ -892,13 +1091,13 @@ Object representing a MTG card. - + Gets all the defined by the query parameters. - A representing the result containing all the items. + A representing the result containing all the items. diff --git a/src/MtgApiManager.Lib/Service/CardService.cs b/src/MtgApiManager.Lib/Service/CardService.cs index 0d9fab1..0c91097 100644 --- a/src/MtgApiManager.Lib/Service/CardService.cs +++ b/src/MtgApiManager.Lib/Service/CardService.cs @@ -10,7 +10,7 @@ namespace MtgApiManager.Lib.Service { - internal class CardService : ServiceBase, ICardService + internal class CardService : ServiceBase, ICardService { public CardService( IMtgApiServiceAdapter serviceAdapter, @@ -22,37 +22,37 @@ public CardService( } /// - public async override Task>> AllAsync() + public async override Task>> AllAsync() { try { var query = BuildUri(WhereQueries); var rootCardList = await CallWebServiceGet(query).ConfigureAwait(false); - return Exceptional>.Success(MapCardsList(rootCardList), MtgApiController.CreatePagingInfo()); + return Exceptional>.Success(MapCardsList(rootCardList), MtgApiController.CreatePagingInfo()); } catch (Exception ex) { - return Exceptional>.Failure(ex); + return Exceptional>.Failure(ex); } } /// - public Task> FindAsync(int multiverseId) => FindAsync(multiverseId.ToString()); + public Task> FindAsync(int multiverseId) => FindAsync(multiverseId.ToString()); /// - public async Task> FindAsync(string id) + public async Task> FindAsync(string id) { try { var rootCard = await CallWebServiceGet(BuildUri(id)).ConfigureAwait(false); var model = ModelMapper.MapCard(rootCard.Card); - return Exceptional.Success(model, MtgApiController.CreatePagingInfo()); + return Exceptional.Success(model, MtgApiController.CreatePagingInfo()); } catch (Exception ex) { - return Exceptional.Failure(ex); + return Exceptional.Failure(ex); } } @@ -104,7 +104,6 @@ public async Task>> GetCardTypesAsync() } } - /// public ICardService Where(Expression> property, U value) { @@ -134,7 +133,7 @@ public ICardService Where(Expression> property, U return this; } - private List MapCardsList(RootCardListDto cardListDto) + private List MapCardsList(RootCardListDto cardListDto) { if (cardListDto == null) { @@ -143,7 +142,7 @@ private List MapCardsList(RootCardListDto cardListDto) if (cardListDto.Cards == null) { - return new(); + return new List(); } return cardListDto.Cards diff --git a/src/MtgApiManager.Lib/Service/ICardService.cs b/src/MtgApiManager.Lib/Service/ICardService.cs index 85426f0..f32b5c2 100644 --- a/src/MtgApiManager.Lib/Service/ICardService.cs +++ b/src/MtgApiManager.Lib/Service/ICardService.cs @@ -7,28 +7,28 @@ namespace MtgApiManager.Lib.Service { /// /// Object representing a MTG card. - /// + /// public interface ICardService : IMtgQueryable { /// /// Gets all the defined by the query parameters. /// - /// A representing the result containing all the items. - Task>> AllAsync(); + /// A representing the result containing all the items. + Task>> AllAsync(); /// /// Find a specific card by its multi verse identifier. /// /// The multi verse identifier to query for. /// A representing the result containing a or an exception. - Task> FindAsync(int multiverseId); + Task> FindAsync(int multiverseId); /// /// Find a specific card by its multi verse identifier. /// /// The identifier to query for. /// A representing the result containing a or an exception. - Task> FindAsync(string id); + Task> FindAsync(string id); /// /// Gets a list of all the card sub types. diff --git a/src/MtgApiManager.Lib/Service/ISetService.cs b/src/MtgApiManager.Lib/Service/ISetService.cs index 4f1dc6a..a374d3e 100644 --- a/src/MtgApiManager.Lib/Service/ISetService.cs +++ b/src/MtgApiManager.Lib/Service/ISetService.cs @@ -14,20 +14,20 @@ public interface ISetService : IMtgQueryable /// Gets all the defined by the query parameters. /// /// A representing the result containing all the items. - Task>> AllAsync(); + Task>> AllAsync(); /// /// Find a specific card by its set code. /// /// The set code to query for. /// A representing the result containing a or an exception. - Task> FindAsync(string code); + Task> FindAsync(string code); /// /// Generates a booster pack for a specific set asynchronously. /// /// The set code to generate a booster for. /// A representing the result containing a or an exception. - Task>> GenerateBoosterAsync(string code); + Task>> GenerateBoosterAsync(string code); } } \ No newline at end of file diff --git a/src/MtgApiManager.Lib/Service/SetService.cs b/src/MtgApiManager.Lib/Service/SetService.cs index 798d1a3..755973b 100644 --- a/src/MtgApiManager.Lib/Service/SetService.cs +++ b/src/MtgApiManager.Lib/Service/SetService.cs @@ -12,7 +12,7 @@ namespace MtgApiManager.Lib.Service { - internal class SetService : ServiceBase, ISetService + internal class SetService : ServiceBase, ISetService { public SetService( IMtgApiServiceAdapter serviceAdapter, @@ -24,38 +24,38 @@ public SetService( } /// - public async override Task>> AllAsync() + public async override Task>> AllAsync() { try { var query = BuildUri(WhereQueries); var rootSetList = await CallWebServiceGet(query).ConfigureAwait(false); - return Exceptional>.Success(MapSetsList(rootSetList), MtgApiController.CreatePagingInfo()); + return Exceptional>.Success(MapSetsList(rootSetList), MtgApiController.CreatePagingInfo()); } catch (Exception ex) { - return Exceptional>.Failure(ex); + return Exceptional>.Failure(ex); } } /// - public async Task> FindAsync(string code) + public async Task> FindAsync(string code) { try { var rootSet = await CallWebServiceGet(BuildUri(code)).ConfigureAwait(false); var model = ModelMapper.MapSet(rootSet.Set); - return Exceptional.Success(model, MtgApiController.CreatePagingInfo()); + return Exceptional.Success(model, MtgApiController.CreatePagingInfo()); } catch (Exception ex) { - return Exceptional.Failure(ex); + return Exceptional.Failure(ex); } } /// - public async Task>> GenerateBoosterAsync(string code) + public async Task>> GenerateBoosterAsync(string code) { try { @@ -66,11 +66,11 @@ public async Task>> GenerateBoosterAsync(string code) .Select(x => ModelMapper.MapCard(x)) .ToList(); - return Exceptional>.Success(cards, MtgApiController.CreatePagingInfo()); + return Exceptional>.Success(cards, MtgApiController.CreatePagingInfo()); } catch (Exception ex) { - return Exceptional>.Failure(ex); + return Exceptional>.Failure(ex); } } @@ -94,7 +94,7 @@ public ISetService Where(Expression> property, U v return this; } - private List MapSetsList(RootSetListDto setListDto) + private List MapSetsList(RootSetListDto setListDto) { if (setListDto == null) { @@ -103,7 +103,7 @@ private List MapSetsList(RootSetListDto setListDto) if (setListDto.Sets == null) { - return new List(); + return new List(); } return setListDto.Sets