-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor handlers, update DTOs, and add service configs
Refactored command handlers to use DataMapper's Map method. Updated AddDishCommand to include RestaurantId. Refactored DishesController to use IDishesRepository. Updated DataMapper with new Map methods. Enhanced ResturantDTO to include a list of Dish objects. Commented out middleware in Program.cs. Modified DishesRepository to return dish ID. Updated IDishesRepository method signatures. Added UserSecretsId to Resturants.csproj. Introduced AddDishDTO and DishDTO classes. Added serviceDependencies.json and serviceDependencies.local.json.
- Loading branch information
Showing
19 changed files
with
117 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
using MediatR; | ||
using Restaurants.DomainMapper; | ||
using Restaurants.Domains.Models; | ||
using Restaurants.Repository.Interfaces; | ||
using Resturants.Repository.Interfaces; | ||
|
||
namespace Resturants.Actions.Commands.AddDish | ||
{ | ||
public class AddDishCommandHandler : IRequestHandler<AddDishCommand> | ||
{ | ||
private readonly IDishesRepository _repository; | ||
|
||
private readonly IDishesRepository _dish_repository; | ||
private readonly IResturantRepository _resturant_repository; | ||
private readonly ILogger<AddDishCommandHandler> _logger; | ||
|
||
public AddDishCommandHandler(IDishesRepository repository, ILogger<AddDishCommandHandler> logger) | ||
public AddDishCommandHandler(IDishesRepository dish_repository, | ||
IResturantRepository resturant_repository, | ||
ILogger<AddDishCommandHandler> logger) | ||
{ | ||
_repository = repository; | ||
|
||
_dish_repository = dish_repository; | ||
_resturant_repository = resturant_repository; | ||
_logger = logger; | ||
} | ||
public async Task Handle(AddDishCommand request, CancellationToken cancellation_token) | ||
Check warning on line 23 in src/Actions/Commands/AddDish/AddDishCommandHandler.cs
|
||
{ | ||
_logger.LogInformation("Adding new dish {@DishRequest}", request); | ||
|
||
Dish domain_dish = new() | ||
{ | ||
Name = request.Name, | ||
Price = request.Price, | ||
Description = request.Description | ||
}; | ||
//var id = request.RestaurantId; | ||
|
||
await _repository.AddDishAsync(domain_dish, cancellation_token); | ||
//var resturant = await _resturant_repository.GetResturantByIdAsync(id) ?? throw new Exception(nameof(Resturant)); | ||
|
||
throw new NotImplementedException(); | ||
|
||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,59 +1,40 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Restaurants.DomainMapper; | ||
using Restaurants.Domains.Models; | ||
using Resturants.Actions.Commands.AddDish; | ||
using Resturants.Domains.DTOs; | ||
using Resturants.Repository.Interfaces; | ||
|
||
namespace Resturants.Controllers | ||
{ | ||
[Route("endpoints/resturants/{resturant_id}/[controller]")] | ||
[ApiController] | ||
public class DishesController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public DishesController(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
|
||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<Dish>>> GetDishes() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
[HttpGet] | ||
[Route("{id:int}")] | ||
public async Task<ActionResult<Dish>> GetDishById(int id) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
private readonly IDishesRepository _repository; | ||
|
||
|
||
[HttpPut] | ||
[Route("{id:int}")] | ||
public async Task<IActionResult> UpdateDish() | ||
public DishesController(IDishesRepository repository) | ||
{ | ||
throw new NotImplementedException(); | ||
|
||
this._repository = repository; | ||
} | ||
|
||
|
||
[HttpPost] | ||
public async Task<ActionResult<Dish>> AddDish([FromRoute] int resturant_id, AddDishCommand command) | ||
public async Task<ActionResult<Dish>> AddDish([FromRoute] int resturant_id, AddDishDTO dish_entry) | ||
{ | ||
await _mediator.Send(command); | ||
var domain_dish = DataMapper.Instance.Map(dish_entry); | ||
|
||
var saved = await _repository.AddDishAsync(domain_dish, CancellationToken.None); | ||
|
||
return Created(); | ||
|
||
|
||
return Ok(saved); | ||
} | ||
|
||
|
||
[HttpDelete] | ||
[Route("{id:int}")] | ||
public async Task<IActionResult> DeleteDish(int id) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
} | ||
} |
This file contains 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
This file contains 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,13 @@ | ||
namespace Resturants.Domains.DTOs | ||
{ | ||
public class AddDishDTO | ||
{ | ||
public string Name { get; set; } = default!; | ||
public string Description { get; set; } = default!; | ||
public decimal Price { get; set; } | ||
|
||
public int? KiloCalories { get; set; } | ||
|
||
public int RestaurantId { get; set; } | ||
} | ||
} |
This file contains 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,12 @@ | ||
namespace Resturants.Domains.DTOs | ||
{ | ||
public class DishDTO | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } = default!; | ||
public string Description { get; set; } = default!; | ||
public decimal Price { get; set; } | ||
|
||
public int? KiloCalories { get; set; } | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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,13 @@ | ||
{ | ||
"dependencies": { | ||
"mssql1": { | ||
"type": "mssql", | ||
"connectionId": "ConnectionStrings:DatabaseConnection", | ||
"dynamicId": null | ||
}, | ||
"secrets1": { | ||
"type": "secrets", | ||
"connectionId": null | ||
} | ||
} | ||
} |
This file contains 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,16 @@ | ||
{ | ||
"dependencies": { | ||
"mssql1": { | ||
"secretStore": "LocalSecretsFile", | ||
"type": "mssql.onprem", | ||
"connectionId": "ConnectionStrings:DatabaseConnection", | ||
"dynamicId": null | ||
}, | ||
"secrets1": { | ||
"secretStore": null, | ||
"resourceId": null, | ||
"type": "secrets.user", | ||
"connectionId": null | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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