Skip to content

Commit daf18e3

Browse files
committed
refactor: Relocate DTOs from ApiService.Models to BookStore.Shared.Models and update all consuming code.
1 parent 4ffc626 commit daf18e3

38 files changed

Lines changed: 81 additions & 251 deletions

.refitter

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"generateStatusCodeComments": true,
1212
"typeAccessibility": "public",
1313
"useCancellationTokens": true,
14-
"useIsoDateFormat": false,
14+
"useIsoDateFormat": true,
1515
"outputFolder": "src/Client/BookStore.Client",
1616
"outputFilename": "IBookStoreApiClient.g.cs",
1717
"contractsOutputFolder": "src/Client/BookStore.Client",
@@ -24,7 +24,15 @@
2424
"typeAccessibilityForContracts": "public",
2525
"codeGeneratorSettings": {
2626
"excludedTypeNames": [
27-
"PartialDate"
27+
"PartialDate",
28+
"BookDto",
29+
"AuthorDto",
30+
"CategoryDto",
31+
"PublisherDto",
32+
"PagedListDto"
33+
],
34+
"additionalNamespaceUsings": [
35+
"BookStore.Shared.Models"
2836
]
2937
}
3038
}

src/ApiService/BookStore.ApiService.Tests/Handlers/BookHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using BookStore.ApiService.Events;
44
using BookStore.ApiService.Handlers.Books;
55
using BookStore.ApiService.Infrastructure;
6-
using BookStore.ApiService.Models;
6+
using BookStore.Shared.Models;
77
using Marten;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.Extensions.Logging;

src/ApiService/BookStore.ApiService.Tests/Helpers/BookHelpersTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using BookStore.ApiService.Helpers;
2-
using BookStore.ApiService.Models;
2+
using BookStore.Shared.Models;
33

44
namespace BookStore.ApiService.Tests.Helpers;
55

src/ApiService/BookStore.ApiService/Aggregates/BookAggregate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BookStore.ApiService.Events;
22
using BookStore.ApiService.Infrastructure;
3-
using BookStore.ApiService.Models;
3+
using BookStore.Shared.Models;
44
using Marten;
55

66
namespace BookStore.ApiService.Aggregates;

src/ApiService/BookStore.ApiService/Commands/Authors/AuthorCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace BookStore.ApiService.Commands;
55
/// </summary>
66
public record CreateAuthor(
77
string Name,
8-
Dictionary<string, AuthorTranslationDto>? Translations)
8+
IReadOnlyDictionary<string, AuthorTranslationDto>? Translations)
99
{
1010
public Guid Id { get; init; } = Guid.CreateVersion7();
1111
}
@@ -21,7 +21,7 @@ public record AuthorTranslationDto(string Biography);
2121
public record UpdateAuthor(
2222
Guid Id,
2323
string Name,
24-
Dictionary<string, AuthorTranslationDto>? Translations)
24+
IReadOnlyDictionary<string, AuthorTranslationDto>? Translations)
2525
{
2626
public string? ETag { get; init; }
2727
}

src/ApiService/BookStore.ApiService/Commands/Books/BookCommands.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BookStore.ApiService.Models;
1+
using BookStore.Shared.Models;
22

33
namespace BookStore.ApiService.Commands;
44

@@ -9,11 +9,11 @@ public record CreateBook(
99
string Title,
1010
string? Isbn,
1111
string Language,
12-
Dictionary<string, BookTranslationDto>? Translations,
12+
IReadOnlyDictionary<string, BookTranslationDto>? Translations,
1313
PartialDate? PublicationDate,
1414
Guid? PublisherId,
15-
List<Guid> AuthorIds,
16-
List<Guid> CategoryIds)
15+
IReadOnlyList<Guid> AuthorIds,
16+
IReadOnlyList<Guid> CategoryIds)
1717
{
1818
/// <summary>
1919
/// Unique identifier for the book (generated automatically)
@@ -34,11 +34,11 @@ public record UpdateBook(
3434
string Title,
3535
string? Isbn,
3636
string Language,
37-
Dictionary<string, BookTranslationDto>? Translations,
37+
IReadOnlyDictionary<string, BookTranslationDto>? Translations,
3838
PartialDate? PublicationDate,
3939
Guid? PublisherId,
40-
List<Guid> AuthorIds,
41-
List<Guid> CategoryIds)
40+
IReadOnlyList<Guid> AuthorIds,
41+
IReadOnlyList<Guid> CategoryIds)
4242
{
4343
/// <summary>
4444
/// ETag for optimistic concurrency control

src/ApiService/BookStore.ApiService/Commands/Categories/CategoryCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace BookStore.ApiService.Commands;
44
/// Command to create a new category
55
/// </summary>
66
public record CreateCategory(
7-
Dictionary<string, CategoryTranslationDto> Translations)
7+
IReadOnlyDictionary<string, CategoryTranslationDto> Translations)
88
{
99
public Guid Id { get; init; } = Guid.CreateVersion7();
1010
}
@@ -19,7 +19,7 @@ public record CategoryTranslationDto(string Name, string? Description);
1919
/// </summary>
2020
public record UpdateCategory(
2121
Guid Id,
22-
Dictionary<string, CategoryTranslationDto> Translations)
22+
IReadOnlyDictionary<string, CategoryTranslationDto> Translations)
2323
{
2424
public string? ETag { get; init; }
2525
}

