Adding Redis for Shopping Cart
This commit is contained in:
parent
f3ef7e326e
commit
0ce1d055c7
@ -10,6 +10,7 @@ namespace API.Extensions
|
||||
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<iProductRepository, ProductRepository>();
|
||||
services.AddScoped<IBasketRepository, BasketRepository>();
|
||||
services.AddScoped(typeof(IGenericRepository<>), (typeof(GenericRepository<>)));
|
||||
services.Configure<ApiBehaviorOptions>(options =>
|
||||
options.InvalidModelStateResponseFactory = actionContext =>
|
||||
|
@ -3,6 +3,7 @@ using API.Helpers;
|
||||
using API.Middleware;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace API
|
||||
{
|
||||
@ -23,6 +24,10 @@ namespace API
|
||||
services.AddApplicationServices();
|
||||
services.AddSwaggerDocumentation();
|
||||
services.AddDbContext<StoreContext>(x => x.UseSqlite(_config.GetConnectionString("DefaultConnection")));
|
||||
services.AddSingleton<ConnectionMultiplexer>(c => {
|
||||
var configuration = ConfigurationOptions.Parse(_config.GetConnectionString("redis"), true);
|
||||
return ConnectionMultiplexer.Connect(configuration);
|
||||
});
|
||||
services.AddAutoMapper(typeof(MappingProfiles));
|
||||
services.AddCors(opt =>
|
||||
{
|
||||
|
@ -6,7 +6,8 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data source=ecommerce.db"
|
||||
"DefaultConnection": "Data source=ecommerce.db",
|
||||
"Redis": "localhost"
|
||||
},
|
||||
"ApiUrl": "https://localhost:5001/"
|
||||
}
|
||||
|
13
Core/Entities/BasketItem.cs
Normal file
13
Core/Entities/BasketItem.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Core.Entities
|
||||
{
|
||||
public class BasketItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string productName { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public string PictureUrl { get; set; }
|
||||
public string Brand { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
22
Core/Entities/CustomerBasket.cs
Normal file
22
Core/Entities/CustomerBasket.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Entities
|
||||
{
|
||||
public class CustomerBasket
|
||||
{
|
||||
public CustomerBasket()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomerBasket(string id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
||||
}
|
||||
}
|
16
Core/Interfaces/IBasketRepository.cs
Normal file
16
Core/Interfaces/IBasketRepository.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Core.Entities;
|
||||
|
||||
namespace Core.Interfaces
|
||||
{
|
||||
public interface IBasketRepository
|
||||
{
|
||||
Task<CustomerBasket> GetCustomerBasketAsync(string basketId);
|
||||
Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket);
|
||||
Task<bool> DeleteBasketAsysnc(string basketId);
|
||||
|
||||
}
|
||||
}
|
27
Infrastructure/Data/BasketRepository.cs
Normal file
27
Infrastructure/Data/BasketRepository.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Core.Entities;
|
||||
using Core.Interfaces;
|
||||
|
||||
namespace Infrastructure.Data
|
||||
{
|
||||
public class BasketRepository : IBasketRepository
|
||||
{
|
||||
public Task<bool> DeleteBasketAsysnc(string basketId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<CustomerBasket> GetCustomerBasketAsync(string basketId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user