-
Notifications
You must be signed in to change notification settings - Fork 72
Project finished #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Lepros311
wants to merge
2
commits into
TheCSharpAcademy:main
Choose a base branch
from
Lepros311:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Project finished #86
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
765 changes: 765 additions & 0 deletions
765
Ecommerce.Api.Lepros311/Ecommerce API.postman_collection.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.14.36327.8 d17.14 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ecommerce.Api", "Ecommerce.Api\Ecommerce.Api.csproj", "{D8CA0565-FF7F-4CE6-A92D-7B29C2CB14B0}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {D8CA0565-FF7F-4CE6-A92D-7B29C2CB14B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {D8CA0565-FF7F-4CE6-A92D-7B29C2CB14B0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {D8CA0565-FF7F-4CE6-A92D-7B29C2CB14B0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {D8CA0565-FF7F-4CE6-A92D-7B29C2CB14B0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {F8125966-4238-49C5-BE43-7136A2350AA5} | ||
| EndGlobalSection | ||
| EndGlobal |
119 changes: 119 additions & 0 deletions
119
Ecommerce.Api.Lepros311/Ecommerce.Api/Controllers/CategoryController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using Ecommerce.Api.Models; | ||
| using Ecommerce.Api.Responses; | ||
| using Ecommerce.Api.Services; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace Ecommerce.Api.Controllers | ||
| { | ||
| [Route("api/categories")] | ||
| [ApiController] | ||
| public class CategoryController : ControllerBase | ||
| { | ||
| private readonly ICategoryService _categoryService; | ||
|
|
||
| public CategoryController(ICategoryService categoryService) | ||
| { | ||
| _categoryService = categoryService; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public async Task<ActionResult<List<CategoryDto>>> GetPagedCategories([FromQuery] PaginationParams paginationParams) | ||
| { | ||
| var responseWithDtos = await _categoryService.GetPagedCategories(paginationParams); | ||
|
|
||
| if (responseWithDtos.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDtos.Message); | ||
| } | ||
|
|
||
| return Ok(responseWithDtos.Data); | ||
| } | ||
|
|
||
| [HttpGet("{id}")] | ||
| public async Task<ActionResult<CategoryDto>> GetCategoryById(int id) | ||
| { | ||
| var response = await _categoryService.GetCategoryById(id); | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| var returnedCategory = response.Data; | ||
|
|
||
| var categoryDto = new CategoryDto | ||
| { | ||
| CategoryId = returnedCategory.CategoryId, | ||
| CategoryName = returnedCategory.CategoryName, | ||
| Products = returnedCategory.Products.Select(p => new ProductDto | ||
| { | ||
| ProductId = p.ProductId, | ||
| ProductName = p.ProductName, | ||
| Price = p.Price, | ||
| Category = p.Category.CategoryName | ||
| }).ToList() | ||
| }; | ||
|
|
||
| return Ok(categoryDto); | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public async Task<ActionResult<CategoryDto>> CreateCategory([FromBody] WriteCategoryDto writeCategoryDto) | ||
| { | ||
| var responseWithDataDto = await _categoryService.CreateCategory(writeCategoryDto); | ||
|
|
||
| if (responseWithDataDto.Message == "Category not found.") | ||
| { | ||
| return NotFound(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| if (responseWithDataDto.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| return CreatedAtAction(nameof(GetCategoryById), | ||
| new { id = responseWithDataDto.Data.CategoryId }, responseWithDataDto.Data); | ||
| } | ||
|
|
||
| [HttpPut("{id}")] | ||
| public async Task<ActionResult<CategoryDto>> UpdateCategory(int id, [FromBody] WriteCategoryDto writeCategoryDto) | ||
| { | ||
| var response = await _categoryService.UpdateCategory(id, writeCategoryDto); | ||
|
|
||
| if (response.Message == "Category not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
|
|
||
| [HttpDelete("{id}")] | ||
| public async Task<IActionResult> DeleteCategory(int id) | ||
| { | ||
| var response = await _categoryService.DeleteCategory(id); | ||
|
|
||
| if (response.Message == "Category not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
| else if (response.Message == "Cannot delete categories that contain products.") | ||
| { | ||
| return Conflict(response.Message); | ||
| } | ||
| else if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
| } | ||
| } | ||
|
|
112 changes: 112 additions & 0 deletions
112
Ecommerce.Api.Lepros311/Ecommerce.Api/Controllers/LineItemController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| using Ecommerce.Api.Models; | ||
| using Ecommerce.Api.Responses; | ||
| using Ecommerce.Api.Services; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace Ecommerce.Api.Controllers | ||
| { | ||
| [Route("api/lineitems")] | ||
| [ApiController] | ||
| public class LineItemController : ControllerBase | ||
| { | ||
| private readonly ILineItemService _lineItemService; | ||
|
|
||
| public LineItemController(ILineItemService lineItemService) | ||
| { | ||
| _lineItemService = lineItemService; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public async Task<ActionResult<List<LineItemDto>>> GetPagedLineItems([FromQuery] PaginationParams paginationParams) | ||
| { | ||
| var responseWithDtos = await _lineItemService.GetPagedLineItems(paginationParams); | ||
|
|
||
| if (responseWithDtos.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDtos.Message); | ||
| } | ||
|
|
||
| return Ok(responseWithDtos.Data); | ||
| } | ||
|
|
||
| [HttpGet("{id}")] | ||
| public async Task<ActionResult<LineItemDto>> GetLineItemById(int id) | ||
| { | ||
| var response = await _lineItemService.GetLineItemById(id); | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| var returnedLineItem = response.Data; | ||
|
|
||
| var lineItemDto = new LineItemDto | ||
| { | ||
| LineItemId = returnedLineItem.LineItemId, | ||
| ProductId = returnedLineItem.ProductId, | ||
| ProductName = returnedLineItem.Product.ProductName, | ||
| Category = returnedLineItem.Product.Category.CategoryName, | ||
| Quantity = returnedLineItem.Quantity, | ||
| UnitPrice = returnedLineItem.UnitPrice, | ||
| SaleId = returnedLineItem.SaleId, | ||
| }; | ||
|
|
||
| return Ok(lineItemDto); | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public async Task<ActionResult<LineItemDto>> CreateLineItem([FromBody] WriteLineItemDto writeLineItemDto) | ||
| { | ||
| var responseWithDataDto = await _lineItemService.CreateLineItem(writeLineItemDto); | ||
|
|
||
| if (responseWithDataDto.Message == "Sale not found.") | ||
| { | ||
| return NotFound(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| if (responseWithDataDto.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| return CreatedAtAction(nameof(GetLineItemById), | ||
| new { id = responseWithDataDto.Data.LineItemId }, responseWithDataDto.Data); | ||
| } | ||
|
|
||
| [HttpPut("{id}")] | ||
| public async Task<ActionResult<LineItemDto>> UpdateLineItem(int id, [FromBody] WriteLineItemDto writeLineItemDto) | ||
| { | ||
| var response = await _lineItemService.UpdateLineItem(id, writeLineItemDto); | ||
|
|
||
| if (response.Message == "Line Item not found." || response.Message == "Sale not found." || response.Message == "Product not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
|
|
||
| [HttpDelete("{id}")] | ||
| public async Task<IActionResult> DeleteLineItem(int id) | ||
| { | ||
| var response = await _lineItemService.DeleteLineItem(id); | ||
|
|
||
| if (response.Message == "Line Item not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
| else if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
| } | ||
| } |
109 changes: 109 additions & 0 deletions
109
Ecommerce.Api.Lepros311/Ecommerce.Api/Controllers/ProductController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| using Ecommerce.Api.Models; | ||
| using Ecommerce.Api.Responses; | ||
| using Ecommerce.Api.Services; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace Ecommerce.Api.Controllers | ||
| { | ||
| [Route("api/products")] | ||
| [ApiController] | ||
| public class ProductController : ControllerBase | ||
| { | ||
| private readonly IProductService _productService; | ||
|
|
||
| public ProductController(IProductService productService) | ||
| { | ||
| _productService = productService; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public async Task<ActionResult<List<ProductDto>>> GetPagedProducts([FromQuery] PaginationParams paginationParams) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 GetProducts endpoints need to have pagination capabilities |
||
| { | ||
| var responseWithDtos = await _productService.GetPagedProducts(paginationParams); | ||
|
|
||
| if (responseWithDtos.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDtos.Message); | ||
| } | ||
|
|
||
| return Ok(responseWithDtos.Data); | ||
| } | ||
|
|
||
| [HttpGet("{id}")] | ||
| public async Task<ActionResult<ProductDto>> GetProductById(int id) | ||
| { | ||
| var response = await _productService.GetProductById(id); | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| var returnedProduct = response.Data; | ||
|
|
||
| var productDto = new ProductDto | ||
| { | ||
| ProductId = returnedProduct.ProductId, | ||
| ProductName = returnedProduct.ProductName, | ||
| Price = returnedProduct.Price, | ||
| Category = returnedProduct.Category.CategoryName | ||
| }; | ||
|
|
||
| return Ok(productDto); | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public async Task<ActionResult<ProductDto>> CreateProduct([FromBody] WriteProductDto writeProductDto) | ||
| { | ||
| var responseWithDataDto = await _productService.CreateProduct(writeProductDto); | ||
|
|
||
| if (responseWithDataDto.Message == "Category not found.") | ||
| { | ||
| return NotFound(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| if (responseWithDataDto.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(responseWithDataDto.Message); | ||
| } | ||
|
|
||
| return CreatedAtAction(nameof(GetProductById), | ||
| new { id = responseWithDataDto.Data.ProductId }, responseWithDataDto.Data); | ||
| } | ||
|
|
||
| [HttpPut("{id}")] | ||
| public async Task<ActionResult<ProductDto>> UpdateProduct(int id, [FromBody] WriteProductDto writeProductDto) | ||
| { | ||
| var response = await _productService.UpdateProduct(id, writeProductDto); | ||
|
|
||
| if (response.Message == "Product not found." || response.Message == "Category not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
|
|
||
| if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
|
|
||
| [HttpDelete("{id}")] | ||
| public async Task<IActionResult> DeleteProduct(int id) | ||
| { | ||
| var response = await _productService.DeleteProduct(id); | ||
|
|
||
| if (response.Message == "Product not found.") | ||
| { | ||
| return NotFound(response.Message); | ||
| } | ||
| else if (response.Status == ResponseStatus.Fail) | ||
| { | ||
| return BadRequest(response.Message); | ||
| } | ||
|
|
||
| return NoContent(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Postman Collection