Skip to content

Commit 49e9b29

Browse files
authored
Base GETDto Initialization and Service Integration (pkyurkchiev#25)
* One Commit for all POST Dtos, Touch in Services also Controllers. It is urgent for merge. * I missed that * Integreate GETDtos for Services
1 parent e48a619 commit 49e9b29

27 files changed

+473
-62
lines changed

GustoHub.API/GustoHub.API/Controllers/CategoriesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using GustoHub.Data.Models;
44
using Microsoft.AspNetCore.Mvc;
55
using GustoHub.Services.Interfaces;
6-
using GustoHub.Data.ViewModels;
6+
using GustoHub.Data.ViewModels.POST;
77

88
[Route("api/[controller]")]
99
[ApiController]

GustoHub.API/GustoHub.API/Controllers/CustomerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using GustoHub.Data.Models;
44
using Microsoft.AspNetCore.Mvc;
55
using GustoHub.Services.Interfaces;
6-
using GustoHub.Data.ViewModels;
6+
using GustoHub.Data.ViewModels.POST;
77

88
[Route("api/[controller]")]
99
[ApiController]

GustoHub.API/GustoHub.API/Controllers/DishController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@
33
using GustoHub.Data.Models;
44
using Microsoft.AspNetCore.Mvc;
55
using GustoHub.Services.Interfaces;
6-
using GustoHub.Data.ViewModels;
6+
using GustoHub.Data.ViewModels.POST;
77

88
[Route("api/[controller]")]
99
[ApiController]
1010
public class DishController : ControllerBase
1111
{
1212
private readonly IDishService dishService;
13+
private readonly ICategoryService categoryService;
1314

14-
public DishController(IDishService dishService)
15+
public DishController(
16+
IDishService dishService,
17+
ICategoryService categoryService)
1518
{
1619
this.dishService = dishService;
20+
this.categoryService = categoryService;
1721
}
1822

1923
[HttpPost]
2024
public async Task<IActionResult> PostDish([FromBody] POSTDishDto dishDto)
2125
{
26+
if (!await categoryService.ExistsByIdAsync(dishDto.CategoryId))
27+
{
28+
return NotFound("Category not found!");
29+
}
2230
string responseMessage = await dishService.AddAsync(dishDto);
2331
return Ok(responseMessage);
2432
}

GustoHub.API/GustoHub.API/Controllers/EmployeeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using GustoHub.Data.Models;
44
using Microsoft.AspNetCore.Mvc;
55
using GustoHub.Services.Interfaces;
6-
using GustoHub.Data.ViewModels;
6+
using GustoHub.Data.ViewModels.POST;
77

88
[Route("api/[controller]")]
99
[ApiController]

GustoHub.API/GustoHub.API/Controllers/OrderController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using GustoHub.Data.Models;
44
using Microsoft.AspNetCore.Mvc;
55
using GustoHub.Services.Interfaces;
6-
using GustoHub.Data.ViewModels;
6+
using GustoHub.Data.ViewModels.POST;
77

88
[Route("api/[controller]")]
99
[ApiController]

GustoHub.API/GustoHub.API/Controllers/OrderDishController.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ namespace GustoHub.API.Controllers
1212
public class OrderDishController : ControllerBase
1313
{
1414
private readonly IOrderDishService orderDishService;
15+
private readonly IOrderService orderService;
16+
private readonly IDishService dishService;
1517

16-
public OrderDishController(IOrderDishService orderDishService)
18+
public OrderDishController(
19+
IOrderDishService orderDishService,
20+
IOrderService orderService,
21+
IDishService dishService)
1722
{
1823
this.orderDishService = orderDishService;
24+
this.orderService = orderService;
25+
this.dishService = dishService;
1926
}
2027

2128
[HttpPost]
@@ -24,6 +31,15 @@ public async Task<IActionResult> PostDishOrder
2431
[FromQuery] int dishId,
2532
[FromQuery] int quantity)
2633
{
34+
if (!await orderService.ExistsByIdAsync(orderId))
35+
{
36+
return NotFound("Order not found!");
37+
}
38+
if (!await dishService.ExistsByIdAsync(dishId))
39+
{
40+
return NotFound("Dish not found!");
41+
}
42+
2743
string responseMessage = await orderDishService.AddDishToOrder(orderId, dishId, quantity);
2844
return Ok(responseMessage);
2945
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
3+
4+
namespace GustoHub.Data.ViewModels.GET
5+
{
6+
public class GETCategoryDto
7+
{
8+
public string Name { get; set; } = null!;
9+
10+
[JsonPropertyName("dishes")]
11+
public List<GETDishDto> DishDtos { get; set; } = new List<GETDishDto>();
12+
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace GustoHub.Data.ViewModels.GET
4+
{
5+
public class GETCustomerDto
6+
{
7+
public string Id { get; set; } = null!;
8+
9+
public string Name { get; set; } = null!;
10+
11+
public string Email { get; set; } = null!;
12+
13+
public string Phone { get; set; } = null!;
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace GustoHub.Data.ViewModels.GET
4+
{
5+
public class GETDishDto
6+
{
7+
public string Name { get; set; } = string.Empty!;
8+
9+
public string Price { get; set; } = string.Empty;
10+
11+
public int CategoryId { get; set; }
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace GustoHub.Data.ViewModels.GET
4+
{
5+
public class GETEmployeeDto
6+
{
7+
public string Name { get; set; } = string.Empty!;
8+
9+
public string Title { get; set; } = string.Empty!;
10+
11+
public string HireDate { get; set; } = string.Empty!;
12+
13+
public bool IsActive { get; set; }
14+
}
15+
}

0 commit comments

Comments
 (0)