feat(Company): Entitäten und Repository erstellt

This commit is contained in:
Developer 02 2025-01-29 23:52:21 +01:00
parent 054527b4ba
commit c70257bb28
5 changed files with 125 additions and 0 deletions

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OData" Version="9.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

View File

@ -0,0 +1,9 @@
namespace DigitalData.Swagger.MockAPI.Dtos;
public class Company
{
public int ID { get; set; }
public string? Name { get; set; }
public int Size { get; set; }
public List<Product>? Products { get; set; }
}

View File

@ -0,0 +1,9 @@
namespace DigitalData.Swagger.MockAPI.Dtos;
public class Product
{
public int ID { get; set; }
public int CompanyID { get; set; }
public string? Name { get; set; }
public decimal Price { get; set; }
}

View File

@ -0,0 +1,95 @@
using DigitalData.Swagger.MockAPI.Dtos;
using System;
namespace DigitalData.Swagger.MockAPI.Repos;
public class CompanyRepo : ICompanyRepo
{
private readonly Lazy<List<Company>> _lazyCompanies = new(() => new()
{
new()
{
ID = 1,
Name = "TechCorp",
Size = 500,
Products = new List<Product>
{
new() { ID = 1, CompanyID = 1, Name = "Laptop X1", Price = 1200.99m },
new() { ID = 2, CompanyID = 1, Name = "Smartphone S2", Price = 799.49m }
}
},
new Company
{
ID = 2,
Name = "AutoWorks",
Size = 300,
Products = new List<Product>
{
new Product { ID = 3, CompanyID = 2, Name = "Electric Car E1", Price = 35000m },
new() { ID = 4, CompanyID = 2, Name = "Hybrid SUV H2", Price = 42000m }
}
},
new Company
{
ID = 3,
Name = "MediHealth",
Size = 200,
Products = new List<Product>
{
new() { ID = 5, CompanyID = 3, Name = "Vitamin Pack V10", Price = 19.99m },
new() { ID = 6, CompanyID = 3, Name = "Protein Shake P5", Price = 25.49m }
}
},
new Company
{
ID = 4,
Name = "HomeStyle",
Size = 150,
Products = new List<Product>
{
new() { ID = 7, CompanyID = 4, Name = "Smart Blender B3", Price = 89.99m },
new() { ID = 8, CompanyID = 4, Name = "Air Purifier A1", Price = 149.99m }
}
},
new Company
{
ID = 5,
Name = "GadgetZone",
Size = 400,
Products = new List<Product>
{
new() { ID = 9, CompanyID = 5, Name = "Wireless Earbuds W1", Price = 99.99m },
new() { ID = 10, CompanyID = 5, Name = "Smart Watch G5", Price = 199.99m }
}
}
});
private List<Company> _companies => _lazyCompanies.Value;
public IQueryable<Company> GetAll()
{
return _companies.AsQueryable();
}
public IQueryable<Company> GetById(int id)
{
return _companies
.AsQueryable()
.Where(c => c.ID == id);
}
public void Create(Company company)
{
_companies.Add(company);
}
public void Update(Company company)
{
var i = _companies.FindIndex(c => c.ID == company.ID);
_companies[i] = company;
}
public void Delete(Company company)
{
_companies.RemoveAll(c => c.ID == company.ID);
}
}

View File

@ -0,0 +1,11 @@
using DigitalData.Swagger.MockAPI.Dtos;
namespace DigitalData.Swagger.MockAPI.Repos;
public interface ICompanyRepo
{
public IQueryable<Company> GetAll();
public IQueryable<Company> GetById(int id);
public void Create(Company company);
public void Update(Company company);
public void Delete(Company company);
}