using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
namespace Example.WarehouseApi
{
public class WarehouseController : Controller
{
private readonlyIWarehouseRepository _warehouseRepository;
publicWarehouseController(IWarehouseRepository warehouseRepository)
{
_warehouseRepository =warehouseRepository;
}
// ReturnOkObjectResult(IEnumerable<WarehouseEntry>)
public IActionResultGetProducts()
{
//Console.WriteLine("Sample debug output");
throw newNotImplementedException();
}
// Return OkResult,BadRequestObjectResult(NotPositiveQuantityMessage), orBadRequestObjectResult(QuantityTooLowMessage)
public IActionResultSetProductCapacity(int productId, int capacity)
{
throw newNotImplementedException();
}
// Return OkResult,BadRequestObjectResult(NotPositiveQuantityMessage), orBadRequestObjectResult(QuantityTooHighMessage)
public IActionResultReceiveProduct(int productId, int qty)
{
throw newNotImplementedException();
}
// Return OkResult,BadRequestObjectResult(NotPositiveQuantityMessage), orBadRequestObjectResult(QuantityTooHighMessage)
public IActionResultDispatchProduct(int productId, int qty)
{
throw newNotImplementedException();
}
}
}
You are a new software engineer in a company that develops a SaaS-based warehouse manager. Your task is to implement an ASP.NET Core API that supports warehouse operations. The API should expose the following methods: - GetProducts() - this method returns all products that are currently stored in the warehouse; - SetProductCapacity(productId, capacity) - this method sets the maximum storage capacity for specified product; - ReceiveProduct(productId, qty) - this method increments the current quantity of a product stored in the warehouse; - DispatchProduct(productId, qty) - this method decrements the current quantity of a product stored in the warehouse. Requirements The requirements are described using the following notation: - FunctionName() - ResponseType - Conditions The API methods should implement the following business logic: - GetProducts() O Ok0bjectResult(IEnumerable) - Return an array of products currently stored in the warehouse. This method should only return products whose quantity is greater than zero. - SetProductCapacity(productId, capacity) - OkResult - Provided data is correct. - BadRequest0bjectResult(NotPositiveQuantityMessage) - Provided capacity of product is less than or equal to zero. o BadRequest0bjectResult(QuantityTooLowMessage) - Provided capacity of product is lower than the quantity currently stored in the warehouse. - ReceiveProduct(productId, qty) o OkResult - Provided data is correct. o BadRequest0bjectResult(NotPositiveQuantityMessage) - Provided quantity of product is less than or equal to zero. o BadRequest0bjectResult(QuantityTooHighMessage) - The sum of the currently stored quantity and the provided quantity is greater than the current capacity. - DispatchProduct(productId, qty) o OkResult - Provided data is correct o BadRequest0bjectResult(NotPositiveQuantityMessage) - Provided quantity of product is less than or equal to zero o BadRequest0bjectResult(QuantityTooHighMessage) - Provided quantity of product is greater than the currently stored quantity
Example flow 1. SetProductCapacity (1,999) - Warehouse can store up to 999 pieces of product 1 ; 0kResult is returned. 3. ReceiveProduct (1,100) - Warehouse receives 100 pieces of product 1 ; there are now 100 pieces of product 1 in stock; okResult is returned. 4. DispatchProduct (1,20) - Warehouse dispatches 20 pieces of product 1 ; there are now 80 pieces of product 1 in stock; okResult is returned. equal to 80 . Assumptions ProductRecord is not returned then the product's quantity is equal to zero. Code Presented below is the code snippet containing the classes and the interface already provided for you: public interface IWarehouseRepository void SetCapacityRecord(int productId, int capacity); IEnumerable GetCapacityRecords(); IEnumerable GetCapacityRecords(Func filter); void SetProductRecord(int productId, int quantity); IEnumerable GetProductRecords(); IEnumerable GetProductRecords(Func filter); public class CapacityRecord public int Productid \{ get; set; } public int Capacity { get; set; } public class ProductRecord \{ public int Productid \{ get; set; } public int Quantity { get; set; } All classes' required composing API responses are provided in the following code snippet: public string Message ⇒ "A positive quantity was not provided"; \} I/ IEnumerable should be returned by GetProducts method. // It can be mapped from ProductRecord public class WarehouseEntry \{ public int ProductId { get; set; } public int Quantity { get; set; } I/ NotPositiveQuantityMessage should be returned by // SetProductCapacity, ReceiveProduct and DispatchProduct methods public class NotPositiveQuantityMessage \{ public string Message ⇒ "A positive quantity was not provided"; If QuantityTooLowMessage should be returned by I/ SetProductCapacity, ReceiveProduct and DispatchProduct methods public class QuantityTooLowMessage \{ \{ public string Message ⇒ "Too low a quantity was provided"; I/ QuantityTooHighMessage should be returned by public class QuantityTooHighMessage
You are a new software engineer in a company that develops a SaaS-based warehouse manager. Your task is to implement an
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
You are a new software engineer in a company that develops a SaaS-based warehouse manager. Your task is to implement an
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!