Skip to content

Commit abff2f1

Browse files
committed
price indexing changed
1 parent 4504ea0 commit abff2f1

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

TableBooking.Api/Controllers/RestaurantController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public async Task<IActionResult> GetRestaurantByTableId(Guid tableId)
4242
[Authorize]
4343
public async Task<IActionResult> CreateRestaurant([FromBody] RestaurantShortInfoDto restaurantShortInfoDto)
4444
{
45+
var allowedPrices = Enum.GetValues(typeof(Price)).Cast<Price>();
46+
47+
if (!allowedPrices.Contains(restaurantShortInfoDto.Price))
48+
{
49+
var allowedValues = string.Join(", ", allowedPrices.Select(p => $"{p} = {(int)p}"));
50+
return BadRequest($"Price must be one of the following: {allowedValues}. Request sent: {restaurantShortInfoDto.Price} is wrong.");
51+
}
52+
4553
return await _restaurantService.CreateRestaurantAsync(restaurantShortInfoDto);
4654
}
4755

@@ -56,6 +64,14 @@ public async Task<IActionResult> DeleteRestaurant(Guid restaurantId)
5664
[Authorize]
5765
public async Task<IActionResult> UpdateRestaurant([FromBody] RestaurantShortInfoDto restaurantShortInfoDto, Guid restaurantId)
5866
{
67+
var allowedPrices = Enum.GetValues(typeof(Price)).Cast<Price>();
68+
69+
if (!allowedPrices.Contains(restaurantShortInfoDto.Price))
70+
{
71+
var allowedValues = string.Join(", ", allowedPrices.Select(p => $"{p} = {(int)p}"));
72+
return BadRequest($"Price must be one of the following: {allowedValues}. Request sent: {restaurantShortInfoDto.Price} is wrong.");
73+
}
74+
5975
return await _restaurantService.UpdateRestaurantAsync(restaurantShortInfoDto, restaurantId);
6076
}
6177
}

TableBooking.Model/Seed/seed.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ CREATE TABLE IF NOT EXISTS "Ratings" (
7777
INSERT INTO "Restaurants" ("Id","Name", "CloseTime", "Description", "Location", "OpenTime", "Type", "PrimaryImageUrl","SecondaryImageUrl", "Price", "Rating", "Phone")
7878
VALUES ('a7f7be1c-adae-40df-b315-f772857936d5', 'UNO', '2023-10-26 21:00:00', 'Description of UNO.', 'Śniadeckich 10b/2', '2023-10-26 12:00:00', 'Pizza', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 1, 5, 123-456-789);
7979
INSERT INTO "Restaurants" ("Id","Name", "CloseTime", "Description", "Location", "OpenTime", "Type", "PrimaryImageUrl","SecondaryImageUrl", "Price", "Rating", "Phone")
80-
VALUES ('bfa8ba14-e4ef-4f13-a4a9-4b1d29d2f8ba','Mozaika', '2023-10-26 22:15:00', 'Description of Mozaika restaurant.', 'Ratuszowska 10', '2023-10-26 15:00:00', 'Generic restaurant', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 3, 4, 41-334-219);
80+
VALUES ('bfa8ba14-e4ef-4f13-a4a9-4b1d29d2f8ba','Mozaika', '2023-10-26 22:15:00', 'Description of Mozaika restaurant.', 'Ratuszowska 10', '2023-10-26 15:00:00', 'Generic restaurant', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 2, 4, 41-334-219);
8181
INSERT INTO "Restaurants" ("Id","Name", "CloseTime", "Description", "Location", "OpenTime", "Type", "PrimaryImageUrl","SecondaryImageUrl", "Price", "Rating", "Phone")
82-
VALUES ('a50c6651-c1b4-497f-b8db-e101da537692','NieNaŻarty', '2023-10-27 00:15:00', 'Description of NieNaŻarty.', 'Zwycięstwa 20/2', '2023-10-26 13:30:00', 'Burger', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 3, 3, 432-123-543);
82+
VALUES ('a50c6651-c1b4-497f-b8db-e101da537692','NieNaŻarty', '2023-10-27 00:15:00', 'Description of NieNaŻarty.', 'Zwycięstwa 20/2', '2023-10-26 13:30:00', 'Burger', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 0, 3, 432-123-543);
8383
INSERT INTO "Restaurants" ("Id","Name", "CloseTime", "Description", "Location", "OpenTime", "Type", "PrimaryImageUrl","SecondaryImageUrl", "Price", "Rating", "Phone")
84-
VALUES ('207989de-6d2b-416a-9634-c45870cd9f4f','Heaven', '2023-10-26 20:00:00', 'Description of Heaven.', 'Staszewskiego 2', '2023-10-26 12:00:00', 'Pizza', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 2, 2, 164-231-324);
84+
VALUES ('207989de-6d2b-416a-9634-c45870cd9f4f','Heaven', '2023-10-26 20:00:00', 'Description of Heaven.', 'Staszewskiego 2', '2023-10-26 12:00:00', 'Pizza', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 0, 2, 164-231-324);
8585
INSERT INTO "Restaurants" ("Id","Name", "CloseTime", "Description", "Location", "OpenTime", "Type", "PrimaryImageUrl","SecondaryImageUrl", "Price", "Rating", "Phone")
86-
VALUES ('123e1a20-6801-4a5e-a327-ecc5cb2bd906','Green', '2023-10-26 24:00:00', 'Description of Green restaurant.', 'Fałata 5/5', '2023-10-26 14:30:00', 'Generic restaurant', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 2, 1, 357-877-667);
86+
VALUES ('123e1a20-6801-4a5e-a327-ecc5cb2bd906','Green', '2023-10-26 24:00:00', 'Description of Green restaurant.', 'Fałata 5/5', '2023-10-26 14:30:00', 'Generic restaurant', 'https://placehold.co/300x200?text=Restaurant','https://placehold.co/300x200?text=Restaurant', 1, 1, 357-877-667);
8787

8888
-- seed Table records
8989
INSERT INTO "Tables" ("Id","NumberOfSeats", "RestaurantId") VALUES ('123e1a20-6801-4a5e-a327-ecc5cb2bd906',1, '123e1a20-6801-4a5e-a327-ecc5cb2bd906');

TableBooking.Model/TableBookingContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2525
restaurantEntity.Property(r => r.Description).HasMaxLength(100);
2626
restaurantEntity.Property(r => r.Location).HasMaxLength(255);
2727
restaurantEntity.Property(r => r.Phone).HasMaxLength(32);
28+
// TODO: set this in next migration
29+
// restaurantEntity.Property(r => r.Price)
30+
// .IsRequired()
31+
// .HasConversion<int>();
2832
});
2933

3034
modelBuilder.Entity<Rating>(ratingEntity =>

0 commit comments

Comments
 (0)