Skip to content

Commit 3ab1c40

Browse files
author
Paul Frank
committed
WIP get user bookings
1 parent d8db01d commit 3ab1c40

File tree

17 files changed

+71
-62
lines changed

17 files changed

+71
-62
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public TableDto TableToTableDto(Table table)
1919
{
2020
return new TableDto
2121
{
22-
RestaurantId = table.Restaurant.Id,
23-
NumberOfSeats = table.NumberOfSeats
22+
RestaurantId = table.RestaurantId,
23+
NumberOfSeats = table.NumberOfSeats,
2424
};
2525
}
2626
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public GetTablesDto TableToTableDto(Table table)
2020
return new GetTablesDto
2121
{
2222
Id = table.Id,
23-
RestaurantId = table.Restaurant.Id,
23+
RestaurantId = table.RestaurantId,
2424
NumberOfSeats = table.NumberOfSeats
2525
};
2626
}

TableBookingAPI/TableBooking.Logic/Interfaces/IBookingRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ namespace TableBooking.Logic.Interfaces
55
public interface IBookingRepository : IGenericRepository<Booking>
66
{
77
public Task<IEnumerable<Booking>> GetAllBookingsForSpecificUserAsync(Guid userId);
8-
public Task<Booking> GetBookingByIdForSpecificUserAsync(Guid bookingId, Guid userId);
8+
public Task<Booking?> GetBookingByIdForSpecificUserAsync(Guid bookingId, Guid userId);
99
}
1010
}

TableBookingAPI/TableBooking.Logic/Repositories/BookingRepository.cs

Lines changed: 3 additions & 3 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.User.Id.Equals(userId)).ToListAsync();
16+
return await _objectSet.Where(x => x.Id.Equals(userId)).ToListAsync();
1717
}
1818

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

TableBookingAPI/TableBooking.Logic/Repositories/TableRepository.cs

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace TableBooking.Model.Dtos.TableDtos
1+
using TableBooking.Model.Models;
2+
3+
namespace TableBooking.Model.Dtos.TableDtos
24
{
3-
public class TableDto
5+
public class TableDto : Entity
46
{
57
public int NumberOfSeats { get; set; }
68
public Guid RestaurantId { get; set; }
Lines changed: 12 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace TableBooking.Model.Migrations
77
{
8-
public partial class initialProperWithOldFixes : Migration
8+
public partial class AppUserId : Migration
99
{
1010
protected override void Up(MigrationBuilder migrationBuilder)
1111
{
@@ -113,7 +113,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
113113
Id = table.Column<Guid>(type: "uuid", nullable: false),
114114
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
115115
DurationInMinutes = table.Column<int>(type: "integer", nullable: false),
116-
UserId = table.Column<Guid>(type: "uuid", nullable: false),
116+
AppUserId = table.Column<Guid>(type: "uuid", nullable: false),
117117
TableId = table.Column<Guid>(type: "uuid", nullable: false)
118118
},
119119
constraints: table =>
@@ -126,22 +126,22 @@ protected override void Up(MigrationBuilder migrationBuilder)
126126
principalColumn: "Id",
127127
onDelete: ReferentialAction.Cascade);
128128
table.ForeignKey(
129-
name: "FK_Bookings_Users_UserId",
130-
column: x => x.UserId,
129+
name: "FK_Bookings_Users_AppUserId",
130+
column: x => x.AppUserId,
131131
principalTable: "Users",
132132
principalColumn: "Id",
133133
onDelete: ReferentialAction.Cascade);
134134
});
135135

136136
migrationBuilder.CreateIndex(
137-
name: "IX_Bookings_TableId",
137+
name: "IX_Bookings_AppUserId",
138138
table: "Bookings",
139-
column: "TableId");
139+
column: "AppUserId");
140140

141141
migrationBuilder.CreateIndex(
142-
name: "IX_Bookings_UserId",
142+
name: "IX_Bookings_TableId",
143143
table: "Bookings",
144-
column: "UserId");
144+
column: "TableId");
145145

146146
migrationBuilder.CreateIndex(
147147
name: "IX_Ratings_AppUserId",

TableBookingAPI/TableBooking.Model/Migrations/TableBookingContextModelSnapshot.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
8787
.ValueGeneratedOnAdd()
8888
.HasColumnType("uuid");
8989

90+
b.Property<Guid>("AppUserId")
91+
.HasColumnType("uuid");
92+
9093
b.Property<DateTime>("Date")
9194
.HasColumnType("timestamp with time zone");
9295

@@ -96,14 +99,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
9699
b.Property<Guid>("TableId")
97100
.HasColumnType("uuid");
98101

99-
b.Property<Guid>("UserId")
100-
.HasColumnType("uuid");
101-
102102
b.HasKey("Id");
103103

104-
b.HasIndex("TableId");
104+
b.HasIndex("AppUserId");
105105

106-
b.HasIndex("UserId");
106+
b.HasIndex("TableId");
107107

108108
b.ToTable("Bookings");
109109
});
@@ -211,21 +211,19 @@ protected override void BuildModel(ModelBuilder modelBuilder)
211211

212212
modelBuilder.Entity("TableBooking.Model.Models.Booking", b =>
213213
{
214-
b.HasOne("TableBooking.Model.Models.Table", "Table")
214+
b.HasOne("TableBooking.Model.Models.AppUser", null)
215215
.WithMany("Bookings")
216-
.HasForeignKey("TableId")
216+
.HasForeignKey("AppUserId")
217217
.OnDelete(DeleteBehavior.Cascade)
218218
.IsRequired();
219219

220-
b.HasOne("TableBooking.Model.Models.AppUser", "User")
220+
b.HasOne("TableBooking.Model.Models.Table", "Table")
221221
.WithMany("Bookings")
222-
.HasForeignKey("UserId")
222+
.HasForeignKey("TableId")
223223
.OnDelete(DeleteBehavior.Cascade)
224224
.IsRequired();
225225

226226
b.Navigation("Table");
227-
228-
b.Navigation("User");
229227
});
230228

231229
modelBuilder.Entity("TableBooking.Model.Models.Rating", b =>
@@ -249,13 +247,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
249247

250248
modelBuilder.Entity("TableBooking.Model.Models.Table", b =>
251249
{
252-
b.HasOne("TableBooking.Model.Models.Restaurant", "Restaurant")
250+
b.HasOne("TableBooking.Model.Models.Restaurant", null)
253251
.WithMany("Tables")
254252
.HasForeignKey("RestaurantId")
255253
.OnDelete(DeleteBehavior.Cascade)
256254
.IsRequired();
257-
258-
b.Navigation("Restaurant");
259255
});
260256

261257
modelBuilder.Entity("TableBooking.Model.Models.AppUser", b =>

TableBookingAPI/TableBooking.Model/Models/Booking.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class Booking : Entity
55
public DateTime Date { get; set; }
66
public int DurationInMinutes { get; set; }
77
public Table Table { get; set; }
8-
public AppUser User { get; set; }
8+
public Guid AppUserId { get; set; }
99
public Guid TableId { get; set; }
1010
}
1111
}

0 commit comments

Comments
 (0)