Skip to content

Commit 88a6633

Browse files
authored
Merge pull request #10 from anycode-pk/feature/Tomek
merge Feature/tomek into dev
2 parents b9db278 + 093fa11 commit 88a6633

36 files changed

+960
-102
lines changed

TableBookingAPI/TableBooking.Logic/Converters/TableConverters/TableToGetConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public GetTablesDto TableToTableDto(Table table)
2121
{
2222
Id = table.Id,
2323
RestaurantId = table.RestaurantId,
24-
NumberOfSeats = table.NumberOfSeats
24+
NumberOfSeats = table.NumberOfSeats,
25+
Bookings = table.Bookings
2526
};
2627
}
2728
}

TableBookingAPI/TableBooking.Logic/Repositories/BookingRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public BookingRepository(TableBookingContext context) : base(context)
1313

1414
public async Task<IEnumerable<Booking>> GetAllBookingsForSpecificUserAsync(Guid userId)
1515
{
16-
return await _objectSet.Where(x => x.Id.Equals(userId)).ToListAsync();
16+
return await _objectSet.Where(x => x.AppUserId.Equals(userId)).ToListAsync();
1717
}
1818

1919
public async Task<Booking?> GetBookingByIdForSpecificUserAsync(Guid bookingId, Guid userId)
2020
{
21-
return await _objectSet.FirstOrDefaultAsync(x => x.Id.Equals(bookingId) && x.Id.Equals(userId));
21+
return await _objectSet.FirstOrDefaultAsync(x => x.Id.Equals(bookingId) && x.AppUserId.Equals(userId));
2222
}
2323
}
2424
}

TableBookingAPI/TableBooking.Logic/Repositories/GenericRepository.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ public async Task Delete(object id)
3535
_objectSet.Remove(objectToDelete);
3636
}
3737

38-
public async virtual Task Update(T entity)
38+
public async Task Update(T entity)
3939
{
40-
await Update(entity);
41-
}
40+
var existingEntity = await _objectSet.FindAsync(GetKeyValues(entity));
41+
42+
if (existingEntity != null)
43+
{
44+
_context.Entry(existingEntity).State = EntityState.Detached;
45+
}
4246

47+
_objectSet.Update(entity);
48+
}
49+
50+
private object[] GetKeyValues(T entity)
51+
{
52+
var keyProperties = _context.Model.FindEntityType(typeof(T)).FindPrimaryKey().Properties;
53+
return keyProperties.Select(prop => prop.PropertyInfo.GetValue(entity)).ToArray();
54+
}
4355
}
4456
}

TableBookingAPI/TableBooking.Logic/Repositories/TableRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public TableRepository(TableBookingContext context) : base(context)
1313
public async Task<IEnumerable<Table>> GetTablesByRestaurantIdAsync(Guid restaurantId)
1414
{
1515
return await _objectSet
16-
.Include(x => x.RestaurantId)
16+
.Include(x => x.Restaurant)
1717
.Where(x => x.RestaurantId.Equals(restaurantId))
1818
.ToListAsync();
1919
}

TableBookingAPI/TableBooking.Model/Dtos/BookingDtos/BookingDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class BookingDto
77
public Guid Id { get; set; }
88
public DateTime Date { get; set; }
99
public int DurationInMinutes { get; set; }
10-
public TableDto TableDto { get; set; }
11-
public Guid UserId { get; set; }
10+
public int AmountOfPeople { get; set; }
11+
public Guid AppUserId { get; set; }
1212
}
1313
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
namespace TableBooking.Model.Dtos.BookingDtos
1+
using TableBooking.Model.Models;
2+
3+
namespace TableBooking.Model.Dtos.BookingDtos
24
{
35
public class CreateBookingDto
46
{
57
public DateTime Date { get; set; }
68
public int DurationInMinutes { get; set; }
7-
public Guid TableId { get; set; }
9+
public int AmountOfPeople { get; set; }
810
}
911
}

TableBookingAPI/TableBooking.Model/Dtos/BookingDtos/UpdateBookingDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public class UpdateBookingDto
44
{
55
public DateTime Date { get; set; }
66
public int DurationInMinutes { get; set; }
7-
public Guid TableId { get; set; }
7+
public int AmountOfPeople { get; set; }
88
}
99
}

TableBookingAPI/TableBooking.Model/Dtos/RestaurantDtos/RestaurantShortInfoDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class RestaurantShortInfoDto
77
public string Name { get; set; }
88
public string Type { get; set; }
99
public string Description { get; set; }
10+
public string Phone { get; set; }
1011
public string Location { get; set; }
1112
public string ImageURL { get; set; }
1213
public int Rating { get; set; }
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace TableBooking.Model.Dtos.TableDtos
1+
using TableBooking.Model.Models;
2+
3+
namespace TableBooking.Model.Dtos.TableDtos
24
{
35
public class GetTablesDto
46
{
57
public Guid Id { get; set; }
68
public int NumberOfSeats { get; set; }
79
public Guid RestaurantId { get; set; }
10+
public IEnumerable<Booking>? Bookings { get; set; }
811
}
912
}

TableBookingAPI/TableBooking.Model/Dtos/TableDtos/TableDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace TableBooking.Model.Dtos.TableDtos
44
{
5-
public class TableDto : Entity
5+
public class TableDto
66
{
77
public int NumberOfSeats { get; set; }
88
public Guid RestaurantId { get; set; }

0 commit comments

Comments
 (0)