(refactor): code review
This commit is contained in:
parent
d7fcc49e72
commit
9c97e50c53
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,10 @@ namespace Core.DomainObjects.Documents {
|
|||||||
hash = hash * 23 + Images.Sum(x => x.GetHashCode());
|
hash = hash * 23 + Images.Sum(x => x.GetHashCode());
|
||||||
hash = hash * 23 + Author.GetHashCode();
|
hash = hash * 23 + Author.GetHashCode();
|
||||||
hash = hash * 23 + Created.GetHashCode();
|
hash = hash * 23 + Created.GetHashCode();
|
||||||
|
if(Tags != null)
|
||||||
hash = hash * 23 + Tags.Sum(x => x.GetHashCode());
|
hash = hash * 23 + Tags.Sum(x => x.GetHashCode());
|
||||||
|
|
||||||
|
if(Categories != null)
|
||||||
hash = hash * 23 + Categories.Sum(x => x.GetHashCode());
|
hash = hash * 23 + Categories.Sum(x => x.GetHashCode());
|
||||||
|
|
||||||
hash = hash * 23 + ReadTime.GetHashCode();
|
hash = hash * 23 + ReadTime.GetHashCode();
|
||||||
|
|||||||
@ -65,6 +65,6 @@ namespace DataProviders {
|
|||||||
DeleteWithPredicate(x => x.Id == id, _collectionName);
|
DeleteWithPredicate(x => x.Id == id, _collectionName);
|
||||||
|
|
||||||
public IDomainResult DeleteAll(Guid siteId) =>
|
public IDomainResult DeleteAll(Guid siteId) =>
|
||||||
DeleteWithPredicate(x => x.SiteId == siteId, _collectionName);
|
DeleteManyWithPredicate(x => x.SiteId == siteId, _collectionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,6 @@ namespace DataProviders {
|
|||||||
DeleteWithPredicate(x => x.Id == id, _collectionName);
|
DeleteWithPredicate(x => x.Id == id, _collectionName);
|
||||||
|
|
||||||
public IDomainResult DeleteAll(Guid siteId, Guid userId) =>
|
public IDomainResult DeleteAll(Guid siteId, Guid userId) =>
|
||||||
DeleteWithPredicate(x => x.SiteId == siteId && x.UserId == userId, _collectionName);
|
DeleteManyWithPredicate(x => x.SiteId == siteId && x.UserId == userId, _collectionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,14 @@ namespace ExtensionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
return Test.GetHashCode();
|
unchecked {
|
||||||
|
int hash = 17;
|
||||||
|
|
||||||
|
if (Test != null)
|
||||||
|
hash = hash * 23 + Test.GetHashCode();
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ namespace ExtensionsTests {
|
|||||||
public class ObjectExtensions {
|
public class ObjectExtensions {
|
||||||
|
|
||||||
private class DummyClass {
|
private class DummyClass {
|
||||||
public string Test { get; set; }
|
public string? Test { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@ -17,12 +17,12 @@ using System.Threading.Tasks;
|
|||||||
namespace ExtensionsTests {
|
namespace ExtensionsTests {
|
||||||
public class StringExtensions : ServicesBase {
|
public class StringExtensions : ServicesBase {
|
||||||
|
|
||||||
private readonly Configuration _configuration;
|
// private readonly Configuration _configuration;
|
||||||
|
|
||||||
public StringExtensions() {
|
// public StringExtensions() {
|
||||||
_configuration = ServiceProvider.GetService<IOptions<Configuration>>()?.Value
|
// _configuration = ServiceProvider.GetService<IOptions<Configuration>>()?.Value
|
||||||
?? throw new NullReferenceException("Configuration not found");
|
// ?? throw new NullReferenceException("Configuration not found");
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -93,7 +93,7 @@ namespace ExtensionsTests {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ToNullableInt() {
|
public void ToNullableInt() {
|
||||||
var value = "0".ToNullableInt();
|
var value = "0".ToNullableInt();
|
||||||
Assert.True(value.GetType() == typeof(int) && value == 0 && "".ToNullableInt() == null);
|
Assert.True(value != null && value.GetType() == typeof(int?) && value == 0 && "".ToNullableInt() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -105,7 +105,7 @@ namespace ExtensionsTests {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ToNullableUint() {
|
public void ToNullableUint() {
|
||||||
var value = "0".ToNullableUint();
|
var value = "0".ToNullableUint();
|
||||||
Assert.True(value.GetType() == typeof(uint) && value == 0 && "".ToNullableUint() == null);
|
Assert.True(value != null && value.GetType() == typeof(uint) && value == 0 && "".ToNullableUint() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -117,7 +117,7 @@ namespace ExtensionsTests {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ToNullableDecimal() {
|
public void ToNullableDecimal() {
|
||||||
var value = "0".ToNullableDecimal();
|
var value = "0".ToNullableDecimal();
|
||||||
Assert.True(value.GetType() == typeof(decimal) && "".ToNullableDecimal() == null);
|
Assert.True(value != null && value.GetType() == typeof(decimal) && "".ToNullableDecimal() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -129,7 +129,7 @@ namespace ExtensionsTests {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ToNullableDouble() {
|
public void ToNullableDouble() {
|
||||||
var value = "0".ToNullableDouble();
|
var value = "0".ToNullableDouble();
|
||||||
Assert.True(value.GetType() == typeof(double) && value == 0 && "".ToNullableDouble() == null);
|
Assert.True(value != null && value.GetType() == typeof(double) && value == 0 && "".ToNullableDouble() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -163,7 +163,12 @@ namespace ExtensionsTests {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToNullalbeBool() {
|
public void ToNullalbeBool() {
|
||||||
Assert.True("true".ToNullableBool().Value && !"false".ToNullableBool().Value && "".ToNullableBool() == null);
|
var trueTest = "true".ToNullableBool();
|
||||||
|
var falseTest = "false".ToNullableBool();
|
||||||
|
if (trueTest == null || falseTest == null)
|
||||||
|
Assert.False(true);
|
||||||
|
else
|
||||||
|
Assert.True(trueTest.Value && !falseTest.Value && "".ToNullableBool() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -195,12 +200,16 @@ namespace ExtensionsTests {
|
|||||||
public void Excerpt() => Assert.Equal("M...", "MAKS-IT".Excerpt(4));
|
public void Excerpt() => Assert.Equal("M...", "MAKS-IT".Excerpt(4));
|
||||||
|
|
||||||
private class DummyClass {
|
private class DummyClass {
|
||||||
public string Test { get; set; }
|
public string? Test { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToObject() {
|
public void ToObject() {
|
||||||
var obj = "{ \"Test\": \"Test\" }".ToObject<DummyClass>();
|
var obj = "{ \"Test\": \"Test\" }".ToObject<DummyClass>();
|
||||||
|
|
||||||
|
if (obj == null)
|
||||||
|
Assert.False(true);
|
||||||
|
else
|
||||||
Assert.Equal("Test", obj.Test);
|
Assert.Equal("Test", obj.Test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,11 +23,6 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TitleSectionModel? TitleSection { get; set; }
|
public TitleSectionModel? TitleSection { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public PageModelBase() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ImageModel? Image { get; set; }
|
public ImageResponseModel? Image { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using Core.Abstractions.Models;
|
using Core.Abstractions.Models;
|
||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
|
using WeatherForecast.Models.Responses;
|
||||||
using WeatherForecast.Models.Responses.L10n;
|
using WeatherForecast.Models.Responses.L10n;
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Abstractions {
|
namespace WeatherForecast.Models.Abstractions {
|
||||||
@ -73,7 +74,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ImageModel>? Images { get; set; }
|
public List<ImageResponseModel>? Images { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -93,7 +94,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CategoryModel>? Categories { get; set; }
|
public List<CategoryItemResponseModel>? Categories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -121,8 +122,8 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <param name="categories"></param>
|
/// <param name="categories"></param>
|
||||||
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories) : this(postItem) {
|
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories) : this(postItem) {
|
||||||
L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList();
|
L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList();
|
||||||
Categories = categories.Select(x => new CategoryModel(x)).ToList();
|
Categories = categories.Select(x => new CategoryItemResponseModel(x)).ToList();
|
||||||
Images = postItem.Images?.Select(x => new ImageModel(x)).ToList();
|
Images = postItem.Images?.Select(x => new ImageResponseModel(x)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -133,7 +134,8 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories, Locales locale) : this(postItem) {
|
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories, Locales locale) : this(postItem) {
|
||||||
|
|
||||||
var postItemL10n = postItem.L10n.SingleOrDefault(x => x.Locale == locale);
|
var postItemL10n = postItem.L10n.Single(x => x.Locale == locale);
|
||||||
|
|
||||||
if (postItemL10n != null) {
|
if (postItemL10n != null) {
|
||||||
Slug = postItemL10n.Slug;
|
Slug = postItemL10n.Slug;
|
||||||
Badges = postItemL10n.Badges;
|
Badges = postItemL10n.Badges;
|
||||||
@ -144,8 +146,8 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
Badges = postItemL10n.Badges;
|
Badges = postItemL10n.Badges;
|
||||||
}
|
}
|
||||||
|
|
||||||
Categories = categories.Select(x => new CategoryModel(x, locale)).ToList();
|
Categories = categories.Select(x => new CategoryItemResponseModel(x, locale)).ToList();
|
||||||
Images = postItem.Images?.Select(x => new ImageModel(x, locale)).ToList();
|
Images = postItem.Images?.Select(x => new ImageResponseModel(x, locale)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,48 +0,0 @@
|
|||||||
using Core.DomainObjects;
|
|
||||||
using Core.Enumerations;
|
|
||||||
using WeatherForecast.Models.L10n;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class CategoryModel {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public List<CategoryL10nModel>? L10n { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string? Slug { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string? Text { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="category"></param>
|
|
||||||
public CategoryModel(Category category) {
|
|
||||||
L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="category"></param>
|
|
||||||
/// <param name="locale"></param>
|
|
||||||
public CategoryModel(Category category, Locales locale) {
|
|
||||||
var categoryL10n = category.L10n.SingleOrDefault(x => x.Locale == locale);
|
|
||||||
if (categoryL10n != null) {
|
|
||||||
Slug = categoryL10n.Slug;
|
|
||||||
Text = categoryL10n.Text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +1,6 @@
|
|||||||
namespace WeatherForecast.Models {
|
using Core.DomainObjects;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -8,16 +10,18 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorModel Author { get; set; }
|
public AuthorModel? Author { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Comment { get; set; }
|
public string? Comment { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CommentModel>? Responses { get; set; }
|
public List<CommentModel>? Responses { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,11 +13,6 @@ namespace WeatherForecast.Models.PageSections {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ReadTime { get; set; }
|
public string ReadTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public FeaturedBlogSectionModel() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace WeatherForecast.Models.PageSections {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ImageModel? Image { get; set; }
|
public ImageResponseModel? Image { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|||||||
@ -26,7 +26,8 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override BlogItem ToDomainObject() {
|
public override BlogItem ToDomainObject() {
|
||||||
if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException();
|
if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this)))
|
||||||
|
throw new ValidationException();
|
||||||
|
|
||||||
return new BlogItem() {
|
return new BlogItem() {
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
||||||
@ -48,16 +49,11 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="validationContext"></param>
|
/// <param name="validationContext"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate( ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (L10n.IsNullOrEmpty())
|
if (L10n.IsNullOrEmpty())
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
yield return new ValidationResult($"{nameof(L10n)} ${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();
|
private bool HasValidationErrors(BlogItemRequestModel model) => Validate(new ValidationContext(model)).Any();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,12 +38,7 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (L10n.IsNullOrEmpty())
|
if (L10n.IsNullOrEmpty())
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
yield return new ValidationResult($"{nameof(L10n)} ${Errors.NullOrEmpty}");
|
||||||
else {
|
|
||||||
foreach (var item in L10n)
|
|
||||||
foreach (var validationResult in item.Validate(validationContext))
|
|
||||||
yield return validationResult;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemberNotNullWhen(false, new[] { nameof(L10n) })]
|
[MemberNotNullWhen(false, new[] { nameof(L10n) })]
|
||||||
|
|||||||
56
webapi/WeatherForecast/Models/Requests/ImageRequestModel.cs
Normal file
56
webapi/WeatherForecast/Models/Requests/ImageRequestModel.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using Extensions;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using WeatherForecast.Models.Requests.L10n;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ImageRequestModel : RequestModelBase<Image> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public List<ImageL10nModel>? L10n { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Src { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Alt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override Image ToDomainObject() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (L10n.IsNullOrEmpty())
|
||||||
|
yield return new ValidationResult($"{nameof(L10n)} ${Errors.NullOrEmpty}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Src))
|
||||||
|
yield return new ValidationResult($"{nameof(Src)} ${Errors.NullOrWhiteSpace}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Alt))
|
||||||
|
yield return new ValidationResult($"{nameof(Alt)} ${Errors.NullOrWhiteSpace}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -50,15 +50,15 @@ namespace WeatherForecast.Models.Requests.L10n {
|
|||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (string.IsNullOrWhiteSpace(Locale))
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Slug))
|
if (string.IsNullOrWhiteSpace(Slug))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Slug)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Text))
|
if (string.IsNullOrWhiteSpace(Text))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Text)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.meziantou.net/csharp-8-nullable-reference-types.htm
|
// https://www.meziantou.net/csharp-8-nullable-reference-types.htm
|
||||||
|
|||||||
@ -42,13 +42,12 @@ namespace WeatherForecast.Models.Requests.L10n {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (string.IsNullOrWhiteSpace(Locale))
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Alt))
|
if (string.IsNullOrWhiteSpace(Alt))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Alt)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Alt) })]
|
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Alt) })]
|
||||||
|
|||||||
@ -87,29 +87,29 @@ namespace WeatherForecast.Models.Requests.L10n {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (string.IsNullOrWhiteSpace(Locale))
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
yield return new ValidationResult($"{nameof(Locale)} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Slug))
|
if (string.IsNullOrWhiteSpace(Slug))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Slug)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Description))
|
if (string.IsNullOrWhiteSpace(Description))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Description)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Title))
|
if (string.IsNullOrWhiteSpace(Title))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Title)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Text))
|
if (string.IsNullOrWhiteSpace(Text))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(Text)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(ShortText))
|
if (string.IsNullOrWhiteSpace(ShortText))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(ShortText)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(ContentType))
|
if (string.IsNullOrWhiteSpace(ContentType))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
yield return new ValidationResult($"{nameof(ContentType)} {Errors.NullOrWhiteSpace.Name}");
|
||||||
else if (Enumeration.FromDisplayName<ContentTypes>(ContentType) == null)
|
else if (Enumeration.FromDisplayName<ContentTypes>(ContentType) == null)
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
yield return new ValidationResult($"{nameof(ContentType)} {Errors.WrongOrNotManaged}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Description), nameof(Title), nameof(Text), nameof(ShortText), nameof(ContentType) })]
|
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Description), nameof(Title), nameof(Text), nameof(ShortText), nameof(ContentType) })]
|
||||||
|
|||||||
@ -36,8 +36,8 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// <param name="validationContext"></param>
|
/// <param name="validationContext"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (Quantity == null)
|
if (Quantity == null || (Quantity != null && Quantity == 0))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
yield return new ValidationResult($"{nameof(Quantity)} ${Errors.NullOrEmpty}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemberNotNullWhen(false, new[] { nameof(Quantity) })]
|
[MemberNotNullWhen(false, new[] { nameof(Quantity) })]
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
using Core.Abstractions.Models;
|
using System.ComponentModel.DataAnnotations;
|
||||||
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 System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
using WeatherForecast.Models.Abstractions;
|
using WeatherForecast.Models.Abstractions;
|
||||||
|
using Core.DomainObjects.Documents;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using Extensions;
|
||||||
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
namespace WeatherForecast.Models.Requests {
|
||||||
|
|
||||||
@ -46,7 +44,8 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override ShopItem ToDomainObject() {
|
public override ShopItem ToDomainObject() {
|
||||||
if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException();
|
if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this)))
|
||||||
|
throw new ValidationException();
|
||||||
|
|
||||||
return new ShopItem() {
|
return new ShopItem() {
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
||||||
@ -72,24 +71,19 @@ namespace WeatherForecast.Models.Requests {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (L10n.IsNullOrEmpty())
|
if (L10n.IsNullOrEmpty())
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
yield return new ValidationResult($"{nameof(L10n)} ${Errors.NullOrEmpty}");
|
||||||
else {
|
|
||||||
foreach (var item in L10n)
|
|
||||||
foreach (var validationResult in item.Validate(validationContext))
|
|
||||||
yield return validationResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(BrandName))
|
if (string.IsNullOrWhiteSpace(BrandName))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrWhiteSpace}");
|
yield return new ValidationResult($"{nameof(BrandName)} ${Errors.NullOrWhiteSpace}");
|
||||||
|
|
||||||
if (Price == null)
|
if (Price == null || (Price != null && Price == 0))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrEmpty.Name}");
|
yield return new ValidationResult($"{nameof(Price)} {Errors.NullOrEmpty.Name}");
|
||||||
|
|
||||||
if (Quantity == null)
|
if (Quantity == null || (Quantity != null && Quantity == 0))
|
||||||
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
yield return new ValidationResult($"{nameof(Quantity)} ${Errors.NullOrEmpty}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[MemberNotNullWhen(false, new[] { nameof(BrandName), nameof(Price), nameof(Quantity) })]
|
[MemberNotNullWhen(false, new[] { nameof(BrandName), nameof(Price), nameof(Quantity) })]
|
||||||
private bool HasValidationErrors(ShopItemRequestModel validationContext) => Validate(new ValidationContext(validationContext)).Any();
|
private bool HasValidationErrors(ShopItemRequestModel model) => Validate(new ValidationContext(model)).Any();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Responses {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class BlogCategoriesResponseModel : ResponseModelBase {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public List<CategoryModel>? Items { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Responses {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class BlogFeaturedResponseModel : ResponseModelBase {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public List<BlogItemModel> Items { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items"></param>
|
|
||||||
public BlogFeaturedResponseModel(List<BlogItemModel> items) {
|
|
||||||
Items = items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,12 +8,6 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BlogItemsResponseModel : PaginationModelBase<BlogItemResponseModel> {
|
public class BlogItemsResponseModel : PaginationModelBase<BlogItemResponseModel> {
|
||||||
|
|
||||||
|
|
||||||
//public BlogItemModel FeaturedBlog { get; set; }
|
|
||||||
|
|
||||||
//public List<CategoryModel> Categories { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -22,6 +16,5 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public BlogItemsResponseModel(int currentPage, int totalPages, List<BlogItemResponseModel> items)
|
public BlogItemsResponseModel(int currentPage, int totalPages, List<BlogItemResponseModel> items)
|
||||||
: base(currentPage, totalPages, items) { }
|
: base(currentPage, totalPages, items) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
using Core.Abstractions.Models;
|
using Core.Abstractions.Models;
|
||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using WeatherForecast.Models.L10n;
|
using WeatherForecast.Models.Responses.L10n;
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Responses {
|
namespace WeatherForecast.Models.Responses {
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using WeatherForecast.Models.L10n;
|
using WeatherForecast.Models.Responses.L10n;
|
||||||
|
|
||||||
namespace WeatherForecast.Models {
|
namespace WeatherForecast.Models {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ImageModel {
|
public class ImageResponseModel {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -28,7 +28,7 @@ namespace WeatherForecast.Models {
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image"></param>
|
/// <param name="image"></param>
|
||||||
public ImageModel(Image image) {
|
public ImageResponseModel(Image image) {
|
||||||
L10n = image.L10n.Select(x => new ImageL10nModel(x)).ToList();
|
L10n = image.L10n.Select(x => new ImageL10nModel(x)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +37,11 @@ namespace WeatherForecast.Models {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image"></param>
|
/// <param name="image"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public ImageModel(Image image, Locales locale) {
|
public ImageResponseModel(Image image, Locales locale) {
|
||||||
Src = image.Src;
|
Src = image.Src;
|
||||||
|
|
||||||
var l10n = image.L10n.SingleOrDefault(x => x.Locale == locale);
|
var l10n = image.L10n.Single(x => x.Locale == locale);
|
||||||
|
|
||||||
if (l10n != null) {
|
if (l10n != null) {
|
||||||
Alt = l10n.Alt;
|
Alt = l10n.Alt;
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ImageModel Image { get; set; }
|
public ImageResponseModel? Image { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -59,11 +59,6 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public uint? Quantity { get; set; }
|
public uint? Quantity { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public ShopCartItemResponseModel() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -79,13 +74,16 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
NewPrice = shopItem.NewPrice;
|
NewPrice = shopItem.NewPrice;
|
||||||
Quantity = shopCartItem.Quantity;
|
Quantity = shopCartItem.Quantity;
|
||||||
|
|
||||||
|
var l10n = shopItem.L10n.SingleOrDefault(x => x.Locale == locale);
|
||||||
|
|
||||||
var shopItemL10n = shopItem.L10n.Single(x => x.Locale == locale);
|
if (l10n != null) {
|
||||||
Slug = shopItemL10n.Slug;
|
Slug = l10n.Slug;
|
||||||
Title = shopItemL10n.Title;
|
Title = l10n.Title;
|
||||||
ShortText = shopItemL10n.ShortText;
|
ShortText = l10n.ShortText;
|
||||||
|
}
|
||||||
|
|
||||||
Image = new ImageModel(shopItem.Images.First(), locale);
|
if(shopItem.Images != null)
|
||||||
|
Image = new ImageResponseModel(shopItem.Images.First(), locale);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
using Core.DomainObjects;
|
using DomainResults.Common;
|
||||||
using Core.Enumerations;
|
|
||||||
|
using ExtensionMethods;
|
||||||
using DataProviders;
|
using DataProviders;
|
||||||
using DomainResults.Common;
|
|
||||||
|
using Core.DomainObjects;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
|
||||||
using WeatherForecast.Models.Requests;
|
using WeatherForecast.Models.Requests;
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
@ -85,7 +90,44 @@ namespace WeatherForecast.Services {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel) {
|
||||||
throw new NotImplementedException();
|
try {
|
||||||
|
var item = requestModel.ToDomainObject();
|
||||||
|
item.SiteId = siteId;
|
||||||
|
|
||||||
|
var (_, getResult) = _blogCatalogDataProvider.GetBySlugs(item.SiteId, item.L10n.Select(x => x.Slug).ToList());
|
||||||
|
if (getResult.IsSuccess)
|
||||||
|
return IDomainResult.Failed<Guid?>();
|
||||||
|
|
||||||
|
// TODO: should be recovered from users by jwt
|
||||||
|
item.Author = "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60".ToGuid();
|
||||||
|
|
||||||
|
// TODO: should be placed to object storage
|
||||||
|
item.Images = new List<Image>() {
|
||||||
|
new Image {
|
||||||
|
Src = "https://dummyimage.com/450x300/dee2e6/6c757d.jpg",
|
||||||
|
L10n = new List<ImageL10n> {
|
||||||
|
new ImageL10n {
|
||||||
|
Locale = Locales.Us,
|
||||||
|
Alt = "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: default value shoud not be hardcoded by database id
|
||||||
|
item.Categories ??= new List<Guid> { "e154e33f-3cc7-468d-bb66-e0390ddb9ae0".ToGuid() };
|
||||||
|
|
||||||
|
|
||||||
|
var (id, insertResult) = _blogCatalogDataProvider.Insert(item);
|
||||||
|
|
||||||
|
if (!insertResult.IsSuccess)
|
||||||
|
return IDomainResult.Failed<Guid?>();
|
||||||
|
|
||||||
|
return IDomainResult.Success(id);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -95,12 +137,15 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="blogId"></param>
|
/// <param name="blogId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) {
|
public (BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) {
|
||||||
|
try {
|
||||||
var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId);
|
var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
var categories = new List<Category>();
|
var categories = new List<Category>();
|
||||||
|
|
||||||
|
if (item.Categories != null) {
|
||||||
foreach (var catId in item.Categories) {
|
foreach (var catId in item.Categories) {
|
||||||
var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
||||||
if (!getCategoryResult.IsSuccess || category == null)
|
if (!getCategoryResult.IsSuccess || category == null)
|
||||||
@ -108,9 +153,14 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
categories.Add(category);
|
categories.Add(category);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new BlogItemResponseModel(item, categories));
|
return IDomainResult.Success(new BlogItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<BlogItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -119,6 +169,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
|
try {
|
||||||
var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -127,6 +178,8 @@ namespace WeatherForecast.Services {
|
|||||||
var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us;
|
var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us;
|
||||||
|
|
||||||
var categories = new List<Category>();
|
var categories = new List<Category>();
|
||||||
|
|
||||||
|
if (item.Categories != null) {
|
||||||
foreach (var catId in item.Categories) {
|
foreach (var catId in item.Categories) {
|
||||||
var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
||||||
if (!getCategoryResult.IsSuccess || category == null)
|
if (!getCategoryResult.IsSuccess || category == null)
|
||||||
@ -134,9 +187,14 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
categories.Add(category);
|
categories.Add(category);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new BlogItemResponseModel(item, categories, locale));
|
return IDomainResult.Success(new BlogItemResponseModel(item, categories, locale));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<BlogItemResponseModel>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -147,7 +205,30 @@ namespace WeatherForecast.Services {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData) {
|
||||||
throw new NotImplementedException();
|
try {
|
||||||
|
var (item, getResult) = _blogCatalogDataProvider.Get(siteId, blogId);
|
||||||
|
if (!getResult.IsSuccess || item == null)
|
||||||
|
return (null, getResult);
|
||||||
|
|
||||||
|
// construct domain object from model
|
||||||
|
var newItem = requestData.ToDomainObject();
|
||||||
|
newItem.Id = item.Id;
|
||||||
|
newItem.SiteId = siteId;
|
||||||
|
|
||||||
|
newItem.Created = item.Created;
|
||||||
|
newItem.Author = item.Author;
|
||||||
|
|
||||||
|
if (!item.Equals(newItem)) {
|
||||||
|
var (id, updateResult) = _blogCatalogDataProvider.Update(newItem);
|
||||||
|
if (!updateResult.IsSuccess || id == null)
|
||||||
|
return (null, updateResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
return IDomainResult.Success(item.Id);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -158,7 +239,20 @@ namespace WeatherForecast.Services {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public IDomainResult Delete(Guid siteId, Guid blogId) {
|
public IDomainResult Delete(Guid siteId, Guid blogId) {
|
||||||
throw new NotImplementedException();
|
try {
|
||||||
|
var (item, getResult) = _blogCatalogDataProvider.Get(siteId, blogId);
|
||||||
|
if (!getResult.IsSuccess || item == null)
|
||||||
|
return getResult;
|
||||||
|
|
||||||
|
var result = _blogCatalogDataProvider.Delete(item.Id);
|
||||||
|
if (!result.IsSuccess)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return IDomainResult.Success();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
using Core.Abstractions;
|
using DomainResults.Common;
|
||||||
|
|
||||||
|
using DataProviders;
|
||||||
|
|
||||||
|
using Core.Abstractions;
|
||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using DataProviders;
|
|
||||||
using DomainResults.Common;
|
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
namespace WeatherForecast.Services {
|
namespace WeatherForecast.Services {
|
||||||
@ -68,6 +71,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (BlogItemsResponseModel?, 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) {
|
||||||
|
try {
|
||||||
var (items, result) = _blogCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
var (items, result) = _blogCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
@ -75,6 +79,8 @@ namespace WeatherForecast.Services {
|
|||||||
var blogItems = new List<BlogItemResponseModel>();
|
var blogItems = new List<BlogItemResponseModel>();
|
||||||
foreach (var item in items) {
|
foreach (var item in items) {
|
||||||
var categories = new List<Category>();
|
var categories = new List<Category>();
|
||||||
|
|
||||||
|
if (item.Categories != null) {
|
||||||
foreach (var catId in item.Categories) {
|
foreach (var catId in item.Categories) {
|
||||||
var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId);
|
||||||
if (!getCategoryResult.IsSuccess || cat == null)
|
if (!getCategoryResult.IsSuccess || cat == null)
|
||||||
@ -82,8 +88,9 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
categories.Add(cat);
|
categories.Add(cat);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(locale != null)
|
if (locale != null)
|
||||||
blogItems.Add(new BlogItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
blogItems.Add(new BlogItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
||||||
else
|
else
|
||||||
blogItems.Add(new BlogItemResponseModel(item, categories));
|
blogItems.Add(new BlogItemResponseModel(item, categories));
|
||||||
@ -93,12 +100,23 @@ namespace WeatherForecast.Services {
|
|||||||
? IDomainResult.Success(new BlogItemsResponseModel(currentPage, 0, blogItems))
|
? IDomainResult.Success(new BlogItemsResponseModel(currentPage, 0, blogItems))
|
||||||
: IDomainResult.NotFound<BlogItemsResponseModel?>();
|
: IDomainResult.NotFound<BlogItemsResponseModel?>();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<BlogItemsResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId) => _blogCatalogDataProvider.DeleteAll(siteId);
|
public IDomainResult Delete(Guid siteId) {
|
||||||
|
try {
|
||||||
|
return _blogCatalogDataProvider.DeleteAll(siteId);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
using Core.Enumerations;
|
using DomainResults.Common;
|
||||||
|
|
||||||
using DataProviders;
|
using DataProviders;
|
||||||
using DomainResults.Common;
|
|
||||||
|
using Core.Enumerations;
|
||||||
|
|
||||||
using WeatherForecast.Models.Requests;
|
using WeatherForecast.Models.Requests;
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
@ -81,13 +84,13 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel) {
|
||||||
var (_, getResult) = _categoryDataProvider.GetBySlugs(siteId, requestModel.L10n.Select(x => x.Slug).ToList());
|
try {
|
||||||
if (getResult.IsSuccess)
|
|
||||||
return IDomainResult.Failed<Guid?>();
|
|
||||||
|
|
||||||
var item = requestModel.ToDomainObject();
|
var item = requestModel.ToDomainObject();
|
||||||
item.SiteId = siteId;
|
item.SiteId = siteId;
|
||||||
|
|
||||||
|
var (_, getResult) = _categoryDataProvider.GetBySlugs(item.SiteId, item.L10n.Select(x => x.Slug).ToList());
|
||||||
|
if (getResult.IsSuccess)
|
||||||
|
return IDomainResult.Failed<Guid?>();
|
||||||
|
|
||||||
var (id, insertResult) = _categoryDataProvider.Insert(item);
|
var (id, insertResult) = _categoryDataProvider.Insert(item);
|
||||||
|
|
||||||
@ -96,6 +99,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(id);
|
return IDomainResult.Success(id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -104,12 +111,17 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) {
|
public (CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) {
|
||||||
|
try {
|
||||||
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
return IDomainResult.Success(new CategoryItemResponseModel(item));
|
return IDomainResult.Success(new CategoryItemResponseModel(item));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<CategoryItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -118,6 +130,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
|
try {
|
||||||
var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
@ -126,6 +139,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(new CategoryItemResponseModel(item, locale));
|
return IDomainResult.Success(new CategoryItemResponseModel(item, locale));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<CategoryItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -135,6 +152,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData) {
|
||||||
|
try {
|
||||||
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
@ -152,6 +170,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(item.Id);
|
return IDomainResult.Success(item.Id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -160,6 +182,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId, Guid categoryId) {
|
public IDomainResult Delete(Guid siteId, Guid categoryId) {
|
||||||
|
try {
|
||||||
var (item, getResult) = _categoryDataProvider.Get(siteId, categoryId);
|
var (item, getResult) = _categoryDataProvider.Get(siteId, categoryId);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return getResult;
|
return getResult;
|
||||||
@ -170,5 +193,9 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success();
|
return IDomainResult.Success();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
using Core.Abstractions;
|
using DomainResults.Common;
|
||||||
using Core.Enumerations;
|
|
||||||
using DataProviders;
|
using DataProviders;
|
||||||
using DomainResults.Common;
|
|
||||||
|
using Core.Abstractions;
|
||||||
|
using Core.Enumerations;
|
||||||
|
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
namespace WeatherForecast.Services {
|
namespace WeatherForecast.Services {
|
||||||
@ -55,6 +58,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (List<CategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale) {
|
public (List<CategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale) {
|
||||||
|
try {
|
||||||
var (items, result) = _categoryDataProvider.GetAll(siteId);
|
var (items, result) = _categoryDataProvider.GetAll(siteId);
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
@ -65,12 +69,23 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x)).ToList());
|
return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x)).ToList());
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<List<CategoryItemResponseModel>?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId) => _categoryDataProvider.DeleteAll(siteId);
|
public IDomainResult Delete(Guid siteId) {
|
||||||
|
try {
|
||||||
|
return _categoryDataProvider.DeleteAll(siteId);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using DataProviders;
|
using DomainResults.Common;
|
||||||
using DomainResults.Common;
|
|
||||||
|
using DataProviders;
|
||||||
|
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) {
|
public (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) {
|
||||||
|
try {
|
||||||
var (content, result) = _contentDataProvider.Get(siteId, locale);
|
var (content, result) = _contentDataProvider.Get(siteId, locale);
|
||||||
|
|
||||||
if (!result.IsSuccess || content == null)
|
if (!result.IsSuccess || content == null)
|
||||||
@ -54,5 +56,9 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(new ContentResponseModel(content));
|
return IDomainResult.Success(new ContentResponseModel(content));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<ContentResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
using Core.Abstractions;
|
using DomainResults.Common;
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
using Core.Enumerations;
|
|
||||||
using DataProviders;
|
using DataProviders;
|
||||||
using DomainResults.Common;
|
|
||||||
|
using Core.Abstractions;
|
||||||
|
using Core.Enumerations;
|
||||||
|
|
||||||
using WeatherForecast.Models.Requests;
|
using WeatherForecast.Models.Requests;
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
@ -32,7 +33,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US");
|
(ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string? locale);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -88,6 +89,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel) {
|
||||||
|
try {
|
||||||
var (_, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (_, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (getResult.IsSuccess)
|
if (getResult.IsSuccess)
|
||||||
return IDomainResult.Failed<Guid?>();
|
return IDomainResult.Failed<Guid?>();
|
||||||
@ -105,6 +107,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(id);
|
return IDomainResult.Success(id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -114,17 +120,26 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US") {
|
public (ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string? locale) {
|
||||||
|
try {
|
||||||
var (cartItem, getCartItemResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (cartItem, getCartItemResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (!getCartItemResult.IsSuccess || cartItem == null)
|
if (!getCartItemResult.IsSuccess || cartItem == null)
|
||||||
return (null, getCartItemResult);
|
return (null, getCartItemResult);
|
||||||
|
|
||||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null) {
|
||||||
return (null, result);
|
var delteResult = _shopCartDataProvider.Delete(cartItem.Id);
|
||||||
|
if (!delteResult.IsSuccess)
|
||||||
|
return (null, delteResult);
|
||||||
|
|
||||||
return IDomainResult.Success(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
return IDomainResult.NotFound<ShopCartItemResponseModel?>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return IDomainResult.Success(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale ?? "en-US")));
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<ShopCartItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,6 +151,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData) {
|
||||||
|
try {
|
||||||
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return (null, getResult);
|
return (null, getResult);
|
||||||
@ -156,6 +172,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(item.Id);
|
return IDomainResult.Success(item.Id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -165,6 +185,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId, Guid userId, string sku) {
|
public IDomainResult Delete(Guid siteId, Guid userId, string sku) {
|
||||||
|
try {
|
||||||
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return getResult;
|
return getResult;
|
||||||
@ -175,5 +196,9 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success();
|
return IDomainResult.Success();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
using DomainResults.Common;
|
using DomainResults.Common;
|
||||||
|
|
||||||
using WeatherForecast.Models.Responses;
|
|
||||||
|
|
||||||
using DataProviders;
|
using DataProviders;
|
||||||
|
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using Core.Abstractions;
|
using Core.Abstractions;
|
||||||
|
|
||||||
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
namespace WeatherForecast.Services {
|
namespace WeatherForecast.Services {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -21,7 +21,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US");
|
(List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string? locale);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -64,8 +64,8 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US") {
|
public (List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string? locale) {
|
||||||
|
try {
|
||||||
var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId);
|
var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId);
|
||||||
if (!getCartItemsResult.IsSuccess || cartItems == null)
|
if (!getCartItemsResult.IsSuccess || cartItems == null)
|
||||||
return (null, getCartItemsResult);
|
return (null, getCartItemsResult);
|
||||||
@ -73,16 +73,23 @@ namespace WeatherForecast.Services {
|
|||||||
var items = new List<ShopCartItemResponseModel>();
|
var items = new List<ShopCartItemResponseModel>();
|
||||||
foreach (var cartItem in cartItems) {
|
foreach (var cartItem in cartItems) {
|
||||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null) {
|
||||||
return (null, result);
|
var delteResult = _shopCartDataProvider.Delete(cartItem.Id);
|
||||||
|
if (!delteResult.IsSuccess)
|
||||||
items.Add(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
return (null, delteResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
items.Add(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale ?? "en-US")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.Count > 0
|
return items.Count > 0
|
||||||
? IDomainResult.Success(items)
|
? IDomainResult.Success(items)
|
||||||
: IDomainResult.NotFound<List<ShopCartItemResponseModel>?>();
|
: IDomainResult.NotFound<List<ShopCartItemResponseModel>?>();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<List<ShopCartItemResponseModel>?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -90,6 +97,13 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId, Guid userId) => _shopCartDataProvider.DeleteAll(siteId, userId);
|
public IDomainResult Delete(Guid siteId, Guid userId) {
|
||||||
|
try {
|
||||||
|
return _shopCartDataProvider.DeleteAll(siteId, userId);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
using Core.DomainObjects;
|
using DomainResults.Common;
|
||||||
|
|
||||||
|
using DataProviders;
|
||||||
|
|
||||||
|
using ExtensionMethods;
|
||||||
|
|
||||||
|
using Core.DomainObjects;
|
||||||
using Core.DomainObjects.L10n;
|
using Core.DomainObjects.L10n;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using DataProviders;
|
|
||||||
using DomainResults.Common;
|
|
||||||
using ExtensionMethods;
|
|
||||||
using WeatherForecast.Models;
|
using WeatherForecast.Models;
|
||||||
using WeatherForecast.Models.Requests;
|
using WeatherForecast.Models.Requests;
|
||||||
|
|
||||||
@ -90,15 +94,16 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel) {
|
||||||
var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
try {
|
||||||
if (getResult.IsSuccess)
|
|
||||||
return IDomainResult.Failed<Guid?>();
|
|
||||||
|
|
||||||
var item = requestModel.ToDomainObject();
|
var item = requestModel.ToDomainObject();
|
||||||
|
|
||||||
item.SiteId = siteId;
|
item.SiteId = siteId;
|
||||||
item.Sku = sku;
|
item.Sku = sku;
|
||||||
|
|
||||||
|
var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
|
if (getResult.IsSuccess)
|
||||||
|
return IDomainResult.Failed<Guid?>();
|
||||||
|
|
||||||
// TODO: should be recovered from users by jwt
|
// TODO: should be recovered from users by jwt
|
||||||
item.Author = "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60".ToGuid();
|
item.Author = "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60".ToGuid();
|
||||||
|
|
||||||
@ -125,6 +130,12 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(id);
|
return IDomainResult.Success(id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -133,6 +144,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) {
|
public (ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) {
|
||||||
|
try {
|
||||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (item, result) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -151,6 +163,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(new ShopItemResponseModel(item, categories));
|
return IDomainResult.Success(new ShopItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<ShopItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -159,6 +175,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
|
try {
|
||||||
var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -179,6 +196,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(new ShopItemResponseModel(item, categories, locale));
|
return IDomainResult.Success(new ShopItemResponseModel(item, categories, locale));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<ShopItemResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -188,6 +209,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData) {
|
||||||
|
try {
|
||||||
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return (null, getResult);
|
return (null, getResult);
|
||||||
@ -208,6 +230,10 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success(item.Id);
|
return IDomainResult.Success(item.Id);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<Guid?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -216,6 +242,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId, string sku) {
|
public IDomainResult Delete(Guid siteId, string sku) {
|
||||||
|
try {
|
||||||
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return getResult;
|
return getResult;
|
||||||
@ -226,6 +253,9 @@ namespace WeatherForecast.Services {
|
|||||||
|
|
||||||
return IDomainResult.Success();
|
return IDomainResult.Success();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
using Core.Abstractions;
|
using DomainResults.Common;
|
||||||
|
|
||||||
|
using DataProviders;
|
||||||
|
|
||||||
|
using Core.Abstractions;
|
||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using DataProviders;
|
|
||||||
using DomainResults.Common;
|
|
||||||
using WeatherForecast.Models;
|
using WeatherForecast.Models;
|
||||||
using WeatherForecast.Models.Responses;
|
using WeatherForecast.Models.Responses;
|
||||||
|
|
||||||
@ -68,6 +71,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (ShopItemsResponseModel?, 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) {
|
||||||
|
try {
|
||||||
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
||||||
|
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
@ -98,12 +102,23 @@ namespace WeatherForecast.Services {
|
|||||||
? IDomainResult.Success(new ShopItemsResponseModel(currentPage, 0, shopItems))
|
? IDomainResult.Success(new ShopItemsResponseModel(currentPage, 0, shopItems))
|
||||||
: IDomainResult.NotFound<ShopItemsResponseModel?>();
|
: IDomainResult.NotFound<ShopItemsResponseModel?>();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed<ShopItemsResponseModel?>(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDomainResult Delete(Guid siteId) => _shopCatalogDataProvider.DeleteAll(siteId);
|
public IDomainResult Delete(Guid siteId) {
|
||||||
|
try {
|
||||||
|
return _shopCatalogDataProvider.DeleteAll(siteId);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return IDomainResult.Failed(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user