src/ApiService/BookStore.ApiService/Endpoints/Admin/AdminAuthorEndpoints.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace BookStore.ApiService.Commands
66
{
7-
public record CreateAuthorRequest(string Name, Dictionary<string, AuthorTranslationDto>? Translations);
8-
public record UpdateAuthorRequest(string Name, Dictionary<string, AuthorTranslationDto>? Translations);
7+
public record CreateAuthorRequest(string Name, IReadOnlyDictionary<string, AuthorTranslationDto>? Translations);
8+
public record UpdateAuthorRequest(string Name, IReadOnlyDictionary<string, AuthorTranslationDto>? Translations);
99
}
1010

1111
namespace BookStore.ApiService.Endpoints.Admin

src/ApiService/BookStore.ApiService/Endpoints/Admin/AdminBookEndpoints.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BookStore.ApiService.Models;
1+
using System.Collections.Immutable;
2+
using BookStore.Shared.Models;
23
using Marten;
34
using Microsoft.AspNetCore.Mvc;
45
using Wolverine;
@@ -9,21 +10,21 @@ public record CreateBookRequest(
910
string Title,
1011
string? Isbn,
1112
string Language,
12-
Dictionary<string, BookTranslationDto>? Translations,
13+
IReadOnlyDictionary<string, BookTranslationDto>? Translations,
1314
PartialDate? PublicationDate,
1415
Guid? PublisherId,
15-
List<Guid> AuthorIds,
16-
List<Guid> CategoryIds);
16+
IReadOnlyList<Guid> AuthorIds,
17+
IReadOnlyList<Guid> CategoryIds);
1718

1819
public record UpdateBookRequest(
1920
string Title,
2021
string? Isbn,
2122
string Language,
22-
Dictionary<string, BookTranslationDto>? Translations,
23+
IReadOnlyDictionary<string, BookTranslationDto>? Translations,
2324
PartialDate? PublicationDate,
2425
Guid? PublisherId,
25-
List<Guid> AuthorIds,
26-
List<Guid> CategoryIds);
26+
IReadOnlyList<Guid> AuthorIds,
27+
IReadOnlyList<Guid> CategoryIds);
2728
}
2829

2930
namespace BookStore.ApiService.Endpoints.Admin
@@ -73,8 +74,8 @@ static Task<IResult> CreateBook(
7374
request.Translations,
7475
request.PublicationDate,
7576
request.PublisherId,
76-
request.AuthorIds ?? [],
77-
request.CategoryIds ?? []);
77+
request.AuthorIds ?? ImmutableList<Guid>.Empty,
78+
request.CategoryIds ?? ImmutableList<Guid>.Empty);
7879

7980
// Wolverine invokes the handler, manages transaction, and returns result
8081
return bus.InvokeAsync<IResult>(command);
@@ -97,8 +98,8 @@ static Task<IResult> UpdateBook(
9798
request.Translations,
9899
request.PublicationDate,
99100
request.PublisherId,
100-
request.AuthorIds ?? [],
101-
request.CategoryIds ?? [])
101+
request.AuthorIds ?? ImmutableList<Guid>.Empty,
102+
request.CategoryIds ?? ImmutableList<Guid>.Empty)
102103
{
103104
ETag = etag
104105
};

src/ApiService/BookStore.ApiService/Endpoints/Admin/AdminCategoryEndpoints.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
using System.Collections.Immutable;
2+
using BookStore.ApiService.Commands;
13
using Marten;
24
using Microsoft.AspNetCore.Mvc;
35
using Wolverine;
46

57
namespace BookStore.ApiService.Commands
68
{
79
public record CreateCategoryRequest(
8-
Dictionary<string, CategoryTranslationDto>? Translations);
10+
IReadOnlyDictionary<string, CategoryTranslationDto>? Translations);
911

1012
public record UpdateCategoryRequest(
11-
Dictionary<string, CategoryTranslationDto>? Translations);
13+
IReadOnlyDictionary<string, CategoryTranslationDto>? Translations);
1214
}
1315

1416
namespace BookStore.ApiService.Endpoints.Admin
@@ -40,7 +42,7 @@ static Task<IResult> CreateCategory(
4042
[FromBody] Commands.CreateCategoryRequest request,
4143
[FromServices] IMessageBus bus)
4244
{
43-
var translations = request.Translations ?? [];
45+
var translations = request.Translations ?? (IReadOnlyDictionary<string, CategoryTranslationDto>)ImmutableDictionary<string, CategoryTranslationDto>.Empty;
4446
var command = new Commands.CreateCategory(translations);
4547
return bus.InvokeAsync<IResult>(command);
4648
}
@@ -52,7 +54,7 @@ static Task<IResult> UpdateCategory(
5254
HttpContext context)
5355
{
5456
var etag = context.Request.Headers["If-Match"].FirstOrDefault();
55-
var translations = request.Translations ?? [];
57+
var translations = request.Translations ?? (IReadOnlyDictionary<string, CategoryTranslationDto>)ImmutableDictionary<string, CategoryTranslationDto>.Empty;
5658
var command = new Commands.UpdateCategory(id, translations) { ETag = etag };
5759
return bus.InvokeAsync<IResult>(command);
5860
}

0 commit comments

Comments
 (0)