Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 002c2b7

Browse files
IProductRepository refactored
1 parent df1bcd9 commit 002c2b7

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

‎src/AspnetRunAngular.Application/Services/ProductService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using AspnetRunAngular.Core.Entities;
88
using AspnetRunAngular.Core.Interfaces;
99
using AspnetRunAngular.Core.Repositories;
10+
using AspnetRunAngular.Core.Specifications;
1011

1112
namespace AspnetRunAngular.Application.Services
1213
{
@@ -41,7 +42,8 @@ public async Task<ProductModel> GetProductById(int productId)
4142

4243
public async Task<IEnumerable<ProductModel>> GetProductsByName(string name)
4344
{
44-
var productList = await _productRepository.GetProductsByNameAsync(name);
45+
var spec = new ProductWithCategorySpecification(name);
46+
var productList = await _productRepository.GetAsync(spec);
4547

4648
var productModels = ObjectMapper.Mapper.Map<IEnumerable<ProductModel>>(productList);
4749

@@ -50,7 +52,8 @@ public async Task<IEnumerable<ProductModel>> GetProductsByName(string name)
5052

5153
public async Task<IEnumerable<ProductModel>> GetProductsByCategoryId(int categoryId)
5254
{
53-
var productList = await _productRepository.GetProductsByCategoryIdAsync(categoryId);
55+
var spec = new ProductWithCategorySpecification(categoryId);
56+
var productList = await _productRepository.GetAsync(spec);
5457

5558
var productModels = ObjectMapper.Mapper.Map<IEnumerable<ProductModel>>(productList);
5659

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using AspnetRunAngular.Core.Entities;
22
using AspnetRunAngular.Core.Repositories.Base;
3-
using System.Collections.Generic;
4-
using System.Threading.Tasks;
53

64
namespace AspnetRunAngular.Core.Repositories
75
{
86
public interface IProductRepository : IRepository<Product>
97
{
10-
Task<IEnumerable<Product>> GetProductsByNameAsync(string productName);
11-
Task<IEnumerable<Product>> GetProductsByCategoryIdAsync(int categoryId);
128
}
139
}

‎src/AspnetRunAngular.Infrastructure/Repository/ProductRepository.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using AspnetRunAngular.Core.Entities;
22
using AspnetRunAngular.Core.Repositories;
3-
using AspnetRunAngular.Core.Specifications;
43
using AspnetRunAngular.Infrastructure.Data;
54
using AspnetRunAngular.Infrastructure.Repository.Base;
65
using System;
@@ -24,17 +23,5 @@ public override async Task<Product> GetByIdAsync(int id)
2423
var products = await GetAsync(p => p.Id == id, null, new List<Expression<Func<Product, object>>> { p => p.Category });
2524
return products.FirstOrDefault();
2625
}
27-
28-
public async Task<IEnumerable<Product>> GetProductsByCategoryIdAsync(int categoryId)
29-
{
30-
var spec = new ProductWithCategorySpecification(categoryId);
31-
return await GetAsync(spec);
32-
}
33-
34-
public async Task<IEnumerable<Product>> GetProductsByNameAsync(string productName)
35-
{
36-
var spec = new ProductWithCategorySpecification(productName);
37-
return await GetAsync(spec);
38-
}
3926
}
4027
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /