diff --git a/db/DML/categories.json b/db/DML/categories.json index 0efec4c..0f72a97 100644 --- a/db/DML/categories.json +++ b/db/DML/categories.json @@ -3,11 +3,16 @@ "_id":"e154e33f-3cc7-468d-bb66-e0390ddb9ae0", "siteId":"404c8232-9048-4519-bfba-6e78dc7005ca", "l10n":[ - { - "locale":0, - "slug":"default", - "text":"Default category" - } + { + "locale": 0, + "slug": "default", + "text": "Default category" + }, + { + "locale": 2, + "slug": "predefinit", + "text": "Categoria predefinita" + } ] } ] \ No newline at end of file diff --git a/webapi/Core/Abstractions/DomainObjects/PostItemBase.cs b/webapi/Core/Abstractions/DomainObjects/PostItemBase.cs index f7d1aec..ac454fc 100644 --- a/webapi/Core/Abstractions/DomainObjects/PostItemBase.cs +++ b/webapi/Core/Abstractions/DomainObjects/PostItemBase.cs @@ -15,16 +15,16 @@ namespace Core.Abstractions.DomainObjects { public List L10n { get; set; } - public List Images { get; set; } + public List? Images { get; set; } public Guid Author { get; set; } public DateTime Created { get; set; } - 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; } } diff --git a/webapi/Core/DomainObjects/Documents/Category.cs b/webapi/Core/DomainObjects/Documents/Category.cs index 90f7c70..bd645a2 100644 --- a/webapi/Core/DomainObjects/Documents/Category.cs +++ b/webapi/Core/DomainObjects/Documents/Category.cs @@ -10,7 +10,7 @@ namespace Core.DomainObjects { unchecked { int hash = 17; hash = hash * 23 + Id.GetHashCode(); - hash = hash * 23 + L10n.Sum(x => x.GetHashCode()); + hash = hash + L10n.Sum(x => x.GetHashCode() * 23); return hash; } } diff --git a/webapi/Core/DomainObjects/L10n/CategoryL10n.cs b/webapi/Core/DomainObjects/L10n/CategoryL10n.cs index bc4e5bc..3e91095 100644 --- a/webapi/Core/DomainObjects/L10n/CategoryL10n.cs +++ b/webapi/Core/DomainObjects/L10n/CategoryL10n.cs @@ -16,6 +16,7 @@ namespace Core.DomainObjects.L10n { unchecked { int hash = 17; hash = hash * 23 + Locale.GetHashCode(); + hash = hash * 23 + Slug.GetHashCode(); hash = hash * 23 + Text.GetHashCode(); return hash; } diff --git a/webapi/Core/DomainObjects/L10n/PostItemL10n.cs b/webapi/Core/DomainObjects/L10n/PostItemL10n.cs index 4542b6a..3711fd8 100644 --- a/webapi/Core/DomainObjects/L10n/PostItemL10n.cs +++ b/webapi/Core/DomainObjects/L10n/PostItemL10n.cs @@ -11,7 +11,7 @@ namespace Core.DomainObjects.L10n { public ContentTypes ContentType { get; set; } public string PlainText { get; set; } public string ShortText { get; set; } - public List Badges { get; set; } + public List? Badges { get; set; } public override int GetHashCode() { unchecked { diff --git a/webapi/DataProviders/BlogCatalogDataProvider.cs b/webapi/DataProviders/BlogCatalogDataProvider.cs index b18471c..f3ae901 100644 --- a/webapi/DataProviders/BlogCatalogDataProvider.cs +++ b/webapi/DataProviders/BlogCatalogDataProvider.cs @@ -12,8 +12,8 @@ namespace DataProviders { public interface IBlogCatalogDataProvider { (Guid?, IDomainResult) Insert(BlogItem blogItem); (BlogItem?, IDomainResult) Get(Guid siteId, Guid blogId); - (BlogItem?, IDomainResult) Get(Guid siteId, string slug); - (BlogItem?, IDomainResult) Get(Guid siteId, List slugs); + (BlogItem?, IDomainResult) GetBySlug(Guid siteId, string slug); + (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs); (List?, IDomainResult) GetAll(Guid siteId, int skip, int take); (Guid?, IDomainResult) Update(BlogItem blogItem); IDomainResult Delete(Guid id); @@ -43,11 +43,8 @@ namespace DataProviders { return (list.First(), result); } - public (BlogItem?, IDomainResult) Get(Guid siteId, string slug) => - Get(siteId, new List { slug }); - - public (BlogItem?, IDomainResult) Get(Guid siteId, List slugs) { - var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (BlogItem?, IDomainResult) GetBySlug(Guid siteId, string slug) { + var (list, result) = GetBySlugs(siteId, new List { slug }); if (!result.IsSuccess || list == null) return (null, result); @@ -55,6 +52,9 @@ namespace DataProviders { return (list.First(), result); } + public (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs) => + GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (List?, IDomainResult) GetAll(Guid siteId, int skip, int take) => GetWithPredicate(x => x.SiteId == siteId, 0, 0, _collectionName); diff --git a/webapi/DataProviders/CategoryDataProvider.cs b/webapi/DataProviders/CategoryDataProvider.cs index be095c0..d6e978f 100644 --- a/webapi/DataProviders/CategoryDataProvider.cs +++ b/webapi/DataProviders/CategoryDataProvider.cs @@ -13,8 +13,8 @@ namespace DataProviders { public interface ICategoryDataProvider { (Guid?, IDomainResult) Insert(Category obj); (Category?, IDomainResult) Get(Guid siteId, Guid categoryId); - (Category?, IDomainResult) Get(Guid siteId, string slug); - (Category?, IDomainResult) Get(Guid siteId, List slugs); + (Category?, IDomainResult) GetBySlug(Guid siteId, string slug); + (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs); (List?, IDomainResult) GetAll(Guid siteId); (Guid?, IDomainResult) Update(Category obj); IDomainResult Delete(Guid id); @@ -43,11 +43,8 @@ namespace DataProviders { return (list.First(), result); } - public (Category?, IDomainResult) Get(Guid siteId, string slug) => - Get(siteId, new List { slug }); - - public (Category?, IDomainResult) Get(Guid siteId, List slugs) { - var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (Category?, IDomainResult) GetBySlug(Guid siteId, string slug) { + var (list, result) = GetBySlugs(siteId, new List { slug }); if (!result.IsSuccess || list == null) return (null, result); @@ -55,6 +52,9 @@ namespace DataProviders { return (list.First(), result); } + public (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs) => + GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (List?, IDomainResult) GetAll(Guid siteId) => GetWithPredicate(x => x.SiteId == siteId, _collectionName); diff --git a/webapi/DataProviders/ShopCatalogDataProvider.cs b/webapi/DataProviders/ShopCatalogDataProvider.cs index 7cfee55..df81408 100644 --- a/webapi/DataProviders/ShopCatalogDataProvider.cs +++ b/webapi/DataProviders/ShopCatalogDataProvider.cs @@ -12,8 +12,8 @@ namespace DataProviders { public interface IShopCatalogDataProvider { (Guid?, IDomainResult) Insert(ShopItem obj); (ShopItem?, IDomainResult) Get(Guid siteId, string sku); - //(ShopItem?, IDomainResult) Get(Guid siteId, string slug); - (ShopItem?, IDomainResult) Get(Guid siteId, List slugs); + (ShopItem?, IDomainResult) GetBySlug(Guid siteId, string slug); + (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs); (List?, IDomainResult) GetAll(Guid siteId, int skip, int take); (Guid?, IDomainResult) Update(ShopItem shopCart); IDomainResult Delete(Guid id); @@ -43,11 +43,8 @@ namespace DataProviders { return (list.First(), result); } - //public (ShopItem?, IDomainResult) Get(Guid siteId, string slug) => - // Get(siteId, new List { slug }); - - public (ShopItem?, IDomainResult) Get(Guid siteId, List slugs) { - var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (ShopItem?, IDomainResult) GetBySlug(Guid siteId, string slug) { + var (list, result) = GetBySlugs(siteId, new List { slug }); if (!result.IsSuccess || list == null) return (null, result); @@ -55,6 +52,9 @@ namespace DataProviders { return (list.First(), result); } + public (List?, IDomainResult) GetBySlugs(Guid siteId, List slugs) => + GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); + public (List?, IDomainResult) GetAll(Guid siteId, int skip, int take) => GetWithPredicate(x => x.SiteId == siteId, skip, take, _collectionName); diff --git a/webapi/WeatherForecast/Controllers/BlogItemController.cs b/webapi/WeatherForecast/Controllers/BlogItemController.cs index 2b3f7be..483a2b0 100644 --- a/webapi/WeatherForecast/Controllers/BlogItemController.cs +++ b/webapi/WeatherForecast/Controllers/BlogItemController.cs @@ -53,7 +53,7 @@ namespace WeatherForecast.Controllers { /// [HttpGet("{siteId}")] public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { - var result = _blogItemService.Get(siteId, slug); + var result = _blogItemService.GetSlug(siteId, slug); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/CategoryItemController.cs b/webapi/WeatherForecast/Controllers/CategoryItemController.cs index 62cba82..3b85e63 100644 --- a/webapi/WeatherForecast/Controllers/CategoryItemController.cs +++ b/webapi/WeatherForecast/Controllers/CategoryItemController.cs @@ -54,7 +54,7 @@ namespace WeatherForecast.Controllers { /// [HttpGet("{siteId}")] public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { - var result = _categoryItemService.Get(siteId, slug); + var result = _categoryItemService.GetSlug(siteId, slug); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/CategoryItemsController.cs b/webapi/WeatherForecast/Controllers/CategoryItemsController.cs index a2ee75c..edd6e79 100644 --- a/webapi/WeatherForecast/Controllers/CategoryItemsController.cs +++ b/webapi/WeatherForecast/Controllers/CategoryItemsController.cs @@ -36,9 +36,7 @@ namespace WeatherForecast.Controllers { /// [HttpGet("{siteId}")] public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) { - var result = _categoryItemsService.Get(siteId, locale != null - ? Enumeration.FromDisplayName(locale) - : Locales.Us); + var result = _categoryItemsService.Get(siteId, locale); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Controllers/ShopItemController.cs b/webapi/WeatherForecast/Controllers/ShopItemController.cs index e100142..69e3fe3 100644 --- a/webapi/WeatherForecast/Controllers/ShopItemController.cs +++ b/webapi/WeatherForecast/Controllers/ShopItemController.cs @@ -56,7 +56,7 @@ namespace WeatherForecast.Controllers { /// [HttpGet("{siteId}")] public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { - var result = _shopItemService.Get(siteId, slug); + var result = _shopItemService.GetSlug(siteId, slug); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs b/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs index d0101ee..ed9aff6 100644 --- a/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs +++ b/webapi/WeatherForecast/Models/Abstractions/PostItemResponseModelBase.cs @@ -2,26 +2,33 @@ using Core.Abstractions.Models; using Core.DomainObjects; using Core.Enumerations; +using WeatherForecast.Models.L10n; namespace WeatherForecast.Models.Abstractions { public abstract class PostItemResponseModelBase : ResponseModelBase { - public string Slug { get; set; } + public Guid Id { get; set; } + public Guid SiteId { get; set; } + + public List? L10n { get; set; } + + #region Localized costrutor + 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; } + #endregion - public string Description { get; set; } public List Images { get; set; } - public List Badges { get; set; } - - public string Title { get; set; } - - public string ShortText { get; set; } - - public string Text { get; set; } - - public string PlainText { get; set; } - public AuthorModel Author { get; set; } public DateTime Created { get; set; } @@ -32,7 +39,22 @@ namespace WeatherForecast.Models.Abstractions { public bool? FamilyFriendly { get; set; } - public PostItemResponseModelBase(PostItemBase postItem, List categories, Locales locale) { + public PostItemResponseModelBase(PostItemBase postItem) { + Id = postItem.Id; + SiteId = postItem.SiteId; + // Author = new AuthorModel(postItem.Author); + Created = postItem.Created; + Tags = postItem.Tags; + FamilyFriendly = postItem.FamilyFriendly; + } + + 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(); + } + + public PostItemResponseModelBase(PostItemBase postItem, List categories, Locales locale) : this(postItem) { var postItemL10n = postItem.L10n.SingleOrDefault(x => x.Locale == locale); if (postItemL10n != null) { @@ -45,18 +67,8 @@ namespace WeatherForecast.Models.Abstractions { Badges = postItemL10n.Badges; } - Categories = categories.Select(x => new CategoryModel(x, locale)).ToList(); - - // Author = new AuthorModel(postItem.Author); - - Created = postItem.Created; - Tags = postItem.Tags; - - Images = postItem.Images.Select(x => new ImageModel(x, locale)).ToList(); - - FamilyFriendly = postItem.FamilyFriendly; } } } diff --git a/webapi/WeatherForecast/Models/CategoryModel.cs b/webapi/WeatherForecast/Models/CategoryModel.cs index ee88748..d154a33 100644 --- a/webapi/WeatherForecast/Models/CategoryModel.cs +++ b/webapi/WeatherForecast/Models/CategoryModel.cs @@ -1,13 +1,19 @@ using Core.DomainObjects; using Core.Enumerations; +using WeatherForecast.Models.L10n; namespace WeatherForecast.Models { public class CategoryModel { - public string Slug { get; set; } - public string Text { get; set; } + public List? L10n { get; set; } + + public string? Slug { get; set; } + public string? Text { get; set; } + + public CategoryModel(Category category) { + L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); + } public CategoryModel(Category category, Locales locale) { - var categoryL10n = category.L10n.SingleOrDefault(x => x.Locale == locale); if (categoryL10n != null) { Slug = categoryL10n.Slug; diff --git a/webapi/WeatherForecast/Models/ImageModel.cs b/webapi/WeatherForecast/Models/ImageModel.cs index 0a13d81..1ed76e7 100644 --- a/webapi/WeatherForecast/Models/ImageModel.cs +++ b/webapi/WeatherForecast/Models/ImageModel.cs @@ -1,12 +1,17 @@ using Core.DomainObjects; using Core.Enumerations; +using WeatherForecast.Models.L10n; namespace WeatherForecast.Models { public class ImageModel { - public string Src { get; set; } - public string Alt { get; set; } + public List? L10n { get; set; } - public ImageModel() { } + public string? Src { get; set; } + public string? Alt { get; set; } + + public ImageModel(Image image) { + L10n = image.L10n.Select(x => new ImageL10nModel(x)).ToList(); + } public ImageModel(Image image, Locales locale) { Src = image.Src; diff --git a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs b/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs index f677d28..92b701c 100644 --- a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs +++ b/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs @@ -10,6 +10,8 @@ namespace WeatherForecast.Models.L10n { public string Slug { get; set; } public string Text { get; set; } + public CategoryL10nModel() { } + public CategoryL10nModel(CategoryL10n categoryL10n) { Locale = categoryL10n.Locale.Name; Slug = categoryL10n.Slug; diff --git a/webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs b/webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs new file mode 100644 index 0000000..7b43e23 --- /dev/null +++ b/webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs @@ -0,0 +1,23 @@ +using Core.Abstractions; +using Core.Abstractions.Models; +using Core.DomainObjects.L10n; +using Core.Enumerations; + +namespace WeatherForecast.Models.L10n { + public class ImageL10nModel : ModelBase { + public string Locale { get; set; } + public string Alt { get; set; } + + public ImageL10nModel() { } + + public ImageL10nModel(ImageL10n imageL10n) { + Locale = imageL10n.Locale.Name; + Alt = imageL10n.Alt; + } + + public ImageL10n ToDomainObject() => new ImageL10n { + Locale = Enumeration.FromDisplayName(Locale), + Alt = Alt + }; + } +} diff --git a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs b/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs index 6f8e261..38e021e 100644 --- a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs +++ b/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs @@ -13,9 +13,12 @@ namespace WeatherForecast.Models.L10n { 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 List? Badges { get; set; } + + public PostItemL10nModel() { } public PostItemL10nModel(PostItemL10n postItemL10n) { Locale = postItemL10n.Locale.Name; diff --git a/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs index 02b7c0f..48a9956 100644 --- a/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs +++ b/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs @@ -1,10 +1,23 @@ using Core.Abstractions.Models; using Core.DomainObjects.Documents; +using WeatherForecast.Models.Abstractions; namespace WeatherForecast.Models.Requests { - public class PostBlogItemRequestModel : RequestModelBase { - public override BlogItem ToDomainObject() { - throw new NotImplementedException(); - } + public class PostBlogItemRequestModel : PostItemRequestModelBase { + public uint? ReadTime { get; set; } + public uint? Likes { get; set; } + + public override BlogItem ToDomainObject() => new BlogItem { + 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/PutBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs index 6c014b8..9212dcf 100644 --- a/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs +++ b/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs @@ -1,10 +1,23 @@ using Core.Abstractions.Models; using Core.DomainObjects.Documents; +using WeatherForecast.Models.Abstractions; namespace WeatherForecast.Models.Requests { - public class PutBlogItemRequestModel : RequestModelBase { - public override BlogItem ToDomainObject() { - throw new NotImplementedException(); - } + public class PutBlogItemRequestModel : PostItemRequestModelBase { + public uint? ReadTime { get; set; } + public uint? Likes { get; set; } + + public override BlogItem ToDomainObject() => new BlogItem { + 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/Responses/GetBlogItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs index 80c17b9..8487e1c 100644 --- a/webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/GetBlogItemResponseModel.cs @@ -12,6 +12,11 @@ namespace WeatherForecast.Models.Responses { public uint? Likes { get; set; } + public GetBlogItemResponseModel(BlogItem blogItem, List categories) : base(blogItem, categories) { + ReadTime = blogItem.ReadTime; + Likes = blogItem.Likes; + } + public GetBlogItemResponseModel(BlogItem blogItem, List categories, Locales locale) : base(blogItem, categories, locale) { ReadTime = blogItem.ReadTime; Likes = blogItem.Likes; diff --git a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs index b236937..72e5e11 100644 --- a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs @@ -5,17 +5,26 @@ using WeatherForecast.Models.L10n; namespace WeatherForecast.Models.Responses { public class GetCategoryItemResponseModel : ResponseModelBase { - + public Guid Id { get; set; } + public Guid SiteId { get; set; } public string? Slug { get; set; } public string? Text { get; set; } public List? L10n { get; set; } + + public GetCategoryItemResponseModel(Category category) { + Id = category.Id; + SiteId = category.SiteId; + L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); } public GetCategoryItemResponseModel(Category category, Locales locale) { + Id = category.Id; + SiteId = category.SiteId; + var l10n = category.L10n.SingleOrDefault(x => x.Locale == locale); if (l10n != null) { Slug = l10n.Slug; diff --git a/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs index 23c2f35..61ee1c8 100644 --- a/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/GetShopItemResponseModel.cs @@ -13,6 +13,14 @@ namespace WeatherForecast.Models { public decimal? NewPrice { get; set; } public uint? Quantity { get; set; } + public GetShopItemResponseModel(ShopItem shopCatalogItem, List categories) : base(shopCatalogItem, categories) { + Sku = shopCatalogItem.Sku; + Rating = shopCatalogItem.Rating; + Price = shopCatalogItem.Price; + NewPrice = shopCatalogItem.NewPrice; + Quantity = shopCatalogItem.Quantity; + } + public GetShopItemResponseModel(ShopItem shopCatalogItem, List categories, Locales locale) : base(shopCatalogItem, categories, locale) { Sku = shopCatalogItem.Sku; Rating = shopCatalogItem.Rating; diff --git a/webapi/WeatherForecast/Services/BlogItemService.cs b/webapi/WeatherForecast/Services/BlogItemService.cs index 6edab92..8bbca90 100644 --- a/webapi/WeatherForecast/Services/BlogItemService.cs +++ b/webapi/WeatherForecast/Services/BlogItemService.cs @@ -10,7 +10,7 @@ namespace WeatherForecast.Services { public interface IBlogItemService { (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel); (GetBlogItemResponseModel, IDomainResult) Get(Guid siteId, Guid blogId); - (GetBlogItemResponseModel, IDomainResult) Get(Guid siteId, string slug); + (GetBlogItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug); (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData); IDomainResult Delete(Guid siteId, Guid blogId); } @@ -22,10 +22,12 @@ namespace WeatherForecast.Services { public BlogItemService( ILogger logger, - IBlogCatalogDataProvider blogCatalogDataProvider + IBlogCatalogDataProvider blogCatalogDataProvider, + ICategoryDataProvider categoryDataProvider ) { _logger = logger; _blogCatalogDataProvider = blogCatalogDataProvider; + _categoryDataProvider = categoryDataProvider; } public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) { @@ -40,18 +42,18 @@ namespace WeatherForecast.Services { var categories = new List(); foreach (var catId in item.Categories) { - var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); if (!getCategoryResult.IsSuccess || category == null) return (null, getCategoryResult); categories.Add(category); } - return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, Locales.Us)); + return IDomainResult.Success(new GetBlogItemResponseModel(item, categories)); } - public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { - var (item, result) = _blogCatalogDataProvider.Get(siteId, slug); + public (GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { + var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug); if (!result.IsSuccess || item == null) return (null, result); @@ -60,7 +62,7 @@ namespace WeatherForecast.Services { var categories = new List(); foreach (var catId in item.Categories) { - var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); if (!getCategoryResult.IsSuccess || category == null) return (null, getCategoryResult); diff --git a/webapi/WeatherForecast/Services/BlogItemsService.cs b/webapi/WeatherForecast/Services/BlogItemsService.cs index 3530b02..169953f 100644 --- a/webapi/WeatherForecast/Services/BlogItemsService.cs +++ b/webapi/WeatherForecast/Services/BlogItemsService.cs @@ -36,7 +36,7 @@ namespace WeatherForecast.Services { foreach (var item in items) { var categories = new List(); foreach (var catId in item.Categories) { - var (cat, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); if (!getCategoryResult.IsSuccess || cat == null) return (null, getCategoryResult); diff --git a/webapi/WeatherForecast/Services/CategoryItemService.cs b/webapi/WeatherForecast/Services/CategoryItemService.cs index 5885083..eb3629f 100644 --- a/webapi/WeatherForecast/Services/CategoryItemService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemService.cs @@ -8,7 +8,7 @@ namespace WeatherForecast.Services { public interface ICategoryItemService { (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel); (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId); - (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, string slug); + (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData); IDomainResult Delete(Guid siteId, Guid categoryId); } @@ -27,7 +27,7 @@ namespace WeatherForecast.Services { } public (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel) { - var (_, getResult) = _categoryDataProvider.Get(siteId, requestModel.L10n.Select(x => x.Slug).ToList()); + var (_, getResult) = _categoryDataProvider.GetBySlugs(siteId, requestModel.L10n.Select(x => x.Slug).ToList()); if (getResult.IsSuccess) return IDomainResult.Failed(); @@ -51,8 +51,8 @@ namespace WeatherForecast.Services { return IDomainResult.Success(new GetCategoryItemResponseModel(item)); } - public (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { - var (item, result) = _categoryDataProvider.Get(siteId, slug); + public (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { + var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug); if (!result.IsSuccess || item == null) return (null, result); diff --git a/webapi/WeatherForecast/Services/CategoryItemsService.cs b/webapi/WeatherForecast/Services/CategoryItemsService.cs index 4941853..a153eb1 100644 --- a/webapi/WeatherForecast/Services/CategoryItemsService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemsService.cs @@ -1,4 +1,5 @@ -using Core.Enumerations; +using Core.Abstractions; +using Core.Enumerations; using DataProviders; using DomainResults.Common; using WeatherForecast.Models.Responses; @@ -6,7 +7,7 @@ using WeatherForecast.Models.Responses; namespace WeatherForecast.Services { public interface ICategoryItemsService { - (List?, IDomainResult) Get(Guid siteId, Locales locale); + (List?, IDomainResult) Get(Guid siteId, string? locale); IDomainResult Delete(Guid siteId); } @@ -23,12 +24,16 @@ namespace WeatherForecast.Services { _categoryDataProvider = categoryDataProvider; } - public (List?, IDomainResult) Get(Guid siteId, Locales locale) { + public (List?, IDomainResult) Get(Guid siteId, string? locale) { var (items, result) = _categoryDataProvider.GetAll(siteId); if (!result.IsSuccess || items == null) return (null, result); - return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x, locale)).ToList()); + 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 GetCategoryItemResponseModel(x)).ToList()); } public IDomainResult Delete(Guid siteId) => _categoryDataProvider.DeleteAll(siteId); diff --git a/webapi/WeatherForecast/Services/ShopItemService.cs b/webapi/WeatherForecast/Services/ShopItemService.cs index 270c32b..7e1da27 100644 --- a/webapi/WeatherForecast/Services/ShopItemService.cs +++ b/webapi/WeatherForecast/Services/ShopItemService.cs @@ -12,6 +12,8 @@ namespace WeatherForecast.Services { public interface IShopItemService { (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel); (GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku); + + (GetShopItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug); (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData); IDomainResult Delete(Guid siteId, string sku); } @@ -77,14 +79,34 @@ namespace WeatherForecast.Services { var categories = new List(); foreach (var catId in item.Categories) { - var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); if (!getCategoryResult.IsSuccess || category == null) return (null, getCategoryResult); categories.Add(category); } - return IDomainResult.Success(new GetShopItemResponseModel(item, categories, Locales.Us)); + return IDomainResult.Success(new GetShopItemResponseModel(item, categories)); + } + + public (GetShopItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug) { + var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug); + + if (!result.IsSuccess || item == null) + return (null, result); + + var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us; + + var categories = new List(); + foreach (var catId in item.Categories) { + var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); + if (!getCategoryResult.IsSuccess || category == null) + return (null, getCategoryResult); + + categories.Add(category); + } + + return IDomainResult.Success(new GetShopItemResponseModel(item, categories, locale)); } public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) { diff --git a/webapi/WeatherForecast/Services/ShopItemsService.cs b/webapi/WeatherForecast/Services/ShopItemsService.cs index e80f240..c900d40 100644 --- a/webapi/WeatherForecast/Services/ShopItemsService.cs +++ b/webapi/WeatherForecast/Services/ShopItemsService.cs @@ -38,7 +38,7 @@ namespace WeatherForecast.Services { foreach (var item in items) { var categories = new List(); foreach (var catId in item.Categories) { - var (cat, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); if (!getCategoryResult.IsSuccess || cat == null) return (null, getCategoryResult);