(feat): blog controllers
This commit is contained in:
parent
4d0133ada9
commit
a1071da8bf
@ -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<string> slugs);
|
||||
(List<BlogItem>?, 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<string> { slug });
|
||||
|
||||
public (BlogItem?, IDomainResult) Get(Guid siteId, List<string> 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);
|
||||
|
||||
@ -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<string> slugs);
|
||||
|
||||
(List<Category>?, 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<string> { slug });
|
||||
|
||||
public (Category?, IDomainResult) Get(Guid siteId, List<string> 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<Category>?, IDomainResult) GetAll(Guid siteId) =>
|
||||
GetWithPredicate(x => x.SiteId == siteId, _collectionName);
|
||||
|
||||
|
||||
@ -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<ShopCartItem>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<string> slugs);
|
||||
(List<ShopItem>?, 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<string> { slug });
|
||||
|
||||
public (ShopItem?, IDomainResult) Get(Guid siteId, List<string> 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<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take) =>
|
||||
GetWithPredicate(x => x.SiteId == siteId, skip, take, _collectionName);
|
||||
|
||||
|
||||
@ -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<BlogItemController> _logger;
|
||||
private readonly IBlogItemService _blogItemService;
|
||||
|
||||
public BlogItemController(ILogger<BlogItemController> logger) {
|
||||
public BlogItemController(
|
||||
ILogger<BlogItemController> logger,
|
||||
IBlogItemService blogItemService
|
||||
) {
|
||||
_logger = logger;
|
||||
_blogItemService = blogItemService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="requestData"></param>
|
||||
/// <returns></returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns full object
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}/{blogId}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid blogId) {
|
||||
var result = _blogItemService.Get(siteId, blogId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns localized object
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}")]
|
||||
public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) {
|
||||
var result = _blogItemService.Get(siteId, slug);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="blogId"></param>
|
||||
/// <param name="requestData"></param>
|
||||
/// <returns></returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="blogId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{siteId}/{blogId}")]
|
||||
public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid blogId) {
|
||||
var result = _blogItemService.Delete(siteId, blogId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -21,29 +23,64 @@ namespace WeatherForecast.Controllers {
|
||||
_categoryItemService = categoryItemService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="requestData"></param>
|
||||
/// <returns></returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns full object
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="categoryId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}/{categoryId}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid categoryId) {
|
||||
var result = _categoryItemService.Get(siteId, categoryId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns localized object
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}")]
|
||||
public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) {
|
||||
var result = _categoryItemService.Get(siteId, slug);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="categoryId"></param>
|
||||
/// <param name="requestData"></param>
|
||||
/// <returns></returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="categoryId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{siteId}/{categoryId}")]
|
||||
public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid categoryId) {
|
||||
var result = _categoryItemService.Delete(siteId, categoryId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,5 +42,12 @@ namespace WeatherForecast.Controllers {
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("{siteId}/{userId}")]
|
||||
public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid userId) {
|
||||
var result = _shopCartItemsService.Delete(siteId, userId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,14 +38,25 @@ namespace WeatherForecast.Controllers {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns full object
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="sku"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}/{sku}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku, [FromQuery] string locale) {
|
||||
var result = _shopItemService.Get(siteId, sku, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us);
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku) {
|
||||
var result = _shopItemService.Get(siteId, sku);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns localized object
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}")]
|
||||
public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) {
|
||||
var result = _shopItemService.Get(siteId, slug);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
|
||||
@ -4,13 +4,19 @@ using Core.DomainObjects.L10n;
|
||||
using Core.Enumerations;
|
||||
|
||||
namespace WeatherForecast.Models.L10n {
|
||||
public class CategoryL10nModel : RequestModelBase<CategoryL10n> {
|
||||
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<Locales>(Locale),
|
||||
Slug = Slug,
|
||||
Text = Text
|
||||
|
||||
@ -4,7 +4,7 @@ using Core.DomainObjects.L10n;
|
||||
using Core.Enumerations;
|
||||
|
||||
namespace WeatherForecast.Models.L10n {
|
||||
public class PostItemL10nModel : RequestModelBase<PostItemL10n> {
|
||||
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<string> 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<Locales>(Locale),
|
||||
Slug = Slug,
|
||||
Description = Description,
|
||||
@ -32,6 +43,4 @@ namespace WeatherForecast.Models.L10n {
|
||||
Badges = Badges
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PostBlogItemRequestModel : RequestModelBase<BlogItem> {
|
||||
public override BlogItem ToDomainObject() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<Category> {
|
||||
|
||||
public List<CategoryL10nModel> L10n { get; set; }
|
||||
public override Category ToDomainObject() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override Category ToDomainObject() => new Category {
|
||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PutBlogItemRequestModel : RequestModelBase<BlogItem> {
|
||||
public override BlogItem ToDomainObject() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects;
|
||||
using WeatherForecast.Models.L10n;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PutCategoryItemRequestModel : RequestModelBase<Category> {
|
||||
public override Category ToDomainObject() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public List<CategoryL10nModel> L10n { get; set; }
|
||||
public override Category ToDomainObject() => new Category {
|
||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<CategoryL10nModel>? 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);
|
||||
|
||||
@ -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<Startup>();
|
||||
});
|
||||
|
||||
81
webapi/WeatherForecast/Services/BlogItemService.cs
Normal file
81
webapi/WeatherForecast/Services/BlogItemService.cs
Normal file
@ -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<BlogItemService> _logger;
|
||||
private readonly IBlogCatalogDataProvider _blogCatalogDataProvider;
|
||||
private readonly ICategoryDataProvider _categoryDataProvider;
|
||||
|
||||
public BlogItemService(
|
||||
ILogger<BlogItemService> 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<Category>();
|
||||
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<Category>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,6 @@ namespace WeatherForecast.Services {
|
||||
: IDomainResult.NotFound<GetBlogItemsResponseModel?>();
|
||||
}
|
||||
|
||||
public IDomainResult Delete(Guid siteId) =>
|
||||
_blogCatalogDataProvider.DeleteAll(siteId);
|
||||
public IDomainResult Delete(Guid siteId) => _blogCatalogDataProvider.DeleteAll(siteId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<GetShopCartItemResponseModel>?, 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<List<GetShopCartItemResponseModel>?>();
|
||||
}
|
||||
|
||||
public IDomainResult Delete(Guid siteId, Guid userId) => _shopCartDataProvider.DeleteAll(siteId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -53,7 +53,6 @@ namespace WeatherForecast.Services {
|
||||
}
|
||||
|
||||
|
||||
public IDomainResult Delete(Guid siteId)
|
||||
=> _shopCatalogDataProvider.DeleteAll(siteId);
|
||||
public IDomainResult Delete(Guid siteId) => _shopCatalogDataProvider.DeleteAll(siteId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
@ -34,9 +35,8 @@ namespace WeatherForecast {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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<IShopItemsService, ShopItemsService>();
|
||||
services.AddScoped<IShopCartItemService, ShopCartItemService>();
|
||||
services.AddScoped<IShopCartItemsService, ShopCartItemsService>();
|
||||
//services.AddScoped<IBlogItemService, BlogItemService>();
|
||||
services.AddScoped<IBlogItemService, BlogItemService>();
|
||||
services.AddScoped<IBlogItemsService, BlogItemsService>();
|
||||
services.AddScoped<ICategoryItemService, CategoryItemService>();
|
||||
services.AddScoped<ICategoryItemsService, CategoryItemsService>();
|
||||
|
||||
@ -16,6 +16,11 @@
|
||||
<PackageReference Include="DomainResult" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user