Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
23cf04f
начало l2
Dmitry-Ischenko Jan 27, 2021
1969eb1
подключения сервисов в контейнер сервисов
Dmitry-Ischenko Jan 30, 2021
8fa0716
добавил контроллер api для сотрудников
Dmitry-Ischenko Jan 30, 2021
03f97c9
api контроллер сотрудников
Dmitry-Ischenko Jan 30, 2021
01c2d66
Заготовка клиента Emploees
Dmitry-Ischenko Jan 30, 2021
cd4bc9d
Расширение базового клиента
Dmitry-Ischenko Jan 30, 2021
938b543
Клиент для сотрудников
Dmitry-Ischenko Jan 30, 2021
6ba7e97
подклю.чили клиент сотрудников к основному проекту
Dmitry-Ischenko Jan 30, 2021
11ef003
Добавил возможность получения бренда и категорнии по id
Dmitry-Ischenko Jan 30, 2021
74aedb9
реализовал методы интерфейса для получения категоирии и бренда по id
Dmitry-Ischenko Jan 30, 2021
3698f45
контроллер для товаров
Dmitry-Ischenko Jan 30, 2021
4e47dad
рефакт
Dmitry-Ischenko Jan 30, 2021
b0f8dd9
Описал DTO
Dmitry-Ischenko Jan 30, 2021
fabbb8f
net5
Dmitry-Ischenko Jan 30, 2021
47b2861
описал DTO
Dmitry-Ischenko Jan 30, 2021
56f0c4a
интерфейс DTO
Dmitry-Ischenko Jan 30, 2021
9e8ac34
mapping
Dmitry-Ischenko Jan 30, 2021
3ebd6ad
поменяли интерфейс на DTO
Dmitry-Ischenko Feb 3, 2021
b89c68e
подключили клиент продуктов к основному проекту
Dmitry-Ischenko Feb 3, 2021
bac6c60
запилили заказы
Dmitry-Ischenko Feb 3, 2021
370adc1
добавил профиль пользователя
Dmitry-Ischenko Feb 3, 2021
f133052
начало
Dmitry-Ischenko Jan 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Common/WebStore.Domain/DTO/Orders/OrderDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using WebStore.Domain.ViewModels;

namespace WebStore.Domain.DTO.Orders
{
public record OrderItemDTO(int Id, decimal Price, int Quantity);

public record OrderDTO(
int Id,
string Name,
string Phone,
string Address,
DateTime Date,
IEnumerable<OrderItemDTO> Items);

public record CreateOrderModel(OrderViewModel Order, IList<OrderItemDTO> Items);
}
16 changes: 16 additions & 0 deletions Common/WebStore.Domain/DTO/Products/BrandDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class BrandDTO: NamedEntity
{
public int Order { get; set; }

public int ProductsCount { get; set; }
}
}
19 changes: 19 additions & 0 deletions Common/WebStore.Domain/DTO/Products/CategoryDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class CategoryDTO: NamedEntity
{

public int Order { get; set; }

public int? ParentId { get; set; }

public int ProductsCount { get; set; }
}
}
21 changes: 21 additions & 0 deletions Common/WebStore.Domain/DTO/Products/ProductDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebStore.Domain.Entities.Base;

namespace WebStore.Domain.DTO.Products
{
public class ProductDTO: NamedEntity
{
public int Order { get; set; }
public decimal Price { get; set; }
public string ImageUrl { get; set; }
public BrandDTO Brand { get; set; }
public CategoryDTO Category { get; set; }
public string Description { get; set; }
public int Discount { get; set; }

}
}
20 changes: 20 additions & 0 deletions Common/WebStore.Domain/ViewModels/UserOrderViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;

namespace WebStore.Domain.ViewModels
{
public class UserOrderViewModel
{
public int Id { get; set; }

[Required]
public string Name { get; set; }

[Required]
public string Phone { get; set; }

[Required]
public string Address { get; set; }

public decimal TotalSum { get; set; }
}
}
4 changes: 2 additions & 2 deletions Common/WebStore.Domain/WebStore.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions Services/WebStore.Client/Base/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;

namespace WebStore.Client.Base
Expand All @@ -22,5 +23,36 @@ protected BaseClient(IConfiguration Configuration, string ServiceAddress)
}
};
}

protected T Get<T>(string url) => GetAsync<T>(url).Result;
protected async Task<T> GetAsync<T>(string url)
{
var response = await Http.GetAsync(url);
return await response.EnsureSuccessStatusCode().Content.ReadAsAsync<T>();
}

protected HttpResponseMessage Post<T>(string url, T item) => PostAsync(url, item).Result;

protected async Task<HttpResponseMessage> PostAsync<T>(string url, T item)
{
var response = await Http.PostAsJsonAsync(url, item);
return response.EnsureSuccessStatusCode();
}

protected HttpResponseMessage Put<T>(string url, T item) => PutAsync(url, item).Result;

protected async Task<HttpResponseMessage> PutAsync<T>(string url, T item)
{
var response = await Http.PutAsJsonAsync(url, item);
return response.EnsureSuccessStatusCode();
}

protected HttpResponseMessage Delete(string url) => DeleteAsync(url).Result;

protected async Task<HttpResponseMessage> DeleteAsync(string url)
{
var response = await Http.DeleteAsync(url);
return response;
}
}
}
36 changes: 36 additions & 0 deletions Services/WebStore.Client/Employees/EmployeesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using Webstore.Interfaces.Services;
using WebStore.Client.Base;
using WebStore.Domain.Models;

