diff --git a/webapi/DataProviders/BlogCatalogDataProvider.cs b/webapi/DataProviders/BlogCatalogDataProvider.cs index 1d7ac0a..b18471c 100644 --- a/webapi/DataProviders/BlogCatalogDataProvider.cs +++ b/webapi/DataProviders/BlogCatalogDataProvider.cs @@ -1,20 +1,19 @@ -using Core.DomainObjects.Documents; -using DataProviders.Abstractions; +using Microsoft.Extensions.Logging; + using DomainResults.Common; -using Microsoft.Extensions.Logging; + using MongoDB.Bson.Serialization; using MongoDB.Driver; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + +using DataProviders.Abstractions; +using Core.DomainObjects.Documents; 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); (List?, IDomainResult) GetAll(Guid siteId, int skip, int take); (Guid?, IDomainResult) Update(BlogItem blogItem); IDomainResult Delete(Guid id); @@ -35,8 +34,20 @@ namespace DataProviders { public (Guid?, IDomainResult) Insert(BlogItem blogItem) => Insert(blogItem, _collectionName); - public (BlogItem?, IDomainResult) Get(Guid siteId, string slug) { - var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Where(y => y.Slug == slug).Count() > 0, _collectionName); + public (BlogItem?, IDomainResult) Get(Guid siteId, Guid blogId) { + var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.Id == blogId, _collectionName); + + if (!result.IsSuccess || list == null) + return (null, result); + + 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); if (!result.IsSuccess || list == null) return (null, result); diff --git a/webapi/DataProviders/CategoryDataProvider.cs b/webapi/DataProviders/CategoryDataProvider.cs index a226f70..be095c0 100644 --- a/webapi/DataProviders/CategoryDataProvider.cs +++ b/webapi/DataProviders/CategoryDataProvider.cs @@ -13,9 +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); - (List?, IDomainResult) GetAll(Guid siteId); (Guid?, IDomainResult) Update(Category obj); IDomainResult Delete(Guid id); @@ -44,6 +43,9 @@ 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); @@ -53,15 +55,6 @@ namespace DataProviders { return (list.First(), result); } - public (Category?, IDomainResult) Get(Guid siteId, string slug) { - var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Where(x => x.Slug == slug).Count() > 0 , _collectionName); - - if (!result.IsSuccess || list == null) - return (null, result); - - return (list.First(), result); - } - public (List?, IDomainResult) GetAll(Guid siteId) => GetWithPredicate(x => x.SiteId == siteId, _collectionName); diff --git a/webapi/DataProviders/ShopCartDataProvider.cs b/webapi/DataProviders/ShopCartDataProvider.cs index 5db259c..0c82ed4 100644 --- a/webapi/DataProviders/ShopCartDataProvider.cs +++ b/webapi/DataProviders/ShopCartDataProvider.cs @@ -16,6 +16,7 @@ namespace DataProviders { (ShopCartItem?, IDomainResult) Get(Guid siteId, Guid userId, string sku); (Guid?, IDomainResult) Update(ShopCartItem shopCart); IDomainResult Delete(Guid id); + IDomainResult DeleteAll(Guid siteId, Guid userId); } public class ShopCartDataProvider : DataProviderBase, IShopCartDataProvider { @@ -47,5 +48,8 @@ namespace DataProviders { public IDomainResult Delete(Guid id) => DeleteWithPredicate(x => x.Id == id, _collectionName); + + public IDomainResult DeleteAll(Guid siteId, Guid userId) => + DeleteWithPredicate(x => x.SiteId == siteId && x.UserId == userId, _collectionName); } } diff --git a/webapi/DataProviders/ShopCatalogDataProvider.cs b/webapi/DataProviders/ShopCatalogDataProvider.cs index a150300..7cfee55 100644 --- a/webapi/DataProviders/ShopCatalogDataProvider.cs +++ b/webapi/DataProviders/ShopCatalogDataProvider.cs @@ -12,6 +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); (List?, IDomainResult) GetAll(Guid siteId, int skip, int take); (Guid?, IDomainResult) Update(ShopItem shopCart); IDomainResult Delete(Guid id); @@ -41,6 +43,18 @@ 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); + + if (!result.IsSuccess || list == null) + return (null, result); + + return (list.First(), result); + } + 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 50cd7de..2b3f7be 100644 --- a/webapi/WeatherForecast/Controllers/BlogItemController.cs +++ b/webapi/WeatherForecast/Controllers/BlogItemController.cs @@ -1,5 +1,10 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using Core.Abstractions; +using Core.Enumerations; +using WeatherForecast.Services; +using DomainResults.Mvc; +using WeatherForecast.Models.Requests; namespace WeatherForecast.Controllers { @@ -9,18 +14,72 @@ namespace WeatherForecast.Controllers { public class BlogItemController : ControllerBase { private readonly ILogger _logger; + private readonly IBlogItemService _blogItemService; - public BlogItemController(ILogger logger) { + public BlogItemController( + ILogger logger, + IBlogItemService blogItemService + ) { _logger = logger; + _blogItemService = blogItemService; } /// /// /// + /// + /// /// - [HttpGet] - public IActionResult Get() { - return Ok(); + [HttpPost("{siteId}")] + public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostBlogItemRequestModel requestData) { + var result = _blogItemService.Post(siteId, requestData); + return result.ToActionResult(); + } + + /// + /// Returns full object + /// + /// + [HttpGet("{siteId}/{blogId}")] + public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid blogId) { + var result = _blogItemService.Get(siteId, blogId); + return result.ToActionResult(); + } + + /// + /// Returns localized object + /// + /// + /// + [HttpGet("{siteId}")] + public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { + var result = _blogItemService.Get(siteId, slug); + return result.ToActionResult(); + } + + /// + /// + /// + /// + /// + /// + /// + [HttpPut("{siteId}/{blogId}")] + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] PutBlogItemRequestModel requestData) { + var result = _blogItemService.Update(siteId, blogId, requestData); + return result.ToActionResult(); + } + + /// + /// + /// + /// + /// + /// + [HttpDelete("{siteId}/{blogId}")] + public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid blogId) { + var result = _blogItemService.Delete(siteId, blogId); + return result.ToActionResult(); } } } diff --git a/webapi/WeatherForecast/Controllers/CategoryItemController.cs b/webapi/WeatherForecast/Controllers/CategoryItemController.cs index ea271e2..62cba82 100644 --- a/webapi/WeatherForecast/Controllers/CategoryItemController.cs +++ b/webapi/WeatherForecast/Controllers/CategoryItemController.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Authorization; using WeatherForecast.Services; using DomainResults.Mvc; using WeatherForecast.Models.Requests; +using Core.Enumerations; +using Core.Abstractions; namespace WeatherForecast.Controllers { @@ -12,7 +14,7 @@ namespace WeatherForecast.Controllers { public class CategoryItemController : ControllerBase { private readonly ILogger _logger; - private readonly ICategoryItemService _categoryItemService; + private readonly ICategoryItemService _categoryItemService; public CategoryItemController( ILogger logger, @@ -21,29 +23,64 @@ namespace WeatherForecast.Controllers { _categoryItemService = categoryItemService; } - /// /// /// /// - /// + /// /// [HttpPost("{siteId}")] - public IActionResult Get([FromRoute] Guid siteId, [FromBody] PostCategoryItemRequestModel requestData) { + public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostCategoryItemRequestModel requestData) { var result = _categoryItemService.Post(siteId, requestData); return result.ToActionResult(); } /// - /// + /// Returns full object /// /// - /// + /// /// [HttpGet("{siteId}/{categoryId}")] public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid categoryId) { var result = _categoryItemService.Get(siteId, categoryId); return result.ToActionResult(); } + + /// + /// Returns localized object + /// + /// + /// + [HttpGet("{siteId}")] + public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { + var result = _categoryItemService.Get(siteId, slug); + return result.ToActionResult(); + } + + /// + /// + /// + /// + /// + /// + /// + [HttpPut("{siteId}/{categoryId}")] + public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid categoryId, [FromBody] PutCategoryItemRequestModel requestData) { + var result = _categoryItemService.Update(siteId, categoryId, requestData); + return result.ToActionResult(); + } + + /// + /// + /// + /// + /// + /// + [HttpDelete("{siteId}/{categoryId}")] + public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid categoryId) { + var result = _categoryItemService.Delete(siteId, categoryId); + return result.ToActionResult(); + } } } diff --git a/webapi/WeatherForecast/Controllers/ShopCartItemsController.cs b/webapi/WeatherForecast/Controllers/ShopCartItemsController.cs index 51146a9..aeee60f 100644 --- a/webapi/WeatherForecast/Controllers/ShopCartItemsController.cs +++ b/webapi/WeatherForecast/Controllers/ShopCartItemsController.cs @@ -41,6 +41,13 @@ namespace WeatherForecast.Controllers { var result = _shopCartItemsService.Get(siteId, userId, Enumeration.FromDisplayName(locale) ?? Locales.Us); return result.ToActionResult(); } + + + [HttpDelete("{siteId}/{userId}")] + public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid userId) { + var result = _shopCartItemsService.Delete(siteId, userId); + return result.ToActionResult(); + } } } diff --git a/webapi/WeatherForecast/Controllers/ShopItemController.cs b/webapi/WeatherForecast/Controllers/ShopItemController.cs index cbad377..e100142 100644 --- a/webapi/WeatherForecast/Controllers/ShopItemController.cs +++ b/webapi/WeatherForecast/Controllers/ShopItemController.cs @@ -38,14 +38,25 @@ namespace WeatherForecast.Controllers { } /// - /// + /// Returns full object /// /// /// /// [HttpGet("{siteId}/{sku}")] - public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku, [FromQuery] string locale) { - var result = _shopItemService.Get(siteId, sku, Enumeration.FromDisplayName(locale) ?? Locales.Us); + public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku) { + var result = _shopItemService.Get(siteId, sku); + return result.ToActionResult(); + } + + /// + /// Returns localized object + /// + /// + /// + [HttpGet("{siteId}")] + public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { + var result = _shopItemService.Get(siteId, slug); return result.ToActionResult(); } diff --git a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs b/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs index 13e6f85..f677d28 100644 --- a/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs +++ b/webapi/WeatherForecast/Models/L10n/CategoryL10nModel.cs @@ -4,13 +4,19 @@ using Core.DomainObjects.L10n; using Core.Enumerations; namespace WeatherForecast.Models.L10n { - public class CategoryL10nModel : RequestModelBase { + public class CategoryL10nModel : ModelBase { public string Locale { get; set; } public string Slug { get; set; } public string Text { get; set; } - public override CategoryL10n ToDomainObject() => new CategoryL10n { + public CategoryL10nModel(CategoryL10n categoryL10n) { + Locale = categoryL10n.Locale.Name; + Slug = categoryL10n.Slug; + Text = categoryL10n.Text; + } + + public CategoryL10n ToDomainObject() => new CategoryL10n { Locale = Enumeration.FromDisplayName(Locale), Slug = Slug, Text = Text diff --git a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs b/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs index 9f44158..6f8e261 100644 --- a/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs +++ b/webapi/WeatherForecast/Models/L10n/PostItemL10nModel.cs @@ -4,7 +4,7 @@ using Core.DomainObjects.L10n; using Core.Enumerations; namespace WeatherForecast.Models.L10n { - public class PostItemL10nModel : RequestModelBase { + public class PostItemL10nModel : ModelBase { public string Locale { get; set; } public string Slug { get; set; } @@ -17,7 +17,18 @@ namespace WeatherForecast.Models.L10n { public string ContentType { get; set; } public List Badges { get; set; } - public override PostItemL10n ToDomainObject() => new PostItemL10n { + public PostItemL10nModel(PostItemL10n postItemL10n) { + Locale = postItemL10n.Locale.Name; + Slug = postItemL10n.Slug; + Description = postItemL10n.Description; + Title = postItemL10n.Title; + ShortText = postItemL10n.ShortText; + Text = postItemL10n.Text; + ContentType = postItemL10n.ContentType.Name; + Badges = postItemL10n.Badges; + } + + public PostItemL10n ToDomainObject() => new PostItemL10n { Locale = Enumeration.FromDisplayName(Locale), Slug = Slug, Description = Description, @@ -32,6 +43,4 @@ namespace WeatherForecast.Models.L10n { Badges = Badges }; } - - } diff --git a/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs new file mode 100644 index 0000000..02b7c0f --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/PostBlogItemRequestModel.cs @@ -0,0 +1,10 @@ +using Core.Abstractions.Models; +using Core.DomainObjects.Documents; + +namespace WeatherForecast.Models.Requests { + public class PostBlogItemRequestModel : RequestModelBase { + public override BlogItem ToDomainObject() { + throw new NotImplementedException(); + } + } +} diff --git a/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs index 9609226..bcb6d2a 100644 --- a/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs +++ b/webapi/WeatherForecast/Models/Requests/PostCategoryItemRequestModel.cs @@ -1,13 +1,14 @@ 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() { - throw new NotImplementedException(); - } + public override Category ToDomainObject() => new Category { + L10n = L10n.Select(x => x.ToDomainObject()).ToList() + }; } } diff --git a/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs new file mode 100644 index 0000000..6c014b8 --- /dev/null +++ b/webapi/WeatherForecast/Models/Requests/PutBlogItemRequestModel.cs @@ -0,0 +1,10 @@ +using Core.Abstractions.Models; +using Core.DomainObjects.Documents; + +namespace WeatherForecast.Models.Requests { + public class PutBlogItemRequestModel : RequestModelBase { + public override BlogItem ToDomainObject() { + throw new NotImplementedException(); + } + } +} diff --git a/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs b/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs index e1dc35a..430e5c0 100644 --- a/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs +++ b/webapi/WeatherForecast/Models/Requests/PutCategoryItemRequestModel.cs @@ -1,10 +1,12 @@ using Core.Abstractions.Models; using Core.DomainObjects; +using WeatherForecast.Models.L10n; namespace WeatherForecast.Models.Requests { public class PutCategoryItemRequestModel : RequestModelBase { - public override Category ToDomainObject() { - throw new NotImplementedException(); - } + public List L10n { get; set; } + public override Category ToDomainObject() => new Category { + L10n = L10n.Select(x => x.ToDomainObject()).ToList() + }; } } diff --git a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs b/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs index a214788..b236937 100644 --- a/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs +++ b/webapi/WeatherForecast/Models/Responses/GetCategoryItemResponseModel.cs @@ -1,12 +1,19 @@ using Core.Abstractions.Models; using Core.DomainObjects; using Core.Enumerations; +using WeatherForecast.Models.L10n; namespace WeatherForecast.Models.Responses { public class GetCategoryItemResponseModel : ResponseModelBase { - public string Slug { get; set; } - public string Text { get; set; } + public string? Slug { get; set; } + public string? Text { get; set; } + + public List? L10n { get; set; } + + public GetCategoryItemResponseModel(Category category) { + L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); + } public GetCategoryItemResponseModel(Category category, Locales locale) { var l10n = category.L10n.SingleOrDefault(x => x.Locale == locale); diff --git a/webapi/WeatherForecast/Program.cs b/webapi/WeatherForecast/Program.cs index 73de067..93f7582 100644 --- a/webapi/WeatherForecast/Program.cs +++ b/webapi/WeatherForecast/Program.cs @@ -1,3 +1,5 @@ +using Serilog; + namespace WeatherForecast { public class Program { public static void Main(string[] args) { @@ -6,6 +8,10 @@ namespace WeatherForecast { public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .UseSerilog((hostContext, services, configuration) => { + configuration.ReadFrom.Configuration(hostContext.Configuration) + .Enrich.FromLogContext(); + }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); diff --git a/webapi/WeatherForecast/Services/BlogItemService.cs b/webapi/WeatherForecast/Services/BlogItemService.cs new file mode 100644 index 0000000..6edab92 --- /dev/null +++ b/webapi/WeatherForecast/Services/BlogItemService.cs @@ -0,0 +1,81 @@ +using Core.DomainObjects; +using Core.Enumerations; +using DataProviders; +using DomainResults.Common; +using WeatherForecast.Models.Requests; +using WeatherForecast.Models.Responses; + +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); + (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData); + IDomainResult Delete(Guid siteId, Guid blogId); + } + + public class BlogItemService : IBlogItemService { + private readonly ILogger _logger; + private readonly IBlogCatalogDataProvider _blogCatalogDataProvider; + private readonly ICategoryDataProvider _categoryDataProvider; + + public BlogItemService( + ILogger logger, + IBlogCatalogDataProvider blogCatalogDataProvider + ) { + _logger = logger; + _blogCatalogDataProvider = blogCatalogDataProvider; + } + + public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) { + throw new NotImplementedException(); + } + + public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) { + var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId); + + if (!result.IsSuccess || item == null) + return (null, result); + + var categories = new List(); + foreach (var catId in item.Categories) { + var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); + if (!getCategoryResult.IsSuccess || category == null) + return (null, getCategoryResult); + + categories.Add(category); + } + + return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, Locales.Us)); + } + + public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { + var (item, result) = _blogCatalogDataProvider.Get(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(catId, siteId); + if (!getCategoryResult.IsSuccess || category == null) + return (null, getCategoryResult); + + categories.Add(category); + } + + return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, locale)); + } + + public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData) { + throw new NotImplementedException(); + } + + public IDomainResult Delete(Guid siteId, Guid blogId) { + throw new NotImplementedException(); + } + } +} diff --git a/webapi/WeatherForecast/Services/BlogItemsService.cs b/webapi/WeatherForecast/Services/BlogItemsService.cs index 716ecdc..3530b02 100644 --- a/webapi/WeatherForecast/Services/BlogItemsService.cs +++ b/webapi/WeatherForecast/Services/BlogItemsService.cs @@ -50,7 +50,6 @@ namespace WeatherForecast.Services { : IDomainResult.NotFound(); } - public IDomainResult Delete(Guid siteId) => - _blogCatalogDataProvider.DeleteAll(siteId); + public IDomainResult Delete(Guid siteId) => _blogCatalogDataProvider.DeleteAll(siteId); } } diff --git a/webapi/WeatherForecast/Services/CategoryItemService.cs b/webapi/WeatherForecast/Services/CategoryItemService.cs index d906218..5885083 100644 --- a/webapi/WeatherForecast/Services/CategoryItemService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemService.cs @@ -8,6 +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); (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData); IDomainResult Delete(Guid siteId, Guid categoryId); } @@ -47,7 +48,17 @@ namespace WeatherForecast.Services { if (!result.IsSuccess || item == null) return (null, result); - return IDomainResult.Success(new GetCategoryItemResponseModel(item, Locales.Us)); + return IDomainResult.Success(new GetCategoryItemResponseModel(item)); + } + + public (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { + var (item, result) = _categoryDataProvider.Get(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)); } public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData) { diff --git a/webapi/WeatherForecast/Services/CategoryItemsService.cs b/webapi/WeatherForecast/Services/CategoryItemsService.cs index 9e67968..4941853 100644 --- a/webapi/WeatherForecast/Services/CategoryItemsService.cs +++ b/webapi/WeatherForecast/Services/CategoryItemsService.cs @@ -31,10 +31,6 @@ namespace WeatherForecast.Services { return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x, locale)).ToList()); } - public IDomainResult Delete(Guid siteId) { - var resutl = _categoryDataProvider.DeleteAll(siteId); - return resutl; - } - + public IDomainResult Delete(Guid siteId) => _categoryDataProvider.DeleteAll(siteId); } } diff --git a/webapi/WeatherForecast/Services/ShopCartItemsService.cs b/webapi/WeatherForecast/Services/ShopCartItemsService.cs index 466ceb0..9b7323c 100644 --- a/webapi/WeatherForecast/Services/ShopCartItemsService.cs +++ b/webapi/WeatherForecast/Services/ShopCartItemsService.cs @@ -4,14 +4,13 @@ using WeatherForecast.Models.Responses; using DataProviders; -using Core.Abstractions; -using Core.DomainObjects.Documents; using Core.Enumerations; namespace WeatherForecast.Services { public interface IShopCartItemsService { (List?, IDomainResult) Get(Guid siteId, Guid userId, Locales locale); + IDomainResult Delete(Guid siteId, Guid userId); } public class ShopCartItemsService : IShopCartItemsService { @@ -49,5 +48,7 @@ namespace WeatherForecast.Services { ? IDomainResult.Success(items) : IDomainResult.NotFound?>(); } + + public IDomainResult Delete(Guid siteId, Guid userId) => _shopCartDataProvider.DeleteAll(siteId, userId); } } diff --git a/webapi/WeatherForecast/Services/ShopItemService.cs b/webapi/WeatherForecast/Services/ShopItemService.cs index 9edc433..270c32b 100644 --- a/webapi/WeatherForecast/Services/ShopItemService.cs +++ b/webapi/WeatherForecast/Services/ShopItemService.cs @@ -11,7 +11,7 @@ namespace WeatherForecast.Services { public interface IShopItemService { (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel); - (GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku, Locales locale); + (GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku); (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData); IDomainResult Delete(Guid siteId, string sku); } @@ -69,7 +69,7 @@ namespace WeatherForecast.Services { return IDomainResult.Success(id); } - public (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku, Locales locale) { + public (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) { var (item, result) = _shopCatalogDataProvider.Get(siteId, sku); if (!result.IsSuccess || item == null) @@ -84,7 +84,7 @@ namespace WeatherForecast.Services { categories.Add(category); } - return IDomainResult.Success(new GetShopItemResponseModel(item, categories, locale)); + return IDomainResult.Success(new GetShopItemResponseModel(item, categories, Locales.Us)); } 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 fbab807..e80f240 100644 --- a/webapi/WeatherForecast/Services/ShopItemsService.cs +++ b/webapi/WeatherForecast/Services/ShopItemsService.cs @@ -53,7 +53,6 @@ namespace WeatherForecast.Services { } - public IDomainResult Delete(Guid siteId) - => _shopCatalogDataProvider.DeleteAll(siteId); + public IDomainResult Delete(Guid siteId) => _shopCatalogDataProvider.DeleteAll(siteId); } } diff --git a/webapi/WeatherForecast/Startup.cs b/webapi/WeatherForecast/Startup.cs index 524e6e1..6e6ebcc 100644 --- a/webapi/WeatherForecast/Startup.cs +++ b/webapi/WeatherForecast/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.AspNetCore.Authentication.JwtBearer; using WeatherForecast.Services; using DataProviders.Extensions; +using System.Text.Json.Serialization; namespace WeatherForecast { public class Startup { @@ -33,10 +34,9 @@ namespace WeatherForecast { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); - - - services.AddControllers(); + services.AddControllers().AddJsonOptions(options => + options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull); // configure jwt authentication services.AddAuthentication(options => { @@ -62,7 +62,7 @@ namespace WeatherForecast { services.AddScoped(); services.AddScoped(); services.AddScoped(); - //services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/webapi/WeatherForecast/WeatherForecast.csproj b/webapi/WeatherForecast/WeatherForecast.csproj index fd99840..3f4bd9c 100644 --- a/webapi/WeatherForecast/WeatherForecast.csproj +++ b/webapi/WeatherForecast/WeatherForecast.csproj @@ -16,6 +16,11 @@ + + + + + diff --git a/webapi/WeatherForecast/appsettings.json b/webapi/WeatherForecast/appsettings.json index 87f0720..5693491 100644 --- a/webapi/WeatherForecast/appsettings.json +++ b/webapi/WeatherForecast/appsettings.json @@ -1,9 +1,17 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } + "Serilog": { + "Using": [ "Serilog.Settings.Configuration", "Serilog.Expressions", "Serilog.Sinks.Console" ], + "MinimumLevel": "Information", + "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "restrictedToMinimumLevel": "Information", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}.{Method}) {Message}{NewLine}{Exception}" + } + } + ] }, "AllowedHosts": "*", "Configuration": {