From d7fcc49e723c3b9498458c9e2323a575dd595914 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Thu, 1 Sep 2022 02:14:05 +0200 Subject: [PATCH] (refactor): nullable model properties --- .../Abstractions/Models/RequestModelBase.cs | 10 +- webapi/Core/Enumerations/Errors.cs | 16 +++ .../Abstractions/DataProviderBase.cs | 15 --- webapi/Extensions/IEnumerableExtensions.cs | 14 +++ .../Controllers/BlogItemController.cs | 4 +- .../Controllers/CategoryItemController.cs | 4 +- .../Controllers/ShopCartItemController.cs | 4 +- .../Controllers/ShopItemController.cs | 4 +- .../Controllers/WeatherForecastController.cs | 4 +- .../Abstractions/PostItemRequestModelBase.cs | 16 ++- .../Abstractions/PostItemResponseModelBase.cs | 17 +-- .../Models/Requests/BlogItemRequestModel.cs | 63 ++++++++++ .../Requests/CategoryItemRequestModel.cs | 52 ++++++++ .../Models/Requests/L10n/CategoryL10nModel.cs | 68 ++++++++++ .../Models/Requests/L10n/ImageL10nModel.cs | 57 +++++++++ .../Models/Requests/L10n/PostItemL10nModel.cs | 118 ++++++++++++++++++ .../Requests/PostBlogItemRequestModel.cs | 39 ------ .../Requests/PostCategoryItemRequestModel.cs | 26 ---- .../Requests/PostShopCartItemRequestModel.cs | 26 ---- .../Requests/PostShopItemRequestModel.cs | 60 --------- .../Requests/PutBlogItemRequestModel.cs | 39 ------ .../Requests/PutCategoryItemRequestModel.cs | 25 ---- .../Requests/PutShopCartItemRequestModel.cs | 25 ---- .../Requests/PutShopItemRequestModel.cs | 58 --------- .../Requests/ShopCartItemRequestModel.cs | 46 +++++++ .../Models/Requests/ShopItemRequestModel.cs | 95 ++++++++++++++ ...odel.cs => BlogCategoriesResponseModel.cs} | 4 +- ...eModel.cs => BlogFeaturedResponseModel.cs} | 4 +- ...ponseModel.cs => BlogItemResponseModel.cs} | 6 +- ...onseModel.cs => BlogItemsResponseModel.cs} | 4 +- ...eModel.cs => CategoryItemResponseModel.cs} | 6 +- ...sponseModel.cs => ContentResponseModel.cs} | 4 +- .../{ => Responses}/L10n/CategoryL10nModel.cs | 23 +--- .../{ => Responses}/L10n/ImageL10nModel.cs | 22 +--- .../{ => Responses}/L10n/PostItemL10nModel.cs | 34 +---- ...eModel.cs => ShopCartItemResponseModel.cs} | 6 +- ...ponseModel.cs => ShopItemResponseModel.cs} | 6 +- ...onseModel.cs => ShopItemsResponseModel.cs} | 4 +- ...del.cs => WeatherForecastResponseModel.cs} | 2 +- .../Services/BlogItemService.cs | 20 +-- .../Services/BlogItemsService.cs | 14 +-- .../Services/CategoryItemService.cs | 20 +-- .../Services/CategoryItemsService.cs | 8 +- .../Services/ContentService.cs | 6 +- .../Services/ShopCartItemService.cs | 14 +-- .../Services/ShopCartItemsService.cs | 10 +- .../Services/ShopItemService.cs | 20 +-- .../Services/ShopItemsService.cs | 14 +-- 48 files changed, 663 insertions(+), 493 deletions(-) create mode 100644 webapi/Core/Enumerations/Errors.cs create mode 100644 webapi/Extensions/IEnumerableExtensions.cs create mode 100644 webapi/WeatherForecast/Models/Requests/BlogItemRequestModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/CategoryItemRequestModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/L10n/CategoryL10nModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/L10n/ImageL10nModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PostShopCartItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PostShopItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PutShopCartItemRequestModel.cs delete mode 100644 webapi/WeatherForecast/Models/Requests/PutShopItemRequestModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/ShopCartItemRequestModel.cs create mode 100644 webapi/WeatherForecast/Models/Requests/ShopItemRequestModel.cs rename webapi/WeatherForecast/Models/Responses/{GetBlogCategoriesResponseModel.cs => BlogCategoriesResponseModel.cs} (59%) rename webapi/WeatherForecast/Models/Responses/{GetBlogFeaturedResponseModel.cs => BlogFeaturedResponseModel.cs} (72%) rename webapi/WeatherForecast/Models/Responses/{GetBlogItemResponseModel.cs => BlogItemResponseModel.cs} (72%) rename webapi/WeatherForecast/Models/Responses/{GetBlogItemsResponseModel.cs => BlogItemsResponseModel.cs} (70%) rename webapi/WeatherForecast/Models/Responses/{GetCategoryItemResponseModel.cs => CategoryItemResponseModel.cs} (85%) rename webapi/WeatherForecast/Models/Responses/{GetContentResponseModel.cs => ContentResponseModel.cs} (96%) rename webapi/WeatherForecast/Models/{ => Responses}/L10n/CategoryL10nModel.cs (54%) rename webapi/WeatherForecast/Models/{ => Responses}/L10n/ImageL10nModel.cs (50%) rename webapi/WeatherForecast/Models/{ => Responses}/L10n/PostItemL10nModel.cs (62%) rename webapi/WeatherForecast/Models/Responses/{GetShopCartItemResponseModel.cs => ShopCartItemResponseModel.cs} (88%) rename webapi/WeatherForecast/Models/Responses/{GetShopItemResponseModel.cs => ShopItemResponseModel.cs} (79%) rename webapi/WeatherForecast/Models/Responses/{GetShopItemsResponseModel.cs => ShopItemsResponseModel.cs} (64%) rename webapi/WeatherForecast/Models/Responses/{GetWeatherForecastResponseModel.cs => WeatherForecastResponseModel.cs} (87%) diff --git a/webapi/Core/Abstractions/Models/RequestModelBase.cs b/webapi/Core/Abstractions/Models/RequestModelBase.cs index b539d65..6164b60 100644 --- a/webapi/Core/Abstractions/Models/RequestModelBase.cs +++ b/webapi/Core/Abstractions/Models/RequestModelBase.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; namespace Core.Abstractions.Models { - public abstract class RequestModelBase : ModelBase { + public abstract class RequestModelBase : ModelBase, IValidatableObject { public abstract T ToDomainObject(); + public abstract IEnumerable Validate(ValidationContext validationContext); } } diff --git a/webapi/Core/Enumerations/Errors.cs b/webapi/Core/Enumerations/Errors.cs new file mode 100644 index 0000000..a085767 --- /dev/null +++ b/webapi/Core/Enumerations/Errors.cs @@ -0,0 +1,16 @@ +using Core.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Core.Enumerations { + public class Errors : Enumeration { + public static Errors NullOrWhiteSpace = new(0, "is null or white space"); + public static Errors WrongOrNotManaged = new(1, "is wrong or not managed"); + public static Errors NullOrEmpty = new(2, "is null or empty"); + + private Errors(int id, string displayName) : base(id, displayName) { } + } +} diff --git a/webapi/DataProviders/Abstractions/DataProviderBase.cs b/webapi/DataProviders/Abstractions/DataProviderBase.cs index 0badd6f..c0aca35 100644 --- a/webapi/DataProviders/Abstractions/DataProviderBase.cs +++ b/webapi/DataProviders/Abstractions/DataProviderBase.cs @@ -40,21 +40,6 @@ namespace DataProviders.Abstractions { _sessionService = sessionService; } - /// - /// Testing constructor - /// - /// - /// - public DataProviderBase( - ILogger> logger, - ISessionService sessionService, - List collection - ) { - _logger = logger; - _sessionService = sessionService; - _collection = collection ?? new List(); - } - #region Insert private protected (Guid?, IDomainResult) Insert(T obj, string collectionName) => InsertAsync(obj, collectionName).Result; diff --git a/webapi/Extensions/IEnumerableExtensions.cs b/webapi/Extensions/IEnumerableExtensions.cs new file mode 100644 index 0000000..38bd8bc --- /dev/null +++ b/webapi/Extensions/IEnumerableExtensions.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Extensions { + public static class IEnumerableExtensions { + + public static bool IsNullOrEmpty([NotNullWhen(false)] this IEnumerable? list) => + list == null || (list != null && !list.Any()); + } +} diff --git a/webapi/WeatherForecast/Controllers/BlogItemController.cs b/webapi/WeatherForecast/Controllers/BlogItemController.cs index 60f58e0..d3c58d0 100644 --- a/webapi/WeatherForecast/Controllers/BlogItemController.cs +++ b/webapi/WeatherForecast/Controllers/BlogItemController.cs @@ -40,7 +40,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPost("{siteId}")] - public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostBlogItemRequestModel requestData) { + public IActionResult Post([FromRoute] Guid siteId, [FromBody] BlogItemRequestModel requestData) { var result = _blogItemService.Post(siteId, requestData); return result.ToActionResult(); } @@ -75,7 +75,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPut("{siteId}/{blogId}")] - public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] PutBlogItemRequestModel requestData) { + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] BlogItemRequestModel requestData) { var result = _blogItemService.Update(siteId, blogId, requestData); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/CategoryItemController.cs b/webapi/WeatherForecast/Controllers/CategoryItemController.cs index 758dd23..17b2e33 100644 --- a/webapi/WeatherForecast/Controllers/CategoryItemController.cs +++ b/webapi/WeatherForecast/Controllers/CategoryItemController.cs @@ -38,7 +38,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPost("{siteId}")] - public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostCategoryItemRequestModel requestData) { + public IActionResult Post([FromRoute] Guid siteId, [FromBody] CategoryItemRequestModel requestData) { var result = _categoryItemService.Post(siteId, requestData); return result.ToActionResult(); } @@ -75,7 +75,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPut("{siteId}/{categoryId}")] - public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid categoryId, [FromBody] PutCategoryItemRequestModel requestData) { + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid categoryId, [FromBody] CategoryItemRequestModel requestData) { var result = _categoryItemService.Update(siteId, categoryId, requestData); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/ShopCartItemController.cs b/webapi/WeatherForecast/Controllers/ShopCartItemController.cs index 478be43..bbc169c 100644 --- a/webapi/WeatherForecast/Controllers/ShopCartItemController.cs +++ b/webapi/WeatherForecast/Controllers/ShopCartItemController.cs @@ -42,7 +42,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPost("{siteId}/{userId}/{sku}")] - public IActionResult Post([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] PostShopCartItemRequestModel requestData) { + public IActionResult Post([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] ShopCartItemRequestModel requestData) { var result = _shopCartItemService.Post(siteId, userId, sku, requestData); return result.ToActionResult(); } @@ -66,7 +66,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPut("{siteId}/{userId}/{sku}")] - public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] PutShopCartItemRequestModel requestData) { + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] ShopCartItemRequestModel requestData) { var result = _shopCartItemService.Update(siteId, userId, sku, requestData); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/ShopItemController.cs b/webapi/WeatherForecast/Controllers/ShopItemController.cs index be3340f..7b4e865 100644 --- a/webapi/WeatherForecast/Controllers/ShopItemController.cs +++ b/webapi/WeatherForecast/Controllers/ShopItemController.cs @@ -40,7 +40,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPost("{siteId}/{sku}")] - public IActionResult Post([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] PostShopItemRequestModel requestData) { + public IActionResult Post([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) { var result = _shopItemService.Post(siteId, sku, requestData); return result.ToActionResult(); } @@ -77,7 +77,7 @@ namespace WeatherForecast.Controllers { /// /// [HttpPut("{siteId}/{sku}")] - public IActionResult Update([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] PutShopItemRequestModel requestData) { + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) { var result = _shopItemService.Update(siteId, sku, requestData); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/WeatherForecastController.cs b/webapi/WeatherForecast/Controllers/WeatherForecastController.cs index 082171e..9b51b2a 100644 --- a/webapi/WeatherForecast/Controllers/WeatherForecastController.cs +++ b/webapi/WeatherForecast/Controllers/WeatherForecastController.cs @@ -30,8 +30,8 @@ public class WeatherForecastController : ControllerBase { /// /// [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() { - return Enumerable.Range(1, 5).Select(index => new GetWeatherForecastResponseModel { + public IEnumerable Get() { + return Enumerable.Range(1, 5).Select(index => new WeatherForecastResponseModel { Date = DateTime.Now.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)] diff --git a/webapi/WeatherForecast/Models/Abstractions/PostItemRequestModelBase.cs b/webapi/WeatherForecast/Models/Abstractions/PostItemRequestModelBase.cs index 74511f7..5b058da 100644 --- a/webapi/WeatherForecast/Models/Abstractions/PostItemRequestModelBase.cs +++ b/webapi/WeatherForecast/Models/Abstractions/PostItemRequestModelBase.cs @@ -1,6 +1,10 @@ using Core.Abstractions.DomainObjects; using Core.Abstractions.Models; -using WeatherForecast.Models.L10n; +using Core.Enumerations; +using Extensions; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using WeatherForecast.Models.Requests.L10n; namespace WeatherForecast.Models.Abstractions { @@ -13,7 +17,7 @@ namespace WeatherForecast.Models.Abstractions { /// /// /// - public List L10n { get; set; } + public List? L10n { get; set; } /// /// @@ -29,5 +33,13 @@ namespace WeatherForecast.Models.Abstractions { /// /// public bool? FamilyFriendly { get; set; } + + /// + /// Base MemberNotNullWhen workaround + /// + /// + /// + [MemberNotNullWhen(false, new[] { nameof(L10n) })] + private protected bool HasValidationErrorsBase(bool hasErrors) => hasErrors; } } diff --git a/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs b/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs index b5f2944..5f7b751 100644 --- a/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs +++ b/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs @@ -2,7 +2,7 @@ using Core.Abstractions.Models; using Core.DomainObjects; using Core.Enumerations; -using WeatherForecast.Models.L10n; +using WeatherForecast.Models.Responses.L10n; namespace WeatherForecast.Models.Abstractions { @@ -73,12 +73,12 @@ namespace WeatherForecast.Models.Abstractions { /// /// /// - public List Images { get; set; } + public List? Images { get; set; } /// /// /// - public AuthorModel Author { get; set; } + public AuthorModel? Author { get; set; } /// /// @@ -88,18 +88,19 @@ namespace WeatherForecast.Models.Abstractions { /// /// /// - public List Tags { get; set; } + public List? Tags { get; set; } /// /// /// - public List Categories { get; set; } + public List? Categories { get; set; } /// /// /// public bool? FamilyFriendly { get; set; } + /// /// /// @@ -107,7 +108,7 @@ namespace WeatherForecast.Models.Abstractions { public PostItemResponseModelBase(PostItemBase postItem) { Id = postItem.Id; SiteId = postItem.SiteId; - // Author = new AuthorModel(postItem.Author); + //Author = new AuthorModel(postItem.Author); Created = postItem.Created; Tags = postItem.Tags; FamilyFriendly = postItem.FamilyFriendly; @@ -121,7 +122,7 @@ namespace WeatherForecast.Models.Abstractions { public PostItemResponseModelBase(PostItemBase postItem, List categories) : this(postItem) { L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList(); Categories = categories.Select(x => new CategoryModel(x)).ToList(); - Images = postItem.Images.Select(x => new ImageModel(x)).ToList(); + Images = postItem.Images?.Select(x => new ImageModel(x)).ToList(); } /// @@ -144,7 +145,7 @@ namespace WeatherForecast.Models.Abstractions { } Categories = categories.Select(x => new CategoryModel(x, locale)).ToList(); - Images = postItem.Images.Select(x => new ImageModel(x, locale)).ToList(); + Images = postItem.Images?.Select(x => new ImageModel(x, locale)).ToList(); } } } diff --git a/webapi/WeatherForecast/Models/Requests/BlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/BlogItemRequestModel.cs new file mode 100644 index 0000000..89f0ff5 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/BlogItemRequestModel.cs @@ -0,0 +1,63 @@ +using Core.DomainObjects.Documents; +using Core.Enumerations; +using Extensions; +using System.ComponentModel.DataAnnotations; +using WeatherForecast.Models.Abstractions; + +namespace WeatherForecast.Models.Requests { + + /// + /// + /// + public class BlogItemRequestModel : PostItemRequestModelBase { + + /// + /// + /// + public uint? ReadTime { get; set; } + + /// + /// + /// + public uint? Likes { get; set; } + + /// + /// + /// + /// + public override BlogItem ToDomainObject() { + if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException(); + + return new BlogItem() { + L10n = L10n.Select(x => x.ToDomainObject()).ToList(), + + // Images + // Author + + Tags = Tags, + Categories = Categories, + FamilyFriendly = FamilyFriendly, + + ReadTime = ReadTime, + Likes = Likes + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate( ValidationContext validationContext) { + if (L10n.IsNullOrEmpty()) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}"); + else { + foreach (var item in L10n) + foreach (var validationResult in item.Validate(validationContext)) + yield return validationResult; + } + } + + private bool HasValidationErrors(BlogItemRequestModel validationContext) => Validate(new ValidationContext(validationContext)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/CategoryItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/CategoryItemRequestModel.cs new file mode 100644 index 0000000..0cbe680 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/CategoryItemRequestModel.cs @@ -0,0 +1,52 @@ +using Core.Abstractions.Models; +using Core.DomainObjects; +using Core.DomainObjects.L10n; +using Core.Enumerations; +using Extensions; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using WeatherForecast.Models.Requests.L10n; + +namespace WeatherForecast.Models.Requests { + + /// + /// + /// + public class CategoryItemRequestModel : RequestModelBase { + + /// + /// + /// + public List? L10n { get; set; } + + /// + /// + /// + /// + public override Category ToDomainObject() { + if (HasValidationErrors()) throw new ValidationException(); + + return new Category() { + L10n = L10n.Select(x => x.ToDomainObject()).ToList() + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (L10n.IsNullOrEmpty()) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}"); + else { + foreach (var item in L10n) + foreach (var validationResult in item.Validate(validationContext)) + yield return validationResult; + } + } + + [MemberNotNullWhen(false, new[] { nameof(L10n) })] + private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/L10n/CategoryL10nModel.cs b/webapi/WeatherForecast/Models/Requests/L10n/CategoryL10nModel.cs new file mode 100644 index 0000000..e6bb2e0 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/L10n/CategoryL10nModel.cs @@ -0,0 +1,68 @@ +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using Core.Abstractions; +using Core.Abstractions.Models; +using Core.DomainObjects.L10n; +using Core.Enumerations; + + +namespace WeatherForecast.Models.Requests.L10n { + + /// + /// + /// + public class CategoryL10nModel : RequestModelBase { + + /// + /// + /// + public string? Locale { get; set; } + + /// + /// + /// + public string? Slug { get; set; } + + /// + /// + /// + public string? Text { get; set; } + + /// + /// + /// + /// + public override CategoryL10n ToDomainObject() { + if (HasValidationErrors()) throw new ValidationException(); + + return new CategoryL10n() { + Locale = Enumeration.FromDisplayName(Locale), + Slug = Slug, + Text = Text + }; + } + + /// + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (string.IsNullOrWhiteSpace(Locale)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + else if (Enumeration.FromDisplayName(Locale) == null) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}"); + + if (string.IsNullOrWhiteSpace(Slug)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(Text)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + } + + // https://www.meziantou.net/csharp-8-nullable-reference-types.htm + [MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Text) })] + private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/L10n/ImageL10nModel.cs b/webapi/WeatherForecast/Models/Requests/L10n/ImageL10nModel.cs new file mode 100644 index 0000000..4ac9a78 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/L10n/ImageL10nModel.cs @@ -0,0 +1,57 @@ +using Core.Abstractions; +using Core.Abstractions.Models; +using Core.DomainObjects.L10n; +using Core.Enumerations; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; + +namespace WeatherForecast.Models.Requests.L10n { + + /// + /// + /// + public class ImageL10nModel : RequestModelBase { + + /// + /// + /// + public string? Locale { get; set; } + + /// + /// + /// + public string? Alt { get; set; } + + /// + /// + /// + /// + public override ImageL10n ToDomainObject() { + if (HasValidationErrors()) throw new ValidationException(); + + return new ImageL10n() { + Locale = Enumeration.FromDisplayName(Locale), + Alt = Alt + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (string.IsNullOrWhiteSpace(Locale)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + else if (Enumeration.FromDisplayName(Locale) == null) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}"); + + if (string.IsNullOrWhiteSpace(Alt)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + } + + [MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Alt) })] + private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs b/webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs new file mode 100644 index 0000000..deca5d9 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs @@ -0,0 +1,118 @@ +using Core.Abstractions; +using Core.Abstractions.Models; +using Core.DomainObjects.L10n; +using Core.Enumerations; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; + +namespace WeatherForecast.Models.Requests.L10n { + + /// + /// + /// + public class PostItemL10nModel : RequestModelBase { + + /// + /// + /// + public string? Locale { get; set; } + + /// + /// + /// + public string? Slug { get; set; } + + /// + /// + /// + public string? Description { get; set; } + + /// + /// + /// + public string? Title { get; set; } + + /// + /// + /// + public string? ShortText { get; set; } + + /// + /// + /// + public string? Text { get; set; } + + /// + /// + /// + public string? PlainText { get; set; } + + /// + /// + /// + public string? ContentType { get; set; } + + /// + /// + /// + public List? Badges { get; set; } + + /// + /// + /// + /// + public override PostItemL10n ToDomainObject() { + if (HasValidationErrors()) throw new ValidationException(); + + return new PostItemL10n() { + Locale = Enumeration.FromDisplayName(Locale), + Slug = Slug, + Description = Description, + Title = Title, + Text = Text, + ShortText = ShortText, + + // TODO: create plain text creation logic + PlainText = "TODO", + + ContentType = Enumeration.FromDisplayName(ContentType), + Badges = Badges + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (string.IsNullOrWhiteSpace(Locale)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + else if (Enumeration.FromDisplayName(Locale) == null) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}"); + + if (string.IsNullOrWhiteSpace(Slug)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(Description)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(Title)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(Text)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(ShortText)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + + if (string.IsNullOrWhiteSpace(ContentType)) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}"); + else if (Enumeration.FromDisplayName(ContentType) == null) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}"); + } + + [MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Description), nameof(Title), nameof(Text), nameof(ShortText), nameof(ContentType) })] + private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs deleted file mode 100644 index 85644c4..0000000 --- a/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects.Documents; -using WeatherForecast.Models.Abstractions; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PostBlogItemRequestModel : PostItemRequestModelBase { - - /// - /// - /// - public uint? ReadTime { get; set; } - - /// - /// - /// - public uint? Likes { get; set; } - - /// - /// - /// - /// - public override BlogItem ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList(), - // Images - // Author - Created = DateTime.UtcNow, - Tags = Tags, - Categories = Categories, - FamilyFriendly = FamilyFriendly, - - ReadTime = ReadTime, - Likes = Likes - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs deleted file mode 100644 index 32aa1d8..0000000 --- a/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects; -using Core.DomainObjects.L10n; -using WeatherForecast.Models.L10n; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PostCategoryItemRequestModel : RequestModelBase { - - /// - /// - /// - public List L10n { get; set; } - - /// - /// - /// - /// - public override Category ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList() - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PostShopCartItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostShopCartItemRequestModel.cs deleted file mode 100644 index c1f0a75..0000000 --- a/webapi/WeatherForecast/Models/Requests/PostShopCartItemRequestModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects; -using Core.DomainObjects.Documents; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PostShopCartItemRequestModel : RequestModelBase { - - /// - /// - /// - public uint Quantity { get; set; } - - /// - /// - /// - /// - public override ShopCartItem ToDomainObject() => new() { - Quantity = Quantity, - Created = DateTime.UtcNow - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PostShopItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostShopItemRequestModel.cs deleted file mode 100644 index c3e09ec..0000000 --- a/webapi/WeatherForecast/Models/Requests/PostShopItemRequestModel.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects; -using Core.DomainObjects.Documents; -using Core.DomainObjects.L10n; -using ExtensionMethods; -using WeatherForecast.Models.Abstractions; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PostShopItemRequestModel : PostItemRequestModelBase { - - /// - /// - /// - public string BrandName { get; set; } - - /// - /// - /// - public decimal? Rating { get; set; } - - /// - /// - /// - public decimal Price { get; set; } - - /// - /// - /// - public decimal? NewPrice { get; set; } - - /// - /// - /// - public uint Quantity { get; set; } - - /// - /// - /// - /// - public override ShopItem ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList(), - // Images - // Author - Created = DateTime.UtcNow, - Tags = Tags, - Categories = Categories, - FamilyFriendly = FamilyFriendly, - - BrandName = BrandName, - Rating = Rating, - Price = Price, - NewPrice = NewPrice, - Quantity = Quantity - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs deleted file mode 100644 index 1a1d280..0000000 --- a/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects.Documents; -using WeatherForecast.Models.Abstractions; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PutBlogItemRequestModel : PostItemRequestModelBase { - - /// - /// - /// - public uint? ReadTime { get; set; } - - /// - /// - /// - public uint? Likes { get; set; } - - /// - /// - /// - /// - public override BlogItem ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList(), - // Images - // Author - Created = DateTime.UtcNow, - Tags = Tags, - Categories = Categories, - FamilyFriendly = FamilyFriendly, - - ReadTime = ReadTime, - Likes = Likes - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs deleted file mode 100644 index 5d07155..0000000 --- a/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects; -using WeatherForecast.Models.L10n; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PutCategoryItemRequestModel : RequestModelBase { - - /// - /// - /// - public List L10n { get; set; } - - /// - /// - /// - /// - public override Category ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList() - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PutShopCartItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutShopCartItemRequestModel.cs deleted file mode 100644 index df226f9..0000000 --- a/webapi/WeatherForecast/Models/Requests/PutShopCartItemRequestModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Core.Abstractions.Models; -using Core.DomainObjects; -using Core.DomainObjects.Documents; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PutShopCartItemRequestModel : RequestModelBase { - - /// - /// - /// - public uint Quantity { get; set; } - - /// - /// - /// - /// - public override ShopCartItem ToDomainObject() => new() { - Quantity = Quantity - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/PutShopItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutShopItemRequestModel.cs deleted file mode 100644 index 2048d69..0000000 --- a/webapi/WeatherForecast/Models/Requests/PutShopItemRequestModel.cs +++ /dev/null @@ -1,58 +0,0 @@ -using WeatherForecast.Models.Abstractions; - -using Core.DomainObjects; -using Core.DomainObjects.Documents; - -namespace WeatherForecast.Models.Requests { - - /// - /// - /// - public class PutShopItemRequestModel : PostItemRequestModelBase { - - /// - /// - /// - public string BrandName { get; set; } - - /// - /// - /// - public decimal? Rating { get; set; } - - /// - /// - /// - public decimal Price { get; set; } - - /// - /// - /// - public decimal? NewPrice { get; set; } - - /// - /// - /// - public uint Quantity { get; set; } - - /// - /// - /// - /// - public override ShopItem ToDomainObject() => new() { - L10n = L10n.Select(x => x.ToDomainObject()).ToList(), - // Images - // Author - Created = DateTime.UtcNow, - Tags = Tags, - Categories = Categories, - FamilyFriendly = FamilyFriendly, - - BrandName = BrandName, - Rating = Rating, - Price = Price, - NewPrice = NewPrice, - Quantity = Quantity - }; - } -} diff --git a/webapi/WeatherForecast/Models/Requests/ShopCartItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/ShopCartItemRequestModel.cs new file mode 100644 index 0000000..e4ed187 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/ShopCartItemRequestModel.cs @@ -0,0 +1,46 @@ +using Core.Abstractions.Models; +using Core.DomainObjects; +using Core.DomainObjects.Documents; +using Core.Enumerations; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; + +namespace WeatherForecast.Models.Requests { + + /// + /// + /// + public class ShopCartItemRequestModel : RequestModelBase { + + /// + /// + /// + public uint? Quantity { get; set; } + + /// + /// + /// + /// + public override ShopCartItem ToDomainObject() { + if (HasValidationErrors()) throw new ValidationException(); + + return new ShopCartItem() { + Quantity = Quantity.Value, + Created = DateTime.UtcNow + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (Quantity == null) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}"); + } + + [MemberNotNullWhen(false, new[] { nameof(Quantity) })] + private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Requests/ShopItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/ShopItemRequestModel.cs new file mode 100644 index 0000000..66f32c8 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/ShopItemRequestModel.cs @@ -0,0 +1,95 @@ +using Core.Abstractions.Models; +using Core.DomainObjects; +using Core.DomainObjects.Documents; +using Core.DomainObjects.L10n; +using Core.Enumerations; +using ExtensionMethods; +using Extensions; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using WeatherForecast.Models.Abstractions; + +namespace WeatherForecast.Models.Requests { + + /// + /// + /// + public class ShopItemRequestModel : PostItemRequestModelBase { + + /// + /// + /// + public string? BrandName { get; set; } + + /// + /// + /// + public decimal? Rating { get; set; } + + /// + /// + /// + public decimal? Price { get; set; } + + /// + /// + /// + public decimal? NewPrice { get; set; } + + /// + /// + /// + public uint? Quantity { get; set; } + + /// + /// + /// + /// + public override ShopItem ToDomainObject() { + if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException(); + + return new ShopItem() { + L10n = L10n.Select(x => x.ToDomainObject()).ToList(), + // Images + // Author + Created = DateTime.UtcNow, + Tags = Tags, + Categories = Categories, + FamilyFriendly = FamilyFriendly, + + BrandName = BrandName, + Rating = Rating, + Price = Price.Value, + NewPrice = NewPrice, + Quantity = Quantity.Value + }; + } + + /// + /// + /// + /// + /// + public override IEnumerable Validate(ValidationContext validationContext) { + if (L10n.IsNullOrEmpty()) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}"); + else { + foreach (var item in L10n) + foreach (var validationResult in item.Validate(validationContext)) + yield return validationResult; + } + + if (string.IsNullOrWhiteSpace(BrandName)) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrWhiteSpace}"); + + if (Price == null) + yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrEmpty.Name}"); + + if (Quantity == null) + yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}"); + } + + [MemberNotNullWhen(false, new[] { nameof(BrandName), nameof(Price), nameof(Quantity) })] + private bool HasValidationErrors(ShopItemRequestModel validationContext) => Validate(new ValidationContext(validationContext)).Any(); + } +} diff --git a/webapi/WeatherForecast/Models/Responses/GetBlogCategoriesResponseModel.cs b/webapi/WeatherForecast/Models/Responses/BlogCategoriesResponseModel.cs similarity index 59% rename from webapi/WeatherForecast/Models/Responses/GetBlogCategoriesResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/BlogCategoriesResponseModel.cs index 7090053..a52b7a5 100644 --- a/webapi/WeatherForecast/Models/Responses/GetBlogCategoriesResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/BlogCategoriesResponseModel.cs @@ -5,11 +5,11 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetBlogCategoriesResponseModel : ResponseModelBase { + public class BlogCategoriesResponseModel : ResponseModelBase { /// /// /// - public List Items { get; set; } + public List? Items { get; set; } } } diff --git a/webapi/WeatherForecast/Models/Responses/GetBlogFeaturedResponseModel.cs b/webapi/WeatherForecast/Models/Responses/BlogFeaturedResponseModel.cs similarity index 72% rename from webapi/WeatherForecast/Models/Responses/GetBlogFeaturedResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/BlogFeaturedResponseModel.cs index 5ae1632..524015e 100644 --- a/webapi/WeatherForecast/Models/Responses/GetBlogFeaturedResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/BlogFeaturedResponseModel.cs @@ -5,7 +5,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetBlogFeaturedResponseModel : ResponseModelBase { + public class BlogFeaturedResponseModel : ResponseModelBase { /// /// @@ -16,7 +16,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetBlogFeaturedResponseModel(List items) { + public BlogFeaturedResponseModel(List items) { Items = items; } } diff --git a/webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/BlogItemResponseModel.cs similarity index 72% rename from webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/BlogItemResponseModel.cs index 34a71f0..833899a 100644 --- a/webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/BlogItemResponseModel.cs @@ -10,7 +10,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetBlogItemResponseModel : PostItemResponseModelBase { + public class BlogItemResponseModel : PostItemResponseModelBase { /// /// @@ -27,7 +27,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetBlogItemResponseModel(BlogItem blogItem, List categories) : base(blogItem, categories) { + public BlogItemResponseModel(BlogItem blogItem, List categories) : base(blogItem, categories) { ReadTime = blogItem.ReadTime; Likes = blogItem.Likes; } @@ -38,7 +38,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetBlogItemResponseModel(BlogItem blogItem, List categories, Locales locale) : base(blogItem, categories, locale) { + public BlogItemResponseModel(BlogItem blogItem, List categories, Locales locale) : base(blogItem, categories, locale) { ReadTime = blogItem.ReadTime; Likes = blogItem.Likes; } diff --git a/webapi/WeatherForecast/Models/Responses/GetBlogItemsResponseModel.cs b/webapi/WeatherForecast/Models/Responses/BlogItemsResponseModel.cs similarity index 70% rename from webapi/WeatherForecast/Models/Responses/GetBlogItemsResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/BlogItemsResponseModel.cs index 6852c2b..0cf983a 100644 --- a/webapi/WeatherForecast/Models/Responses/GetBlogItemsResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/BlogItemsResponseModel.cs @@ -6,7 +6,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetBlogItemsResponseModel : PaginationModelBase { + public class BlogItemsResponseModel : PaginationModelBase { //public BlogItemModel FeaturedBlog { get; set; } @@ -20,7 +20,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetBlogItemsResponseModel(int currentPage, int totalPages, List items) + public BlogItemsResponseModel(int currentPage, int totalPages, List items) : base(currentPage, totalPages, items) { } } diff --git a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/CategoryItemResponseModel.cs similarity index 85% rename from webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/CategoryItemResponseModel.cs index 780b6f9..c0ca54d 100644 --- a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/CategoryItemResponseModel.cs @@ -8,7 +8,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetCategoryItemResponseModel : ResponseModelBase { + public class CategoryItemResponseModel : ResponseModelBase { /// /// @@ -39,7 +39,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetCategoryItemResponseModel(Category category) { + public CategoryItemResponseModel(Category category) { Id = category.Id; SiteId = category.SiteId; @@ -51,7 +51,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetCategoryItemResponseModel(Category category, Locales locale) { + public CategoryItemResponseModel(Category category, Locales locale) { Id = category.Id; SiteId = category.SiteId; diff --git a/webapi/WeatherForecast/Models/Responses/GetContentResponseModel.cs b/webapi/WeatherForecast/Models/Responses/ContentResponseModel.cs similarity index 96% rename from webapi/WeatherForecast/Models/Responses/GetContentResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/ContentResponseModel.cs index a80a6bc..1b89d67 100644 --- a/webapi/WeatherForecast/Models/Responses/GetContentResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/ContentResponseModel.cs @@ -7,7 +7,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetContentResponseModel : ResponseModelBase { + public class ContentResponseModel : ResponseModelBase { /// /// @@ -103,7 +103,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetContentResponseModel(Content domainObject) { + public ContentResponseModel(Content domainObject) { SiteName = domainObject.SiteName; SiteUrl = domainObject.SiteUrl; diff --git a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs b/webapi/WeatherForecast/Models/Responses/L10n/CategoryL10nModel.cs similarity index 54% rename from webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs rename to webapi/WeatherForecast/Models/Responses/L10n/CategoryL10nModel.cs index ba08eb5..13ac85d 100644 --- a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs +++ b/webapi/WeatherForecast/Models/Responses/L10n/CategoryL10nModel.cs @@ -1,14 +1,12 @@ -using Core.Abstractions; -using Core.Abstractions.Models; +using Core.Abstractions.Models; using Core.DomainObjects.L10n; -using Core.Enumerations; -namespace WeatherForecast.Models.L10n { +namespace WeatherForecast.Models.Responses.L10n { /// /// /// - public class CategoryL10nModel : ModelBase { + public class CategoryL10nModel : ResponseModelBase { /// /// @@ -25,11 +23,6 @@ namespace WeatherForecast.Models.L10n { /// public string Text { get; set; } - /// - /// - /// - public CategoryL10nModel() { } - /// /// /// @@ -39,15 +32,5 @@ namespace WeatherForecast.Models.L10n { Slug = categoryL10n.Slug; Text = categoryL10n.Text; } - - /// - /// - /// - /// - public CategoryL10n ToDomainObject() => new() { - Locale = Enumeration.FromDisplayName(Locale), - Slug = Slug, - Text = Text - }; } } diff --git a/webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs b/webapi/WeatherForecast/Models/Responses/L10n/ImageL10nModel.cs similarity index 50% rename from webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs rename to webapi/WeatherForecast/Models/Responses/L10n/ImageL10nModel.cs index f74c97f..acf6fe9 100644 --- a/webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs +++ b/webapi/WeatherForecast/Models/Responses/L10n/ImageL10nModel.cs @@ -1,14 +1,12 @@ -using Core.Abstractions; -using Core.Abstractions.Models; +using Core.Abstractions.Models; using Core.DomainObjects.L10n; -using Core.Enumerations; -namespace WeatherForecast.Models.L10n { +namespace WeatherForecast.Models.Responses.L10n { /// /// /// - public class ImageL10nModel : ModelBase { + public class ImageL10nModel : ResponseModelBase { /// /// @@ -20,11 +18,6 @@ namespace WeatherForecast.Models.L10n { /// public string Alt { get; set; } - /// - /// - /// - public ImageL10nModel() { } - /// /// /// @@ -33,14 +26,5 @@ namespace WeatherForecast.Models.L10n { Locale = imageL10n.Locale.Name; Alt = imageL10n.Alt; } - - /// - /// - /// - /// - public ImageL10n ToDomainObject() => new() { - Locale = Enumeration.FromDisplayName(Locale), - Alt = Alt - }; } } diff --git a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs b/webapi/WeatherForecast/Models/Responses/L10n/PostItemL10nModel.cs similarity index 62% rename from webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs rename to webapi/WeatherForecast/Models/Responses/L10n/PostItemL10nModel.cs index 7d082c8..dc370c2 100644 --- a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs +++ b/webapi/WeatherForecast/Models/Responses/L10n/PostItemL10nModel.cs @@ -1,14 +1,12 @@ -using Core.Abstractions; -using Core.Abstractions.Models; +using Core.Abstractions.Models; using Core.DomainObjects.L10n; -using Core.Enumerations; -namespace WeatherForecast.Models.L10n { +namespace WeatherForecast.Models.Responses.L10n { /// /// /// - public class PostItemL10nModel : ModelBase { + public class PostItemL10nModel : ResponseModelBase { /// /// @@ -38,7 +36,7 @@ namespace WeatherForecast.Models.L10n { /// /// /// - public string Text { get; set; } + public string? Text { get; set; } /// /// @@ -55,10 +53,6 @@ namespace WeatherForecast.Models.L10n { /// public List? Badges { get; set; } - /// - /// - /// - public PostItemL10nModel() { } /// /// @@ -70,28 +64,10 @@ namespace WeatherForecast.Models.L10n { Description = postItemL10n.Description; Title = postItemL10n.Title; ShortText = postItemL10n.ShortText; + PlainText = postItemL10n.PlainText; Text = postItemL10n.Text; ContentType = postItemL10n.ContentType.Name; Badges = postItemL10n.Badges; } - - /// - /// - /// - /// - public PostItemL10n ToDomainObject() => new() { - Locale = Enumeration.FromDisplayName(Locale), - Slug = Slug, - Description = Description, - Title = Title, - Text = Text, - ShortText = ShortText, - - // TODO: create plain text creation logic - PlainText = "TODO", - - ContentType = Enumeration.FromDisplayName(ContentType), - Badges = Badges - }; } } diff --git a/webapi/WeatherForecast/Models/Responses/GetShopCartItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/ShopCartItemResponseModel.cs similarity index 88% rename from webapi/WeatherForecast/Models/Responses/GetShopCartItemResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/ShopCartItemResponseModel.cs index 3c44e23..fee0d43 100644 --- a/webapi/WeatherForecast/Models/Responses/GetShopCartItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/ShopCartItemResponseModel.cs @@ -7,7 +7,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetShopCartItemResponseModel : ResponseModelBase { + public class ShopCartItemResponseModel : ResponseModelBase { /// /// @@ -62,7 +62,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetShopCartItemResponseModel() { } + public ShopCartItemResponseModel() { } /// /// @@ -70,7 +70,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetShopCartItemResponseModel(ShopItem shopItem, ShopCartItem shopCartItem, Locales locale) { + public ShopCartItemResponseModel(ShopItem shopItem, ShopCartItem shopCartItem, Locales locale) { Sku = shopItem.Sku; BrandName = shopItem.BrandName; diff --git a/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/ShopItemResponseModel.cs similarity index 79% rename from webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/ShopItemResponseModel.cs index d22c778..94044fd 100644 --- a/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/ShopItemResponseModel.cs @@ -9,7 +9,7 @@ namespace WeatherForecast.Models { /// /// /// - public class GetShopItemResponseModel : PostItemResponseModelBase { + public class ShopItemResponseModel : PostItemResponseModelBase { /// /// @@ -41,7 +41,7 @@ namespace WeatherForecast.Models { /// /// /// - public GetShopItemResponseModel(ShopItem shopCatalogItem, List categories) : base(shopCatalogItem, categories) { + public ShopItemResponseModel(ShopItem shopCatalogItem, List categories) : base(shopCatalogItem, categories) { Sku = shopCatalogItem.Sku; Rating = shopCatalogItem.Rating; Price = shopCatalogItem.Price; @@ -55,7 +55,7 @@ namespace WeatherForecast.Models { /// /// /// - public GetShopItemResponseModel(ShopItem shopCatalogItem, List categories, Locales locale) : base(shopCatalogItem, categories, locale) { + public ShopItemResponseModel(ShopItem shopCatalogItem, List categories, Locales locale) : base(shopCatalogItem, categories, locale) { Sku = shopCatalogItem.Sku; Rating = shopCatalogItem.Rating; Price = shopCatalogItem.Price; diff --git a/webapi/WeatherForecast/Models/Responses/GetShopItemsResponseModel.cs b/webapi/WeatherForecast/Models/Responses/ShopItemsResponseModel.cs similarity index 64% rename from webapi/WeatherForecast/Models/Responses/GetShopItemsResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/ShopItemsResponseModel.cs index 8a31e71..dc7d80f 100644 --- a/webapi/WeatherForecast/Models/Responses/GetShopItemsResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/ShopItemsResponseModel.cs @@ -6,7 +6,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetShopItemsResponseModel : PaginationModelBase { + public class ShopItemsResponseModel : PaginationModelBase { /// /// @@ -14,7 +14,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public GetShopItemsResponseModel(int currentPage, int totalPages, List items) + public ShopItemsResponseModel(int currentPage, int totalPages, List items) : base(currentPage, totalPages, items) { } } } diff --git a/webapi/WeatherForecast/Models/Responses/GetWeatherForecastResponseModel.cs b/webapi/WeatherForecast/Models/Responses/WeatherForecastResponseModel.cs similarity index 87% rename from webapi/WeatherForecast/Models/Responses/GetWeatherForecastResponseModel.cs rename to webapi/WeatherForecast/Models/Responses/WeatherForecastResponseModel.cs index 3c0154e..2f1e2cc 100644 --- a/webapi/WeatherForecast/Models/Responses/GetWeatherForecastResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/WeatherForecastResponseModel.cs @@ -5,7 +5,7 @@ namespace WeatherForecast.Models.Responses { /// /// /// - public class GetWeatherForecastResponseModel : ResponseModelBase { + public class WeatherForecastResponseModel : ResponseModelBase { /// /// diff --git a/webapi/WeatherForecast/Services/BlogItemService.cs b/webapi/WeatherForecast/Services/BlogItemService.cs index 154de73..0d3a1bd 100644 --- a/webapi/WeatherForecast/Services/BlogItemService.cs +++ b/webapi/WeatherForecast/Services/BlogItemService.cs @@ -17,7 +17,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel); + (Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel); /// /// @@ -25,7 +25,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId); + (BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId); /// /// @@ -33,7 +33,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); + (BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); /// /// @@ -42,7 +42,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData); + (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData); /// /// @@ -84,7 +84,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) { + public (Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel) { throw new NotImplementedException(); } @@ -94,7 +94,7 @@ namespace WeatherForecast.Services { /// /// /// - public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) { + public (BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) { var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId); if (!result.IsSuccess || item == null) @@ -109,7 +109,7 @@ namespace WeatherForecast.Services { categories.Add(category); } - return IDomainResult.Success(new GetBlogItemResponseModel(item, categories)); + return IDomainResult.Success(new BlogItemResponseModel(item, categories)); } /// @@ -118,7 +118,7 @@ namespace WeatherForecast.Services { /// /// /// - public (GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { + public (BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug); if (!result.IsSuccess || item == null) @@ -135,7 +135,7 @@ namespace WeatherForecast.Services { categories.Add(category); } - return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, locale)); + return IDomainResult.Success(new BlogItemResponseModel(item, categories, locale)); } /// @@ -146,7 +146,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData) { + public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData) { throw new NotImplementedException(); } diff --git a/webapi/WeatherForecast/Services/BlogItemsService.cs b/webapi/WeatherForecast/Services/BlogItemsService.cs index 171e23e..147c0df 100644 --- a/webapi/WeatherForecast/Services/BlogItemsService.cs +++ b/webapi/WeatherForecast/Services/BlogItemsService.cs @@ -22,7 +22,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetBlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText); + (BlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText); /// /// @@ -67,12 +67,12 @@ namespace WeatherForecast.Services { /// /// /// - public (GetBlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) { + public (BlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) { var (items, result) = _blogCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage); if (!result.IsSuccess || items == null) return (null, result); - var blogItems = new List(); + var blogItems = new List(); foreach (var item in items) { var categories = new List(); foreach (var catId in item.Categories) { @@ -84,14 +84,14 @@ namespace WeatherForecast.Services { } if(locale != null) - blogItems.Add(new GetBlogItemResponseModel(item, categories, Enumeration.FromDisplayName(locale) ?? Locales.Us)); + blogItems.Add(new BlogItemResponseModel(item, categories, Enumeration.FromDisplayName(locale) ?? Locales.Us)); else - blogItems.Add(new GetBlogItemResponseModel(item, categories)); + blogItems.Add(new BlogItemResponseModel(item, categories)); } return blogItems.Count > 0 - ? IDomainResult.Success(new GetBlogItemsResponseModel(currentPage, 0, blogItems)) - : IDomainResult.NotFound(); + ? IDomainResult.Success(new BlogItemsResponseModel(currentPage, 0, blogItems)) + : IDomainResult.NotFound(); } /// diff --git a/webapi/WeatherForecast/Services/CategoryItemService.cs b/webapi/WeatherForecast/Services/CategoryItemService.cs index 9bb3cd0..a5b0acd 100644 --- a/webapi/WeatherForecast/Services/CategoryItemService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemService.cs @@ -17,7 +17,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel); + (Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel); /// /// @@ -25,7 +25,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId); + (CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId); /// /// @@ -33,7 +33,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); + (CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); /// /// @@ -42,7 +42,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData); + (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData); /// /// @@ -80,7 +80,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel) { + public (Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel) { var (_, getResult) = _categoryDataProvider.GetBySlugs(siteId, requestModel.L10n.Select(x => x.Slug).ToList()); if (getResult.IsSuccess) return IDomainResult.Failed(); @@ -103,12 +103,12 @@ namespace WeatherForecast.Services { /// /// /// - public (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) { + public (CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) { var (item, result) = _categoryDataProvider.Get(siteId, categoryId); if (!result.IsSuccess || item == null) return (null, result); - return IDomainResult.Success(new GetCategoryItemResponseModel(item)); + return IDomainResult.Success(new CategoryItemResponseModel(item)); } /// @@ -117,14 +117,14 @@ namespace WeatherForecast.Services { /// /// /// - public (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { + public (CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug); if (!result.IsSuccess || item == null) return (null, result); var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us; - return IDomainResult.Success(new GetCategoryItemResponseModel(item, locale)); + return IDomainResult.Success(new CategoryItemResponseModel(item, locale)); } /// @@ -134,7 +134,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData) { + public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData) { var (item, result) = _categoryDataProvider.Get(siteId, categoryId); if (!result.IsSuccess || item == null) return (null, result); diff --git a/webapi/WeatherForecast/Services/CategoryItemsService.cs b/webapi/WeatherForecast/Services/CategoryItemsService.cs index c0fe192..f472531 100644 --- a/webapi/WeatherForecast/Services/CategoryItemsService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemsService.cs @@ -17,7 +17,7 @@ namespace WeatherForecast.Services { /// /// /// - (List?, IDomainResult) Get(Guid siteId, string? locale); + (List?, IDomainResult) Get(Guid siteId, string? locale); /// /// @@ -54,16 +54,16 @@ namespace WeatherForecast.Services { /// /// /// - public (List?, IDomainResult) Get(Guid siteId, string? locale) { + public (List?, IDomainResult) Get(Guid siteId, string? locale) { var (items, result) = _categoryDataProvider.GetAll(siteId); if (!result.IsSuccess || items == null) return (null, result); if (locale != null) { - return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x, Enumeration.FromDisplayName(locale) ?? Locales.Us)).ToList()); + return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x, Enumeration.FromDisplayName(locale) ?? Locales.Us)).ToList()); } - return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x)).ToList()); + return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x)).ToList()); } /// diff --git a/webapi/WeatherForecast/Services/ContentService.cs b/webapi/WeatherForecast/Services/ContentService.cs index f134ff1..bcabb8c 100644 --- a/webapi/WeatherForecast/Services/ContentService.cs +++ b/webapi/WeatherForecast/Services/ContentService.cs @@ -16,7 +16,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale); + (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale); } /// @@ -46,13 +46,13 @@ namespace WeatherForecast.Services { /// /// /// - public (GetContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) { + public (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) { var (content, result) = _contentDataProvider.Get(siteId, locale); if (!result.IsSuccess || content == null) return (null, result); - return IDomainResult.Success(new GetContentResponseModel(content)); + return IDomainResult.Success(new ContentResponseModel(content)); } } } diff --git a/webapi/WeatherForecast/Services/ShopCartItemService.cs b/webapi/WeatherForecast/Services/ShopCartItemService.cs index 383fa85..aa9870a 100644 --- a/webapi/WeatherForecast/Services/ShopCartItemService.cs +++ b/webapi/WeatherForecast/Services/ShopCartItemService.cs @@ -22,7 +22,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, PostShopCartItemRequestModel requestModel); + (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel); /// /// @@ -32,7 +32,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US"); + (ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US"); /// /// @@ -42,7 +42,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, PutShopCartItemRequestModel requestData); + (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData); /// /// @@ -87,7 +87,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, PostShopCartItemRequestModel requestModel) { + public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel) { var (_, getResult) = _shopCartDataProvider.Get(siteId, userId, sku); if (getResult.IsSuccess) return IDomainResult.Failed(); @@ -114,7 +114,7 @@ namespace WeatherForecast.Services { /// /// /// - public (GetShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US") { + public (ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US") { var (cartItem, getCartItemResult) = _shopCartDataProvider.Get(siteId, userId, sku); if (!getCartItemResult.IsSuccess || cartItem == null) @@ -124,7 +124,7 @@ namespace WeatherForecast.Services { if (!result.IsSuccess || item == null) return (null, result); - return IDomainResult.Success(new GetShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName(locale))); + return IDomainResult.Success(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName(locale))); } /// @@ -135,7 +135,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, PutShopCartItemRequestModel requestData) { + public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData) { var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku); if (!getResult.IsSuccess || item == null) return (null, getResult); diff --git a/webapi/WeatherForecast/Services/ShopCartItemsService.cs b/webapi/WeatherForecast/Services/ShopCartItemsService.cs index eb8240a..1ce2802 100644 --- a/webapi/WeatherForecast/Services/ShopCartItemsService.cs +++ b/webapi/WeatherForecast/Services/ShopCartItemsService.cs @@ -21,7 +21,7 @@ namespace WeatherForecast.Services { /// /// /// - (List?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US"); + (List?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US"); /// /// @@ -64,24 +64,24 @@ namespace WeatherForecast.Services { /// /// /// - public (List?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US") { + public (List?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US") { var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId); if (!getCartItemsResult.IsSuccess || cartItems == null) return (null, getCartItemsResult); - var items = new List(); + var items = new List(); foreach (var cartItem in cartItems) { var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku); if (!result.IsSuccess || item == null) return (null, result); - items.Add(new GetShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName(locale))); + items.Add(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName(locale))); } return items.Count > 0 ? IDomainResult.Success(items) - : IDomainResult.NotFound?>(); + : IDomainResult.NotFound?>(); } /// diff --git a/webapi/WeatherForecast/Services/ShopItemService.cs b/webapi/WeatherForecast/Services/ShopItemService.cs index 5cb41a9..074b8bc 100644 --- a/webapi/WeatherForecast/Services/ShopItemService.cs +++ b/webapi/WeatherForecast/Services/ShopItemService.cs @@ -21,7 +21,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel); + (Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel); /// /// @@ -29,7 +29,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku); + (ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku); /// /// @@ -37,7 +37,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); + (ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); /// /// @@ -46,7 +46,7 @@ namespace WeatherForecast.Services { /// /// /// - (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData); + (Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData); /// /// @@ -89,7 +89,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel) { + public (Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel) { var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku); if (getResult.IsSuccess) return IDomainResult.Failed(); @@ -132,7 +132,7 @@ namespace WeatherForecast.Services { /// /// /// - public (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) { + public (ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) { var (item, result) = _shopCatalogDataProvider.Get(siteId, sku); if (!result.IsSuccess || item == null) @@ -149,7 +149,7 @@ namespace WeatherForecast.Services { } } - return IDomainResult.Success(new GetShopItemResponseModel(item, categories)); + return IDomainResult.Success(new ShopItemResponseModel(item, categories)); } /// @@ -158,7 +158,7 @@ namespace WeatherForecast.Services { /// /// /// - public (GetShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { + public (ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug); if (!result.IsSuccess || item == null) @@ -177,7 +177,7 @@ namespace WeatherForecast.Services { } } - return IDomainResult.Success(new GetShopItemResponseModel(item, categories, locale)); + return IDomainResult.Success(new ShopItemResponseModel(item, categories, locale)); } /// @@ -187,7 +187,7 @@ namespace WeatherForecast.Services { /// /// /// - public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) { + public (Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData) { var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku); if (!getResult.IsSuccess || item == null) return (null, getResult); diff --git a/webapi/WeatherForecast/Services/ShopItemsService.cs b/webapi/WeatherForecast/Services/ShopItemsService.cs index 256c9a7..629bf16 100644 --- a/webapi/WeatherForecast/Services/ShopItemsService.cs +++ b/webapi/WeatherForecast/Services/ShopItemsService.cs @@ -23,7 +23,7 @@ namespace WeatherForecast.Services { /// /// /// - (GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText); + (ShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText); /// /// @@ -67,14 +67,14 @@ namespace WeatherForecast.Services { /// /// /// - public (GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) { + public (ShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) { var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage); if (!result.IsSuccess || items == null) return (null, result); - var shopItems = new List(); + var shopItems = new List(); foreach (var item in items) { var categories = new List(); @@ -89,14 +89,14 @@ namespace WeatherForecast.Services { } if(locale != null) - shopItems.Add(new GetShopItemResponseModel(item, categories, Enumeration.FromDisplayName(locale) ?? Locales.Us)); + shopItems.Add(new ShopItemResponseModel(item, categories, Enumeration.FromDisplayName(locale) ?? Locales.Us)); else - shopItems.Add(new GetShopItemResponseModel(item, categories)); + shopItems.Add(new ShopItemResponseModel(item, categories)); } return shopItems.Count > 0 - ? IDomainResult.Success(new GetShopItemsResponseModel(currentPage, 0, shopItems)) - : IDomainResult.NotFound(); + ? IDomainResult.Success(new ShopItemsResponseModel(currentPage, 0, shopItems)) + : IDomainResult.NotFound(); } ///