added product entity and initial data for it

This commit is contained in:
stasex 2023-10-12 20:55:34 +03:00
parent 6b8b2bdeb3
commit e9c3b57fc4
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,19 @@
using MongoDB.Bson;
using ShoppingAssistantApi.Domain.Common;
namespace ShoppingAssistantApi.Domain.Entities;
public class Product : EntityBase
{
public ObjectId WishlistId { get; set; }
public string? Url { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public double Rating { get; set; }
public string[]? ImagesUrls { get; set; }
}

View File

@ -23,9 +23,13 @@ public class DbInitialaizer
private readonly ITokensService _tokensService;
private readonly IWishlistsService _wishlistsService;
private readonly IMongoCollection<User> _userCollection;
private readonly IMongoCollection<Wishlist> _wishlistCollection;
private readonly IMongoCollection<Product> _productCollection;
public IEnumerable<RoleDto> Roles { get; set; }
@ -35,8 +39,10 @@ public class DbInitialaizer
_rolesService = serviceProvider.GetService<IRolesService>();
_userManager = serviceProvider.GetService<IUserManager>();
_tokensService = serviceProvider.GetService<ITokensService>();
_wishlistsService = serviceProvider.GetService<IWishlistsService>();
_wishlistCollection = serviceProvider.GetService<MongoDbContext>().Db.GetCollection<Wishlist>("Wishlists");
_userCollection = serviceProvider.GetService<MongoDbContext>().Db.GetCollection<User>("Users");
_productCollection = serviceProvider.GetService<MongoDbContext>().Db.GetCollection<Product>("Product");
}
public async Task InitialaizeDb(CancellationToken cancellationToken)
@ -213,4 +219,43 @@ public class DbInitialaizer
await _wishlistCollection.InsertManyAsync(wishlists);
}
public async Task AddProducts(CancellationToken cancellationToken)
{
var wishList1 = await _wishlistCollection.FindAsync(w => w.Name == "Gaming PC");
var wishList2 = await _wishlistCollection.FindAsync(w => w.Name == "Generic Wishlist Name");
var products = new Product[]
{
new Product()
{
Id = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"),
Url = "url",
Name = "Thermaltake Glacier",
Description = "Something",
Rating = 4.1,
ImagesUrls = new string[]
{
"url1",
"url2"
}
},
new Product()
{
Id = ObjectId.Parse("ab6c2c2d9edf39abcd1ef9ab"),
Url = "url",
Name = "Mac",
Description = "very very cool laptop",
Rating = 4.9,
ImagesUrls = new string[]
{
"url1",
"url2"
}
}
};
}
}

View File

@ -0,0 +1,9 @@
using ShoppingAssistantApi.Domain.Entities;
using ShoppingAssistantApi.Persistance.Database;
namespace ShoppingAssistantApi.Persistance.Repositories;
public class ProductsRepository : BaseRepository<Product>
{
public ProductsRepository(MongoDbContext db) : base(db, "Products") { }
}