Skip to content

Commit dd53edd

Browse files
authored
Chore/form category (#21)
* chore: form category * chore: multi select * fix: select * chore: dto * fix: post create * chore: form category * chore: code review * fix: test
1 parent fc84eac commit dd53edd

File tree

22 files changed

+513
-356
lines changed

22 files changed

+513
-356
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace Evently.Server.Common.Domains.Models;
2+
3+
// [{"categoryId":1,"gatheringId":22},{"categoryId":2,"gatheringId":22}]
4+
public sealed record GatheringCategoryDetailDto(long GatheringId, long CategoryId);

src/Evently.Server/Common/Domains/Models/GatheringReqDto.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public sealed record GatheringReqDto(
99
DateTimeOffset? CancellationDateTime,
1010
string Location,
1111
string OrganiserId,
12-
string? CoverSrc
12+
string? CoverSrc,
13+
List<GatheringCategoryDetailDto> GatheringCategoryDetails
1314
);

src/Evently.Server/Common/Extensions/MapperExtension.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace Evently.Server.Common.Extensions;
55

66
public static class MapperExtension {
77
public static Gathering ToGathering(this GatheringReqDto gatheringReqDto) {
8+
List<GatheringCategoryDetail> gatheringCategoryDetails = gatheringReqDto.GatheringCategoryDetails
9+
.Select((detail) => new GatheringCategoryDetail {
10+
GatheringId = gatheringReqDto.GatheringId,
11+
CategoryId = detail.CategoryId,
12+
})
13+
.ToList();
814
Gathering gathering = new() {
915
GatheringId = gatheringReqDto.GatheringId,
1016
Name = gatheringReqDto.Name,
@@ -15,11 +21,15 @@ public static Gathering ToGathering(this GatheringReqDto gatheringReqDto) {
1521
Location = gatheringReqDto.Location,
1622
OrganiserId = gatheringReqDto.OrganiserId,
1723
CoverSrc = gatheringReqDto.CoverSrc,
24+
GatheringCategoryDetails = gatheringCategoryDetails,
1825
};
1926
return gathering;
2027
}
2128

2229
public static GatheringReqDto ToGatheringDto(this Gathering gathering) {
30+
List<GatheringCategoryDetailDto> gatheringCategoryDetails = gathering.GatheringCategoryDetails
31+
.Select(detail => new GatheringCategoryDetailDto(detail.GatheringId, detail.CategoryId))
32+
.ToList();
2333
GatheringReqDto reqDto = new(
2434
gathering.GatheringId,
2535
gathering.Name,
@@ -29,7 +39,8 @@ public static GatheringReqDto ToGatheringDto(this Gathering gathering) {
2939
gathering.CancellationDateTime,
3040
gathering.Location,
3141
gathering.OrganiserId,
32-
gathering.CoverSrc
42+
gathering.CoverSrc,
43+
gatheringCategoryDetails
3344
);
3445
return reqDto;
3546
}

src/Evently.Server/Features/Accounts/AccountController.cs renamed to src/Evently.Server/Features/Accounts/Controllers/AccountController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.AspNetCore.Mvc;
1010
using System.Security.Claims;
1111

12-
namespace Evently.Server.Features.Accounts;
12+
namespace Evently.Server.Features.Accounts.Controllers;
1313

1414
// Based on https://tinyurl.com/26arz8vk
1515
[ApiController]

src/Evently.Server/Features/Bookings/BookingsController.cs renamed to src/Evently.Server/Features/Bookings/Controllers/BookingsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Globalization;
88
using System.Threading.Channels;
99

10-
namespace Evently.Server.Features.Bookings;
10+
namespace Evently.Server.Features.Bookings.Controllers;
1111

1212
[ApiController]
1313
[Route("api/v1/[controller]")]

src/Evently.Server/Features/Bookings/Services/BookingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task<Booking> CreateBooking(BookingReqDto bookingReqDto) {
7070
if (!validationResult.IsValid) {
7171
throw new ArgumentException($"Account has already booked this gathering (GatheringId: {booking.GatheringId})");
7272
}
73-
73+
7474
booking.BookingId = $"book_{await Nanoid.GenerateAsync(size: 10)}";
7575
await db.Bookings.AddAsync(booking);
7676
await db.SaveChangesAsync();

src/Evently.Server/Features/Categories/CategoriesController.cs renamed to src/Evently.Server/Features/Categories/Controllers/CategoriesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.AspNetCore.Mvc;
55
using System.Globalization;
66

7-
namespace Evently.Server.Features.Categories;
7+
namespace Evently.Server.Features.Categories.Controllers;
88

99
[ApiController]
1010
[Route("api/v1/[controller]")]

src/Evently.Server/Features/Gatherings/GatheringsController.cs renamed to src/Evently.Server/Features/Gatherings/Controllers/GatheringsController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
using Evently.Server.Common.Domains.Models;
44
using Evently.Server.Common.Extensions;
55
using Evently.Server.Features.Accounts.Services;
6-
using FluentValidation;
76
using Microsoft.AspNetCore.Authentication;
87
using Microsoft.AspNetCore.Identity;
98
using Microsoft.AspNetCore.Mvc;
109
using MimeKit;
1110
using System.Globalization;
1211

13-
namespace Evently.Server.Features.Gatherings;
12+
namespace Evently.Server.Features.Gatherings.Controllers;
1413

1514
[ApiController]
1615
[Route("api/v1/[controller]")]

src/Evently.Server/Features/Gatherings/Services/GatheringService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public async Task<Gathering> UpdateGathering(long gatheringId, GatheringReqDto g
7878
}
7979

8080
Gathering current = await db.Gatherings.AsTracking()
81+
.Include((g) => g.GatheringCategoryDetails)
8182
.FirstOrDefaultAsync((ex) => ex.GatheringId == gatheringId)
8283
?? throw new KeyNotFoundException($"{gatheringId} not found");
8384

@@ -87,6 +88,7 @@ public async Task<Gathering> UpdateGathering(long gatheringId, GatheringReqDto g
8788
current.End = gathering.End;
8889
current.Location = gathering.Location;
8990
current.CoverSrc = gathering.CoverSrc;
91+
current.GatheringCategoryDetails = gathering.GatheringCategoryDetails;
9092

9193
await db.SaveChangesAsync();
9294
return current;

src/Evently.Server/Features/HealthChecks/HealthChecksController.cs renamed to src/Evently.Server/Features/HealthChecks/Controllers/HealthChecksController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.Extensions.Diagnostics.HealthChecks;
33

4-
namespace Evently.Server.Features.HealthChecks;
4+
namespace Evently.Server.Features.HealthChecks.Controllers;
55

66
[ApiController]
77
[Route("api/v1/[controller]")]

0 commit comments

Comments
 (0)