Get without id
Comment out db
docker.io
This commit is contained in:
2024-11-17 12:22:43 -07:00
parent 23fa7a553e
commit c45310e81a
9 changed files with 57 additions and 29 deletions

View File

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using OneReview.Domain;
using OneReview.Services;
using System.Collections;
using System.Collections.ObjectModel;
namespace OneReview.Controllers;
@ -11,6 +13,14 @@ public class ProductsController(ProductService productService) : ControllerBase
private readonly ProductService _ProductService = productService;
[HttpGet()]
public IActionResult Get()
{
ReadOnlyCollection<Product> products = _ProductService.Get();
ProductResponse?[] productResponses = ProductResponse.FromDomain(products);
return Ok(productResponses);
}
[HttpPost]
public IActionResult Create(CreateProductRequest request)
{
@ -75,6 +85,9 @@ public class ProductsController(ProductService productService) : ControllerBase
Category: product.Category,
SubCategory: product.SubCategory);
public static ProductResponse?[] FromDomain(IEnumerable<Product> products) =>
products.Select(FromDomain).ToArray();
}
}

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

View File

@ -1,4 +1,5 @@
using OneReview.Domain;
using System.Collections.ObjectModel;
namespace OneReview.Services;
@ -8,6 +9,9 @@ public class ProductService
private static readonly List<Product> _ProductsRepository = [];
// private static readonly List<User> _UsersRepository = [];
public ReadOnlyCollection<Product> Get() =>
_ProductsRepository.AsReadOnly();
// 1. fetch user
// 1. fetch product
// 1. check wether the user reached the