(feat): shop item dataprovider and controllers
This commit is contained in:
parent
5cf3a7f7f7
commit
3506afda39
@ -6,7 +6,7 @@
|
||||
"slug": "shop-catalog-item",
|
||||
"sku": "SKU-01",
|
||||
"image": { "src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg", "alt": "..." },
|
||||
"title": "Shop item title",
|
||||
"title": "Mongo Shop item title",
|
||||
"brandName": "Brand & Name",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"created": { "$date": "2022-01-01T00:00:00.000Z" },
|
||||
@ -21,7 +21,7 @@
|
||||
"slug": "shop-catalog-item",
|
||||
"sku": "SKU-02",
|
||||
"image": { "src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg", "alt": "..." },
|
||||
"title": "Shop item title",
|
||||
"title": "Mongo Shop item title",
|
||||
"brandName": "Brand & Name",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"created": { "$date": "2022-01-01T00:00:00.000Z" },
|
||||
@ -36,7 +36,7 @@
|
||||
"slug": "shop-catalog-item",
|
||||
"sku": "SKU-03",
|
||||
"image": { "src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg", "alt": "..." },
|
||||
"title": "Shop item title",
|
||||
"title": "Mongo Shop item title",
|
||||
"brandName": "Brand & Name",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"created": { "$date": "2022-01-01T00:00:00.000Z" },
|
||||
|
||||
187
db/DML/shopcatalog.json
Normal file
187
db/DML/shopcatalog.json
Normal file
@ -0,0 +1,187 @@
|
||||
[
|
||||
{
|
||||
"_id": "e2dd785c-f036-453a-886b-d842b7c31366",
|
||||
"siteId": "404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"slug": "shop-catalog-item",
|
||||
|
||||
"images": [
|
||||
{
|
||||
"src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg",
|
||||
"alt": "..."
|
||||
}
|
||||
],
|
||||
"title": "Shop item title",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"text": "",
|
||||
"author": {
|
||||
"_id": "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"image": {
|
||||
"src": "https://dummyimage.com/40x40/ced4da/6c757d",
|
||||
"alt": "..."
|
||||
},
|
||||
"nickName": "Admin"
|
||||
},
|
||||
"created": {
|
||||
"$date": "2022-01-01T00:00:00.000Z"
|
||||
},
|
||||
"badges": [
|
||||
"sale"
|
||||
],
|
||||
"tags": [
|
||||
"react",
|
||||
"redux",
|
||||
"webapi"
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"_id": "e154e33f-3cc7-468d-bb66-e0390ddb9ae0",
|
||||
"slug": "default",
|
||||
"text": "Default category"
|
||||
}
|
||||
],
|
||||
"brandName": "Mongodb Brand & Name",
|
||||
"sku": "SKU-01",
|
||||
"rating": 4.5,
|
||||
"price": 20,
|
||||
"newPrice": 10,
|
||||
"quantity": 100
|
||||
},
|
||||
{
|
||||
"_id": "055ede3f-7449-47d1-83b1-387dc3573711",
|
||||
"siteId": "404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"slug": "shop-catalog-item",
|
||||
"images": [
|
||||
{
|
||||
"src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg",
|
||||
"alt": "..."
|
||||
}
|
||||
],
|
||||
"title": "Shop item title",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"text": "",
|
||||
"author": {
|
||||
"_id": "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"image": {
|
||||
"src": "https://dummyimage.com/40x40/ced4da/6c757d",
|
||||
"alt": "..."
|
||||
},
|
||||
"nickName": "Admin"
|
||||
},
|
||||
"created": {
|
||||
"$date": "2022-01-01T00:00:00.000Z"
|
||||
},
|
||||
"badges": [
|
||||
"sale"
|
||||
],
|
||||
"tags": [
|
||||
"react",
|
||||
"redux",
|
||||
"webapi"
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"_id": "e154e33f-3cc7-468d-bb66-e0390ddb9ae0",
|
||||
"slug": "default",
|
||||
"text": "Default category"
|
||||
}
|
||||
],
|
||||
"brandName": "Mongodb Brand & Name",
|
||||
"sku": "SKU-02",
|
||||
"rating": 4.5,
|
||||
"price": 20,
|
||||
"newPrice": 10,
|
||||
"quantity": 100
|
||||
},
|
||||
{
|
||||
"_id": "d17accca-6666-43ef-a91f-b63604e6113c",
|
||||
"siteId": "404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"slug": "shop-catalog-item",
|
||||
"images": [
|
||||
{
|
||||
"src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg",
|
||||
"alt": "..."
|
||||
}
|
||||
],
|
||||
"brandName": "Brand & Name",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"text": "",
|
||||
"author": {
|
||||
"_id": "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"image": {
|
||||
"src": "https://dummyimage.com/40x40/ced4da/6c757d",
|
||||
"alt": "..."
|
||||
},
|
||||
"nickName": "Admin"
|
||||
},
|
||||
"created": {
|
||||
"$date": "2022-01-01T00:00:00.000Z"
|
||||
},
|
||||
"badges": [
|
||||
"sale"
|
||||
],
|
||||
"tags": [
|
||||
"react",
|
||||
"redux",
|
||||
"webapi"
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"_id": "e154e33f-3cc7-468d-bb66-e0390ddb9ae0",
|
||||
"slug": "default",
|
||||
"text": "Default category"
|
||||
}
|
||||
],
|
||||
"brandName": "Mongodb Brand & Name",
|
||||
"sku": "SKU-03",
|
||||
"rating": 4.5,
|
||||
"price": 20,
|
||||
"newPrice": 10,
|
||||
"quantity": 100
|
||||
},
|
||||
{
|
||||
"_id": "0dc37621-0925-41d8-90db-552224d59c2a",
|
||||
"siteId": "404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"slug": "shop-catalog-item",
|
||||
"images": [
|
||||
{
|
||||
"src": "https://dummyimage.com/450x300/dee2e6/6c757d.jpg",
|
||||
"alt": "..."
|
||||
}
|
||||
],
|
||||
"title": "Shop item title",
|
||||
"shortText": "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
"text": "",
|
||||
"author": {
|
||||
"_id": "fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"image": {
|
||||
"src": "https://dummyimage.com/40x40/ced4da/6c757d",
|
||||
"alt": "..."
|
||||
},
|
||||
"nickName": "Admin"
|
||||
},
|
||||
"created": {
|
||||
"$date": "2022-01-01T00:00:00.000Z"
|
||||
},
|
||||
"badges": [
|
||||
"sale"
|
||||
],
|
||||
"tags": [
|
||||
"react",
|
||||
"redux",
|
||||
"webapi"
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"_id": "e154e33f-3cc7-468d-bb66-e0390ddb9ae0",
|
||||
"slug": "default",
|
||||
"text": "Default category"
|
||||
}
|
||||
],
|
||||
"brandName": "Mongodb Brand & Name",
|
||||
"sku": "SKU-04",
|
||||
"rating": 4.5,
|
||||
"price": 20,
|
||||
"newPrice": 10,
|
||||
"quantity": 100
|
||||
}
|
||||
]
|
||||
@ -9,7 +9,7 @@
|
||||
"name": "Content",
|
||||
"item": [
|
||||
{
|
||||
"name": "GetContent",
|
||||
"name": "01-Get",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
@ -49,10 +49,10 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ShopCart",
|
||||
"name": "ShopCartItems",
|
||||
"item": [
|
||||
{
|
||||
"name": "GetShopCart",
|
||||
"name": "01-Get",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
@ -68,7 +68,7 @@
|
||||
}
|
||||
],
|
||||
"url": {
|
||||
"raw": "https://localhost:7151/api/ShopCart/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"raw": "https://localhost:7151/api/ShopCartItems/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"protocol": "https",
|
||||
"host": [
|
||||
"localhost"
|
||||
@ -76,7 +76,7 @@
|
||||
"port": "7151",
|
||||
"path": [
|
||||
"api",
|
||||
"ShopCart",
|
||||
"ShopCartItems",
|
||||
"404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60"
|
||||
]
|
||||
@ -85,6 +85,155 @@
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ShopCartItem",
|
||||
"item": [
|
||||
{
|
||||
"name": "01-Get",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
}
|
||||
],
|
||||
"url": {
|
||||
"raw": "https://localhost:7151/api/ShopCartItem/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60/SKU-01",
|
||||
"protocol": "https",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "7151",
|
||||
"path": [
|
||||
"api",
|
||||
"ShopCartItem",
|
||||
"404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"SKU-01"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "02-Post",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"slug\": \"shop-catalog-item\",\r\n \"image\": {\r\n \"src\": \"https://dummyimage.com/450x300/dee2e6/6c757d.jpg\",\r\n \"alt\": \"...\"\r\n },\r\n \"title\": \"Shop item title\",\r\n \"brandName\": \"Brand & Name\",\r\n \"shortText\": \"Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...\",\r\n \"created\": \"2022-01-01T00:00:00Z\",\r\n \"price\": 20,\r\n \"newPrice\": 10,\r\n \"quantity\": 1\r\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "https://localhost:7151/api/ShopCartItem/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60/SKU-04",
|
||||
"protocol": "https",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "7151",
|
||||
"path": [
|
||||
"api",
|
||||
"ShopCartItem",
|
||||
"404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"SKU-04"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "03-Put",
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"slug\": \"shop-catalog-item\",\r\n \"image\": {\r\n \"src\": \"https://dummyimage.com/450x300/dee2e6/6c757d.jpg\",\r\n \"alt\": \"...\"\r\n },\r\n \"title\": \"Shop item title\",\r\n \"brandName\": \"New Brand & Name\",\r\n \"shortText\": \"Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...\",\r\n \"created\": \"2022-01-01T00:00:00Z\",\r\n \"price\": 40,\r\n \"newPrice\": 50,\r\n \"quantity\": 2\r\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "https://localhost:7151/api/ShopCartItem/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60/SKU-04",
|
||||
"protocol": "https",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "7151",
|
||||
"path": [
|
||||
"api",
|
||||
"ShopCartItem",
|
||||
"404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"SKU-04"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "04-Delete",
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
},
|
||||
{
|
||||
"key": "Accept",
|
||||
"value": "application/json",
|
||||
"type": "default"
|
||||
}
|
||||
],
|
||||
"url": {
|
||||
"raw": "https://localhost:7151/api/ShopCartItem/404c8232-9048-4519-bfba-6e78dc7005ca/fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60/SKU-04",
|
||||
"protocol": "https",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "7151",
|
||||
"path": [
|
||||
"api",
|
||||
"ShopCartItem",
|
||||
"404c8232-9048-4519-bfba-6e78dc7005ca",
|
||||
"fdc5aa50-ee68-4bae-a8e6-b8ae2c258f60",
|
||||
"SKU-04"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Core.Abstractions.DomainObjects {
|
||||
public class Category {
|
||||
public Guid Id { get; set; }
|
||||
public string Slug { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,28 +9,28 @@ namespace Core.Abstractions.DomainObjects {
|
||||
|
||||
public abstract class PostItemBase<T> : DomainObjectDocumentBase<T> {
|
||||
|
||||
public List<Image> Images { get; set; }
|
||||
public Guid SiteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Author / Owner
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
public string Slug { get; set; }
|
||||
|
||||
public List<Image> Images { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public string Badge { get; set; }
|
||||
public string ShortText { get; set; }
|
||||
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public List<string> Categories { get; set; }
|
||||
public Author Author { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Edit dateTime, and Author
|
||||
/// </summary>
|
||||
public Dictionary<DateTime, Guid> Edited { get; set; }
|
||||
public List<string> Badges { get; set; }
|
||||
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public List<Category> Categories { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,5 +11,11 @@ namespace Core.Models {
|
||||
public int TotalPages { get; set; }
|
||||
public int CurrentPage { get; set; }
|
||||
public List<T> Items { get; set; }
|
||||
|
||||
public PaginationModelBase(int currentPage, int totalPages, List<T> items) {
|
||||
CurrentPage = currentPage;
|
||||
TotalPages = totalPages;
|
||||
Items = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Abstractions.Models {
|
||||
public abstract class RequestModelBase<T> : ModelBase {
|
||||
public abstract class PostItemRequestModel<T> : ModelBase {
|
||||
public abstract T ToDomainObject();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,19 @@
|
||||
using Core.Abstractions.DomainObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.DomainObjects {
|
||||
public class Author : PersonBase<Author>{
|
||||
public string NickName { get; set; }
|
||||
|
||||
public override int GetHashCode() {
|
||||
throw new NotImplementedException();
|
||||
unchecked {
|
||||
int hash = 17;
|
||||
hash = hash * 23 + Id.GetHashCode();
|
||||
if(Image != null)
|
||||
hash = hash * 23 + Image.GetHashCode();
|
||||
hash = hash * 23 + NickName.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
namespace Core.DomainObjects.Documents {
|
||||
public class BlogItem : PostItemBase<BlogItem> {
|
||||
|
||||
public int? ReadTime { get; set; }
|
||||
public uint? ReadTime { get; set; }
|
||||
|
||||
public int? Likes { get; set; }
|
||||
public uint? Likes { get; set; }
|
||||
|
||||
public override int GetHashCode() {
|
||||
throw new NotImplementedException();
|
||||
|
||||
@ -19,9 +19,9 @@ namespace Core.DomainObjects.Documents {
|
||||
// https://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-overriding-gethashcode
|
||||
// Overflow is fine, just wrap
|
||||
unchecked {
|
||||
|
||||
int hash = 17;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
// Suitable nullity checks etc, of course :)
|
||||
hash = hash * 23 + Id.GetHashCode();
|
||||
hash = hash * 23 + SiteId.GetHashCode();
|
||||
hash = hash * 23 + UserId.GetHashCode();
|
||||
hash = hash * 23 + Slug.GetHashCode();
|
||||
@ -35,7 +35,7 @@ namespace Core.DomainObjects.Documents {
|
||||
hash = hash * 23 + NewPrice.GetHashCode();
|
||||
hash = hash * 23 + Quantity.GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
using Core.Abstractions.DomainObjects;
|
||||
|
||||
namespace Core.DomainObjects.Documents {
|
||||
public class ShopCatalogItem : PostItemBase<ShopCatalogItem> {
|
||||
|
||||
public string Sku { get; set; }
|
||||
public int Rating { get; set; }
|
||||
public int Price { get; set; }
|
||||
public int NewPrice { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public override int GetHashCode() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
webapi/Core/DomainObjects/Documents/ShopItem.cs
Normal file
39
webapi/Core/DomainObjects/Documents/ShopItem.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Core.Abstractions.DomainObjects;
|
||||
|
||||
namespace Core.DomainObjects.Documents {
|
||||
public class ShopItem : PostItemBase<ShopItem> {
|
||||
public string BrandName { get; set; }
|
||||
public string Sku { get; set; }
|
||||
public decimal? Rating { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double? NewPrice { get; set; }
|
||||
public uint? Quantity { get; set; }
|
||||
|
||||
public override int GetHashCode() {
|
||||
unchecked {
|
||||
int hash = 17;
|
||||
hash = hash * 23 + Id.GetHashCode();
|
||||
hash = hash * 23 + SiteId.GetHashCode();
|
||||
hash = hash * 23 + Slug.GetHashCode();
|
||||
hash = hash * 23 + Images.Sum(x => x.GetHashCode());
|
||||
hash = hash * 23 + Title.GetHashCode();
|
||||
hash = hash * 23 + Text.GetHashCode();
|
||||
hash = hash * 23 + ShortText.GetHashCode();
|
||||
hash = hash * 23 + Author.GetHashCode();
|
||||
hash = hash * 23 + Created.GetHashCode();
|
||||
hash = hash * 23 + Badges.Sum(x => x.GetHashCode());
|
||||
hash = hash * 23 + Tags.Sum(x => x.GetHashCode());
|
||||
hash = hash * 23 + Categories.Sum(x => x.GetHashCode());
|
||||
|
||||
hash = hash * 23 + BrandName.GetHashCode();
|
||||
hash = hash * 23 + Sku.GetHashCode();
|
||||
hash = hash * 23 + Rating.GetHashCode();
|
||||
hash = hash * 23 + Price.GetHashCode();
|
||||
hash = hash * 23 + NewPrice.GetHashCode();
|
||||
hash = hash * 23 + Quantity.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,9 @@ namespace DataProviders.Abstractions {
|
||||
|
||||
#region Get
|
||||
private protected (List<T>?, IDomainResult) GetWithPredicate(Expression<Func<T, bool>> predicate, string collectionName) =>
|
||||
GetWithPredicateCore(predicate, collectionName);
|
||||
GetWithPredicateCore(predicate, 0, 0, collectionName);
|
||||
private protected (List<T>?, IDomainResult) GetWithPredicate(Expression<Func<T, bool>> predicate, int skip, int limit, string collectionName) =>
|
||||
GetWithPredicateCore(predicate, skip, limit, collectionName);
|
||||
#endregion
|
||||
|
||||
#region Update
|
||||
@ -104,7 +106,7 @@ namespace DataProviders.Abstractions {
|
||||
|
||||
#region Exists
|
||||
private protected (Guid?, IDomainResult) Exists(Guid id, string collectionName) {
|
||||
var (_resultList, result) = GetWithPredicate(x => x.Id == id, collectionName);
|
||||
var (_resultList, result) = GetWithPredicate(x => x.Id == id, 0, 0, collectionName);
|
||||
|
||||
return (result.Status != DomainOperationStatus.Failed && _resultList != null && _resultList.Count > 0
|
||||
? id
|
||||
@ -189,7 +191,7 @@ namespace DataProviders.Abstractions {
|
||||
}
|
||||
}
|
||||
|
||||
private (List<T>?, IDomainResult) GetWithPredicateCore(Expression<Func<T, bool>> predicate, string collectionName) {
|
||||
private (List<T>?, IDomainResult) GetWithPredicateCore(Expression<Func<T, bool>> predicate, int skip, int limit, string collectionName) {
|
||||
try {
|
||||
List<T>? result;
|
||||
|
||||
@ -199,7 +201,7 @@ namespace DataProviders.Abstractions {
|
||||
}
|
||||
else {
|
||||
result = _client.GetDatabase(_databaseName).GetCollection<T>(collectionName)
|
||||
.Find(predicate).ToList();
|
||||
.Find(predicate).Skip(skip).Limit(limit).ToList();
|
||||
}
|
||||
|
||||
return result != null && result.Count > 0
|
||||
|
||||
@ -23,7 +23,7 @@ namespace DataProviders {
|
||||
|
||||
public (Content?, IDomainResult) Get(Guid siteId, string locale) {
|
||||
var (list, result) = GetWithPredicate(x => x.SiteId == siteId
|
||||
&& (x.Localization.Locale == null || x.Localization.Locale.ToLower() == locale.ToLower()), _collectionName);
|
||||
&& (x.Localization.Locale == null || x.Localization.Locale.ToLower() == locale.ToLower()), 0, 0, _collectionName);
|
||||
|
||||
if (!result.IsSuccess || list == null || list.Count == 0)
|
||||
return (null, result);
|
||||
|
||||
@ -16,6 +16,7 @@ namespace DataProviders.Extensions
|
||||
services.AddSingleton<ISessionService, SessionService>();
|
||||
|
||||
services.AddSingleton<IContentDataProvider, ContentDataProvider>();
|
||||
services.AddSingleton<IShopCatalogDataProvider, ShopCatalogDataProvider>();
|
||||
services.AddSingleton<IShopCartDataProvider, ShopCartDataProvider>();
|
||||
|
||||
Mappings.RegisterClassMap();
|
||||
|
||||
@ -290,8 +290,8 @@ namespace DataProviders {
|
||||
#endregion
|
||||
|
||||
#region ShopItem
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ShopCatalogItem))) {
|
||||
BsonClassMap.RegisterClassMap<ShopCatalogItem>(cm => {
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ShopItem))) {
|
||||
BsonClassMap.RegisterClassMap<ShopItem>(cm => {
|
||||
cm.AutoMap();
|
||||
});
|
||||
}
|
||||
|
||||
@ -31,10 +31,10 @@ namespace DataProviders {
|
||||
Insert(obj, _collectionName);
|
||||
|
||||
public (List<ShopCartItem>?, IDomainResult) GetAll(Guid siteId, Guid userId) =>
|
||||
GetWithPredicate(x => x.SiteId == siteId && x.UserId == userId, _collectionName);
|
||||
GetWithPredicate(x => x.SiteId == siteId && x.UserId == userId, 0, 0,_collectionName);
|
||||
|
||||
public (ShopCartItem?, IDomainResult) Get(Guid siteId, Guid userId, string sku) {
|
||||
var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.UserId == userId && x.Sku == sku, _collectionName);
|
||||
var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.UserId == userId && x.Sku == sku, 0, 0, _collectionName);
|
||||
|
||||
if (!result.IsSuccess || list == null || list.Count == 0)
|
||||
return (null, result);
|
||||
|
||||
52
webapi/DataProviders/ShopCatalogDataProvider.cs
Normal file
52
webapi/DataProviders/ShopCatalogDataProvider.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using DomainResults.Common;
|
||||
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Driver;
|
||||
|
||||
using Core.DomainObjects.Documents;
|
||||
using DataProviders.Abstractions;
|
||||
|
||||
namespace DataProviders {
|
||||
public interface IShopCatalogDataProvider {
|
||||
(Guid?, IDomainResult) Insert(ShopItem obj);
|
||||
(ShopItem?, IDomainResult) Get(Guid siteId, string sku);
|
||||
(List<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take);
|
||||
(Guid?, IDomainResult) Update(ShopItem shopCart);
|
||||
IDomainResult Delete(Guid id);
|
||||
}
|
||||
|
||||
public class ShopCatalogDataProvider : DataProviderBase<ShopItem>, IShopCatalogDataProvider {
|
||||
|
||||
private const string _collectionName = "shopcatalog";
|
||||
|
||||
public ShopCatalogDataProvider(
|
||||
ILogger<DataProviderBase<ShopItem>> logger,
|
||||
IMongoClient client,
|
||||
IIdGenerator idGenerator,
|
||||
ISessionService sessionService) : base(logger, client, idGenerator, sessionService) {
|
||||
}
|
||||
|
||||
public (Guid?, IDomainResult) Insert(ShopItem obj) =>
|
||||
Insert(obj, _collectionName);
|
||||
|
||||
public (ShopItem?, IDomainResult) Get(Guid siteId, string sku) {
|
||||
var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.Sku == sku, _collectionName);
|
||||
|
||||
if (!result.IsSuccess || list == null || list.Count == 0)
|
||||
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);
|
||||
|
||||
public (Guid?, IDomainResult) Update(ShopItem shopCart) =>
|
||||
UpdateWithPredicate(shopCart, x => x.Id == shopCart.Id, _collectionName);
|
||||
|
||||
public IDomainResult Delete(Guid id) =>
|
||||
DeleteWithPredicate(x => x.Id == id, _collectionName);
|
||||
}
|
||||
}
|
||||
@ -32,31 +32,31 @@ public class BlogCatalogController : ControllerBase {
|
||||
public IActionResult Get([FromQuery] Guid? category, [FromQuery] string? searchText, [FromQuery] int currentPage = 1, [FromQuery] int itemsPerPage = 4) {
|
||||
|
||||
|
||||
var blogModels = new List<BlogItemModel>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
var blogItemModel = new BlogItemModel {
|
||||
Id = Guid.NewGuid(),
|
||||
Slug = "blog-post-title",
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/850x350/dee2e6/6c757d.jpg", Alt = "..." },
|
||||
Badge = "news",
|
||||
Title = $"Blog post title {i}",
|
||||
ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
Text = "",
|
||||
Author = new AuthorModel {
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
|
||||
NickName = "Admin"
|
||||
},
|
||||
Created = DateTime.UtcNow,
|
||||
Tags = new List<string> { "react", "redux", "webapi" },
|
||||
//var blogModels = new List<BlogItemModel>();
|
||||
//for (int i = 0; i < 100; i++) {
|
||||
// var blogItemModel = new BlogItemModel {
|
||||
// Id = Guid.NewGuid(),
|
||||
// Slug = "blog-post-title",
|
||||
// Image = new ImageModel { Src = "https://dummyimage.com/850x350/dee2e6/6c757d.jpg", Alt = "..." },
|
||||
// Badge = "news",
|
||||
// Title = $"Blog post title {i}",
|
||||
// ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
// Text = "",
|
||||
// Author = new AuthorModel {
|
||||
// Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
|
||||
// NickName = "Admin"
|
||||
// },
|
||||
// Created = DateTime.UtcNow,
|
||||
// Tags = new List<string> { "react", "redux", "webapi" },
|
||||
|
||||
ReadTime = 10,
|
||||
Likes = 200,
|
||||
};
|
||||
// ReadTime = 10,
|
||||
// Likes = 200,
|
||||
// };
|
||||
|
||||
blogModels.Add(blogItemModel);
|
||||
}
|
||||
// blogModels.Add(blogItemModel);
|
||||
//}
|
||||
|
||||
var totalPages = blogModels.Count() / itemsPerPage;
|
||||
//var totalPages = blogModels.Count() / itemsPerPage;
|
||||
|
||||
var blogCatalogResponse = new GetBlogCatalogResponseModel {
|
||||
|
||||
|
||||
@ -22,36 +22,9 @@ namespace WeatherForecast.Controllers {
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Get() {
|
||||
#if MOCK_SERVER
|
||||
var blogItems = new List<BlogItemModel>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
blogItems.Add(new BlogItemModel {
|
||||
Id = Guid.NewGuid(),
|
||||
Slug = "blog-post-title",
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/600x350/ced4da/6c757d", Alt = "..." },
|
||||
Badge = "news",
|
||||
Title = "C# Blog post title",
|
||||
ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
Text = "",
|
||||
Author = new AuthorModel {
|
||||
//Id = Guid.NewGuid(),
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
|
||||
NickName = "Admin"
|
||||
},
|
||||
Created = DateTime.UtcNow,
|
||||
Tags = new List<string> { "react", "redux", "webapi" },
|
||||
|
||||
ReadTime = 10,
|
||||
Likes = 200,
|
||||
});
|
||||
}
|
||||
|
||||
var result = new GetBlogFeaturedResponseModel(blogItems);
|
||||
|
||||
return Ok(result);
|
||||
#else
|
||||
return Ok();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class ContentController : ControllerBase {
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) {
|
||||
var result = _contentService.GetContent(siteId, locale ?? "en-Us") ;
|
||||
var result = _contentService.GetContent(siteId, locale ?? "en-US") ;
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WeatherForecast.Models;
|
||||
using WeatherForecast.Models.Responses;
|
||||
|
||||
namespace WeatherForecast.Controllers;
|
||||
|
||||
[AllowAnonymous]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ShopCatalogController : ControllerBase {
|
||||
|
||||
private readonly ILogger<ShopCatalogController> _logger;
|
||||
|
||||
public ShopCatalogController(ILogger<ShopCatalogController> logger) {
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="currentPage"></param>
|
||||
/// <param name="itemsPerPage"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Get([FromQuery] Guid? category, [FromQuery] string? searchText, [FromQuery] int currentPage = 1, [FromQuery] int itemsPerPage = 8) {
|
||||
|
||||
var shopModels = new List<ShopItemModel>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
var shopItemModel = new ShopItemModel {
|
||||
Id = Guid.NewGuid(),
|
||||
Sku = "SKU-0",
|
||||
Slug = "shop-catalog-item",
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/450x300/dee2e6/6c757d.jpg", Alt = "..." },
|
||||
Badge = "sale",
|
||||
Title = "Shop item title",
|
||||
|
||||
ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
|
||||
Text = "",
|
||||
Author = new AuthorModel {
|
||||
// Id = Guid.NewGuid(),
|
||||
Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
|
||||
NickName = "Admin"
|
||||
},
|
||||
Created = DateTime.UtcNow,
|
||||
|
||||
Tags = new List<string> { "react", "redux", "webapi" },
|
||||
|
||||
Rating = 4.5,
|
||||
Price = 20,
|
||||
NewPrice = 10
|
||||
};
|
||||
|
||||
shopModels.Add(shopItemModel);
|
||||
}
|
||||
|
||||
var shopCatalogResponse = new GetShopCatalogResponseModel {
|
||||
/*ShopItemsPagination = new PaginationModelBase<ShopItemModel> {
|
||||
CurrentPage = currentPage,
|
||||
TotalPages = 100,
|
||||
Items = shopModels
|
||||
}*/
|
||||
};
|
||||
|
||||
|
||||
return Ok(shopCatalogResponse);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using WeatherForecast.Services;
|
||||
using DomainResults.Mvc;
|
||||
|
||||
namespace WeatherForecast.Controllers {
|
||||
|
||||
@ -9,18 +11,26 @@ namespace WeatherForecast.Controllers {
|
||||
public class ShopItemController : ControllerBase {
|
||||
|
||||
private readonly ILogger<ShopItemController> _logger;
|
||||
private readonly IShopItemService _shopItemService;
|
||||
|
||||
public ShopItemController(ILogger<ShopItemController> logger) {
|
||||
public ShopItemController(
|
||||
ILogger<ShopItemController> logger,
|
||||
IShopItemService shopItemService
|
||||
) {
|
||||
_logger = logger;
|
||||
_shopItemService = shopItemService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="siteId"></param>
|
||||
/// <param name="sku"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Get() {
|
||||
return Ok();
|
||||
[HttpGet("{siteId}/{sku}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku) {
|
||||
var result = _shopItemService.Get(siteId, sku);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
webapi/WeatherForecast/Controllers/ShopItemsController.cs
Normal file
42
webapi/WeatherForecast/Controllers/ShopItemsController.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Models;
|
||||
using DomainResults.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WeatherForecast.Models;
|
||||
using WeatherForecast.Models.Responses;
|
||||
using WeatherForecast.Services;
|
||||
|
||||
namespace WeatherForecast.Controllers;
|
||||
|
||||
[AllowAnonymous]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ShopItemsController : ControllerBase {
|
||||
|
||||
private readonly ILogger<ShopItemsController> _logger;
|
||||
private readonly IShopItemsService _shopItemsService;
|
||||
|
||||
public ShopItemsController(
|
||||
ILogger<ShopItemsController> logger,
|
||||
IShopItemsService shopCatalogService
|
||||
) {
|
||||
_logger = logger;
|
||||
_shopItemsService = shopCatalogService;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="currentPage"></param>
|
||||
/// <param name="itemsPerPage"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{siteId}")]
|
||||
public IActionResult Get([FromRoute] Guid siteId, [FromQuery] Guid? category, [FromQuery] int? currentPage, [FromQuery] int? itemsPerPage, [FromQuery] string? searchText) {
|
||||
var result = _shopItemsService.Get(siteId, category, currentPage ?? 1, itemsPerPage ?? 8, searchText);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,9 @@ namespace WeatherForecast.Controllers {
|
||||
|
||||
private readonly ILogger<ShopRelatedController> _logger;
|
||||
|
||||
|
||||
|
||||
|
||||
public ShopRelatedController(ILogger<ShopRelatedController> logger) {
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Abstractions.DomainObjects;
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects;
|
||||
|
||||
namespace WeatherForecast.Models.Abstractions {
|
||||
public abstract class PersonModelBase : ModelBase {
|
||||
public abstract class PersonModelBase<T> : ModelBase {
|
||||
public ImageModel? Image { get; set; }
|
||||
|
||||
public PersonModelBase() { }
|
||||
|
||||
public PersonModelBase(Image? image) {
|
||||
Image = new ImageModel(image);
|
||||
public PersonModelBase(PersonBase<T> person) {
|
||||
if(person.Image != null)
|
||||
Image = new ImageModel(person.Image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Abstractions.DomainObjects;
|
||||
using Core.Abstractions.Models;
|
||||
|
||||
namespace WeatherForecast.Models.Abstractions {
|
||||
public abstract class PostItemModelBase : ModelBase {
|
||||
public Guid Id { get; set; }
|
||||
public abstract class PostItemRequestModelBase<T> : PostItemRequestModel<T> {
|
||||
|
||||
public string Slug { get; set; }
|
||||
|
||||
public ImageModel Image { get; set; }
|
||||
public List<ImageModel> Images { get; set; }
|
||||
|
||||
public string Badge { get; set; }
|
||||
public List<string> Badges { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
using Core.Abstractions.DomainObjects;
|
||||
using Core.Abstractions.Models;
|
||||
|
||||
namespace WeatherForecast.Models.Abstractions {
|
||||
public abstract class PostItemResponseModelBase<T> : ResponseModelBase {
|
||||
|
||||
public string Slug { get; set; }
|
||||
|
||||
public List<ImageModel> Images { get; set; }
|
||||
|
||||
public List<string> Badges { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string? ShortText { get; set; }
|
||||
|
||||
public string? Text { get; set; }
|
||||
|
||||
public AuthorModel Author { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public PostItemResponseModelBase(PostItemBase<T> postItem) {
|
||||
Slug = postItem.Slug;
|
||||
Images = postItem.Images.Select(x => new ImageModel(x)).ToList();
|
||||
Badges = postItem.Badges;
|
||||
Title = postItem.Title;
|
||||
Text = postItem.Text;
|
||||
ShortText = postItem.ShortText;
|
||||
Author = new AuthorModel(postItem.Author);
|
||||
Created = postItem.Created;
|
||||
Tags = postItem.Tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,12 @@
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
using Core.DomainObjects;
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
|
||||
namespace WeatherForecast.Models {
|
||||
public class AuthorModel : PersonModelBase {
|
||||
public class AuthorModel : PersonModelBase<Author> {
|
||||
public string NickName { get; set; }
|
||||
|
||||
public AuthorModel(Author author) {
|
||||
NickName = author.NickName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
using Core.Abstractions.DomainObjects;
|
||||
using Core.DomainObjects.Documents;
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
|
||||
namespace WeatherForecast.Models {
|
||||
public class BlogItemModel : PostItemModelBase {
|
||||
public class BlogItemModel : PostItemResponseModelBase<BlogItem> {
|
||||
|
||||
public uint? ReadTime { get; set; }
|
||||
|
||||
public int? ReadTime { get; set; }
|
||||
public uint? Likes { get; set; }
|
||||
|
||||
public int? Likes { get; set; }
|
||||
|
||||
|
||||
public BlogItemModel(BlogItem postItem) : base(postItem) {
|
||||
ReadTime = postItem.ReadTime;
|
||||
Likes = postItem.Likes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ using Core.DomainObjects;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PostShopCartItemRequestModel : RequestModelBase<ShopCartItem> {
|
||||
public class PostShopCartItemRequestModel : PostItemRequestModel<ShopCartItem> {
|
||||
|
||||
public string Slug { get; set; }
|
||||
public ImageModel Image { get; set; }
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PostShopItemRequestModel : PostItemRequestModel<ShopItem> {
|
||||
public string Slug { get; set; }
|
||||
public List<ImageModel> Images { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string BrandName { get; set; }
|
||||
public string ShortText { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double NewPrice { get; set; }
|
||||
public uint Quantity { get; set; }
|
||||
|
||||
public override ShopItem ToDomainObject() => new ShopItem {
|
||||
Slug = Slug,
|
||||
Images = Images.Select(x => new Image {
|
||||
Src = x.Src,
|
||||
Alt = x.Alt
|
||||
}).ToList(),
|
||||
Title = Title,
|
||||
BrandName = BrandName,
|
||||
ShortText = ShortText,
|
||||
Created = Created,
|
||||
Price = Price,
|
||||
NewPrice = NewPrice,
|
||||
Quantity = Quantity
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ using Core.DomainObjects;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PutShopCartItemRequestModel : RequestModelBase<ShopCartItem> {
|
||||
public class PutShopCartItemRequestModel : PostItemRequestModel<ShopCartItem> {
|
||||
|
||||
public string Slug { get; set; }
|
||||
public ImageModel Image { get; set; }
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.DomainObjects.Documents;
|
||||
|
||||
namespace WeatherForecast.Models.Requests {
|
||||
public class PutShopItemRequestModel : PostItemRequestModel<ShopItem> {
|
||||
public override ShopItem ToDomainObject() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Models;
|
||||
|
||||
namespace WeatherForecast.Models.Responses {
|
||||
public class GetShopCatalogResponseModel : ResponseModelBase {
|
||||
public PaginationModelBase<ShopItemModel> ShopItemsPagination { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
using Core.DomainObjects.Documents;
|
||||
using Core.DomainObjects.Pages;
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
|
||||
namespace WeatherForecast.Models {
|
||||
public class GetShopItemResponseModel : PostItemResponseModelBase<ShopItem> {
|
||||
public List<ImageModel>? Images { get; set; }
|
||||
public string Sku { get; set; }
|
||||
public decimal? Rating { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double? NewPrice { get; set; }
|
||||
public uint? Quantity { get; set; }
|
||||
|
||||
public GetShopItemResponseModel(ShopItem shopCatalogItem) : base(shopCatalogItem) {
|
||||
Images = shopCatalogItem.Images.Select(x => new ImageModel(x)).ToList();
|
||||
Sku = shopCatalogItem.Sku;
|
||||
Rating = shopCatalogItem.Rating;
|
||||
Price = shopCatalogItem.Price;
|
||||
NewPrice = shopCatalogItem.NewPrice;
|
||||
Quantity = shopCatalogItem.Quantity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Core.Abstractions.Models;
|
||||
using Core.Models;
|
||||
|
||||
namespace WeatherForecast.Models.Responses {
|
||||
public class GetShopItemsResponseModel : PaginationModelBase<GetShopItemResponseModel> {
|
||||
public GetShopItemsResponseModel(int currentPage, int totalPages, List<GetShopItemResponseModel> items)
|
||||
: base(currentPage, totalPages, items) { }
|
||||
}
|
||||
}
|
||||
@ -2,11 +2,11 @@
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
|
||||
namespace WeatherForecast.Models {
|
||||
public class ReviewerModel : PersonModelBase {
|
||||
public class ReviewerModel : PersonModelBase<Reviewer> {
|
||||
public string FullName { get; set; }
|
||||
public string Position { get; set; }
|
||||
|
||||
public ReviewerModel(Reviewer reviewer) : base(reviewer.Image) {
|
||||
public ReviewerModel(Reviewer reviewer) : base(reviewer) {
|
||||
FullName = reviewer.FullName;
|
||||
Position = reviewer.Position;
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
using Core.DomainObjects.Documents;
|
||||
using Core.DomainObjects.Pages;
|
||||
using WeatherForecast.Models.Abstractions;
|
||||
|
||||
namespace WeatherForecast.Models {
|
||||
public class ShopItemModel : PostItemModelBase {
|
||||
public List<ImageModel>? Images { get; set; }
|
||||
public string Sku { get; set; }
|
||||
public double? Rating { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double? NewPrice { get; set; }
|
||||
public int? Quantity { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
85
webapi/WeatherForecast/Services/ShopItemService.cs
Normal file
85
webapi/WeatherForecast/Services/ShopItemService.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using DataProviders;
|
||||
using DomainResults.Common;
|
||||
using WeatherForecast.Models;
|
||||
using WeatherForecast.Models.Requests;
|
||||
|
||||
namespace WeatherForecast.Services {
|
||||
|
||||
public interface IShopItemService {
|
||||
(GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku);
|
||||
}
|
||||
|
||||
public class ShopItemService : IShopItemService {
|
||||
|
||||
private readonly ILogger<ShopItemService> _logger;
|
||||
private readonly IShopCatalogDataProvider _shopCatalogDataProvider;
|
||||
|
||||
public ShopItemService(
|
||||
ILogger<ShopItemService> logger,
|
||||
IShopCatalogDataProvider shopCatalogDataProvider
|
||||
) {
|
||||
_logger = logger;
|
||||
_shopCatalogDataProvider = shopCatalogDataProvider;
|
||||
}
|
||||
|
||||
public (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel) {
|
||||
var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||
if (getResult.IsSuccess)
|
||||
return IDomainResult.Failed<Guid?>();
|
||||
|
||||
var item = requestModel.ToDomainObject();
|
||||
|
||||
item.SiteId = siteId;
|
||||
item.Sku = sku;
|
||||
|
||||
var (id, insertResult) = _shopCatalogDataProvider.Insert(item);
|
||||
|
||||
if (!insertResult.IsSuccess)
|
||||
return IDomainResult.Failed<Guid?>();
|
||||
|
||||
return IDomainResult.Success(id);
|
||||
}
|
||||
|
||||
public (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) {
|
||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||
|
||||
if (!result.IsSuccess || item == null)
|
||||
return (null, result);
|
||||
|
||||
return IDomainResult.Success(new GetShopItemResponseModel(item));
|
||||
}
|
||||
|
||||
public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) {
|
||||
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||
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.Sku = sku;
|
||||
|
||||
if (!item.Equals(newItem)) {
|
||||
var (id, updateResult) = _shopCatalogDataProvider.Update(newItem);
|
||||
if (!updateResult.IsSuccess || id == null)
|
||||
return (null, updateResult);
|
||||
}
|
||||
|
||||
return IDomainResult.Success(item.Id);
|
||||
}
|
||||
|
||||
public IDomainResult Delete(Guid siteId, string sku) {
|
||||
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||
if (!getResult.IsSuccess || item == null)
|
||||
return getResult;
|
||||
|
||||
var result = _shopCatalogDataProvider.Delete(item.Id);
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
|
||||
return IDomainResult.Success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
33
webapi/WeatherForecast/Services/ShopItemsService.cs
Normal file
33
webapi/WeatherForecast/Services/ShopItemsService.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using DataProviders;
|
||||
using DomainResults.Common;
|
||||
using WeatherForecast.Models;
|
||||
using WeatherForecast.Models.Responses;
|
||||
|
||||
namespace WeatherForecast.Services {
|
||||
|
||||
public interface IShopItemsService {
|
||||
(GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? searchText);
|
||||
}
|
||||
|
||||
public class ShopItemsService : IShopItemsService {
|
||||
ILogger<ShopItemsService> _logger;
|
||||
IShopCatalogDataProvider _shopCatalogDataProvider;
|
||||
|
||||
public ShopItemsService(
|
||||
ILogger<ShopItemsService> logger,
|
||||
IShopCatalogDataProvider shopCatalogDataprovider
|
||||
) {
|
||||
_logger = logger;
|
||||
_shopCatalogDataProvider = shopCatalogDataprovider;
|
||||
}
|
||||
|
||||
public (GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? searchText) {
|
||||
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
||||
|
||||
if (!result.IsSuccess || items == null)
|
||||
return (null, result);
|
||||
|
||||
return IDomainResult.Success(new GetShopItemsResponseModel(currentPage, 0, items.Select(x => new GetShopItemResponseModel(x)).ToList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,6 +58,8 @@ namespace WeatherForecast {
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddScoped<IContentService, ContentService>();
|
||||
services.AddScoped<IShopItemService, ShopItemService>();
|
||||
services.AddScoped<IShopItemsService, ShopItemsService>();
|
||||
services.AddScoped<IShopCartItemService, ShopCartItemService>();
|
||||
services.AddScoped<IShopCartItemsService, ShopCartItemsService>();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user