namespace WebStore.Client.Employees
{
public class EmployeesClient: BaseClient, IEmployeesData
{
private readonly ILogger<EmployeesClient> _Logger;

public EmployeesClient(IConfiguration Configuration, ILogger<EmployeesClient> Logger): base(Configuration, "api/employees")
{
_Logger = Logger;
}

public int Add(Employee employee)=>Post(Address,employee).Content.ReadAsAsync<int>().Result;

public bool Delete(int id) => Delete($"{Address}/{id}").IsSuccessStatusCode;

public IEnumerable<Employee> Get() => Get<IEnumerable<Employee>>(Address);

public Employee Get(int id) => Get<Employee>($"{Address}/{id}");

public void Update(Employee employee)
{
_Logger.LogInformation("Редактирование сотрудника с id:{ 0}", employee.Id);
Put(Address, employee);
}
}
}
35 changes: 35 additions & 0 deletions Services/WebStore.Client/Orders/OrdersClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Webstore.Interfaces;
using Webstore.Interfaces.Services;
using WebStore.Client.Base;
using WebStore.Domain.DTO.Orders;
using WebStore.Domain.ViewModels;
using WebStore.Interfaces;

namespace WebStore.Client.Orders
{
public class OrdersClient : BaseClient, IOrderService
{
private readonly ILogger<OrdersClient> _Logger;
public OrdersClient(IConfiguration Configuration, ILogger<OrdersClient> Logger)
: base(Configuration, WebAPI.Orders) =>
_Logger = Logger;


public async Task<IEnumerable<OrderDTO>> GetUserOrders(string UserName) =>
await GetAsync<IEnumerable<OrderDTO>>($"{Address}/user/{UserName}");

public async Task<OrderDTO> GetOrderById(int id) =>
await GetAsync<OrderDTO>($"{Address}/{id}");

public async Task<OrderDTO> CreateOrder(string UserName, CreateOrderModel OrderModel)
{
var response = await PostAsync($"{Address}/{UserName}", OrderModel);
return await response.Content.ReadAsAsync<OrderDTO>();
}
}
}
55 changes: 55 additions & 0 deletions Services/WebStore.Client/Products/ProductsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Webstore.Interfaces;
using Webstore.Interfaces.Services;
using WebStore.Client.Base;
using WebStore.Domain;
using WebStore.Domain.DTO.Products;

namespace WebStore.Client.Products
{
public class ProductsClient : BaseClient, IProductData
{
public ProductsClient(IConfiguration Configuration) : base(Configuration, WebAPI.Products)
{
}

public IEnumerable<BrandDTO> GetBrands()
{
return Get<IEnumerable<BrandDTO>>($"{Address}/brands");
}

public BrandDTO GetBrandsById(int id)
{
return Get<BrandDTO>($"{Address}/brands/{id}");
}

public ProductDTO GetProductById(int id)
{
return Get<ProductDTO>($"{Address}/{id}");
}

public IEnumerable<ProductDTO> GetProducts(ProductFilter Filter = null)
{
return Post(Address, Filter ?? new ProductFilter())
.Content
.ReadAsAsync<IEnumerable<ProductDTO>>()
.Result;
}

public IEnumerable<CategoryDTO> GetСategories()
{
return Get<IEnumerable<CategoryDTO>>($"{Address}/categories");
}

public CategoryDTO GetСategoriesById(int id)
{
return Get<CategoryDTO>($"{Address}/categories/{id}");
}
}
}
2 changes: 1 addition & 1 deletion Services/WebStore.Client/WebStore.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webstore.Interfaces.Services;
using WebStore.Domain.Models;

namespace WebStore.ServiceHosting.Controllers
{
[Route("api/employees")]
[ApiController]
public class EmployeesApiController : ControllerBase, IEmployeesData
{
private readonly IEmployeesData _db;
private readonly ILogger<EmployeesApiController> _Logger;

public EmployeesApiController(IEmployeesData db, ILogger<EmployeesApiController> Logger)
{
_db = db;
_Logger = Logger;
}

[HttpPost]
public int Add(Employee employee)
{
if (!ModelState.IsValid)
{
_Logger.LogWarning("Ошибка модели данных при добавлении нового сотрудника {0} {1}",
employee.LastName, employee.FirstName);
return 0;
}
_Logger.LogInformation("Добавление сотрудника {0} {1}",
employee.LastName, employee.FirstName);
var id = _db.Add(employee);
if (id > 0)
_Logger.LogInformation("Cотрудник [id:{0}] {1} {2} добавлен успешно",
employee.Id, employee.LastName, employee.FirstName);
else
_Logger.LogWarning("Ошибка при добавлении сотрудника {0} {1}",
employee.LastName, employee.FirstName);
return id;
}

[HttpDelete("{id}")]
public bool Delete(int id)
{

var result = _db.Delete(id);
if (result)
_Logger.LogInformation("Сотрудник с id:{0} успешно удалён", id);
else
_Logger.LogWarning("ошибка при попытке удаления сотрдуника с id:{0}", id);

return result;
}

[HttpGet]
public IEnumerable<Employee> Get()
{
return _db.Get();
}

[HttpGet("{id}")]
public Employee Get(int id)
{
return _db.Get(id);
}

[HttpPut]
public void Update(Employee employee)
{
_db.Update(employee);
}
}
}
Loading