mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 02:01:10 +00:00
Adds refactoring
This commit is contained in:
1 parent
ed0d341513
commit
b9dcb831e9
10 files changed
+184
-102
No files matched your search
+179
-69
@@ -16,25 +16,101 @@
|
||||
#### Add Book Request
|
||||
|
||||
```js
|
||||
POST /books
|
||||
POST api/v1/books
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Yummy Menu",
|
||||
"description": "A menu with yummy food",
|
||||
"sections": [
|
||||
{
|
||||
"name": "Appetizers",
|
||||
"description": "Starters",
|
||||
"items": [
|
||||
{
|
||||
"name": "Fried Pickles",
|
||||
"description": "Deep fried pickles"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"metadata": {
|
||||
"title": "The Fellowship of the Ring",
|
||||
"originalTitle": "The Fellowship of the Ring",
|
||||
"description": "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
|
||||
"releaseInfo": {
|
||||
"originalReleaseDate": "1954-07-29",
|
||||
"originalReleaseYear": 1954,
|
||||
"reReleaseDate": "2001-09-06",
|
||||
"reReleaseYear": 2001,
|
||||
"releaseCountry": "uk",
|
||||
"releaseVersion": "50th Anniversary Edition"
|
||||
},
|
||||
"genres": [
|
||||
{ "name": "fantasy" },
|
||||
{ "name": "adventure" },
|
||||
{ "name": "classic" }
|
||||
],
|
||||
"tags": [
|
||||
{ "name": "epic fantasy" },
|
||||
{ "name": "quest" },
|
||||
{ "name": "middle-earth" }
|
||||
],
|
||||
"language": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"originalLanguage": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"publisher": "Houghton Mifflin",
|
||||
"pageCount": 398
|
||||
},
|
||||
"format": "Paperback",
|
||||
"edition": "50th Anniversary Edition",
|
||||
"volumeNumber": 1,
|
||||
"series": {
|
||||
"title": "The Lord of the Rings"
|
||||
},
|
||||
"asin": "B007978NPG",
|
||||
"goodreadsId": "3",
|
||||
"lccn": "54009621",
|
||||
"oclcNumber": "ocm00012345",
|
||||
"openLibraryId": "OL7603910M",
|
||||
"libraryThingId": "3203347",
|
||||
"googleBooksId": "aWZzLPhY4o0C",
|
||||
"barnesAndNobleId": "1100307790",
|
||||
"appleBooksId": "id395211",
|
||||
"isbns": [
|
||||
{
|
||||
"value": "0395272238",
|
||||
"format": "Isbn10"
|
||||
},
|
||||
{
|
||||
"value": "9780395272237",
|
||||
"format": "Isbn13"
|
||||
}
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"name": "J.R.R. Tolkien",
|
||||
"role": {
|
||||
"name": "author",
|
||||
"category": "book"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Alan Lee",
|
||||
"role": {
|
||||
"name": "illustrator",
|
||||
"category": "book"
|
||||
}
|
||||
}
|
||||
],
|
||||
"ratings": [
|
||||
{
|
||||
"source": "Goodreads",
|
||||
"value": 4.36,
|
||||
"maxValue": 5,
|
||||
"voteCount": 2345678
|
||||
},
|
||||
{
|
||||
"source": "Amazon",
|
||||
"value": 4.7,
|
||||
"maxValue": 5,
|
||||
"voteCount": 87654
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -46,33 +122,92 @@ POST /books
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Yummy Menu",
|
||||
"description": "A menu with yummy food",
|
||||
"averageRating": null,
|
||||
"sections": [
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Appetizers",
|
||||
"description": "Starters",
|
||||
"items": [
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Fried Pickles",
|
||||
"description": "Deep fried pickles"
|
||||
}
|
||||
]
|
||||
}
|
||||
"metadata": {
|
||||
"publisher": "Houghton Mifflin",
|
||||
"pageCount": 398,
|
||||
"title": "The Fellowship of the Ring",
|
||||
"originalTitle": "The Fellowship of the Ring",
|
||||
"description": "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
|
||||
"releaseInfo": {
|
||||
"originalReleaseDate": "1954-07-29",
|
||||
"originalReleaseYear": 1954,
|
||||
"reReleaseDate": "2001-09-06",
|
||||
"reReleaseYear": 2001,
|
||||
"releaseCountry": "uk",
|
||||
"releaseVersion": "50th Anniversary Edition"
|
||||
},
|
||||
"language": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"originalLanguage": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"name": "epic fantasy"
|
||||
},
|
||||
{
|
||||
"name": "quest"
|
||||
},
|
||||
{
|
||||
"name": "middle-earth"
|
||||
}
|
||||
],
|
||||
"hostId": "00000000-0000-0000-0000-000000000000",
|
||||
"dinnerIds": [
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
],
|
||||
"menuReviewIds": [
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
],
|
||||
"createdDateTime": "2020-01-01T00:00:00.0000000Z",
|
||||
"updatedDateTime": "2020-01-01T00:00:00.0000000Z"
|
||||
"genres": [
|
||||
{
|
||||
"name": "fantasy"
|
||||
},
|
||||
{
|
||||
"name": "adventure"
|
||||
},
|
||||
{
|
||||
"name": "classic"
|
||||
}
|
||||
]
|
||||
},
|
||||
"format": "Paperback",
|
||||
"edition": "50th Anniversary Edition",
|
||||
"volumeNumber": 1,
|
||||
"series": null,
|
||||
"asin": "B007978NPG",
|
||||
"goodreadsId": "3",
|
||||
"lccn": "54009621",
|
||||
"oclcNumber": "ocm00012345",
|
||||
"openLibraryId": "OL7603910M",
|
||||
"libraryThingId": "3203347",
|
||||
"googleBooksId": "aWZzLPhY4o0C",
|
||||
"barnesAndNobleId": "1100307790",
|
||||
"appleBooksId": "id395211",
|
||||
"isbNs": [
|
||||
{
|
||||
"value": "0395272238",
|
||||
"format": "Isbn10"
|
||||
},
|
||||
{
|
||||
"value": "9780395272237",
|
||||
"format": "Isbn13"
|
||||
}
|
||||
],
|
||||
"contributors": [],
|
||||
"ratings": [
|
||||
{
|
||||
"value": 4.36,
|
||||
"maxValue": 5,
|
||||
"voteCount": 2345678
|
||||
},
|
||||
{
|
||||
"value": 4.7,
|
||||
"maxValue": 5,
|
||||
"voteCount": 87654
|
||||
}
|
||||
],
|
||||
"id": {
|
||||
"value": "32b336e8-dafc-4a08-9dec-9454e66dd55d"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -92,34 +227,9 @@ GET /books
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Yummy Menu",
|
||||
"description": "A menu with yummy food",
|
||||
"averageRating": null,
|
||||
"sections": [
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Appetizers",
|
||||
"description": "Starters",
|
||||
"items": [
|
||||
{
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"name": "Fried Pickles",
|
||||
"description": "Deep fried pickles"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"hostId": "00000000-0000-0000-0000-000000000000",
|
||||
"dinnerIds": [
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
],
|
||||
"menuReviewIds": [
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
],
|
||||
"createdDateTime": "2020-01-01T00:00:00.0000000Z",
|
||||
"updatedDateTime": "2020-01-01T00:00:00.0000000Z"
|
||||
{
|
||||
"created": "2020-01-01T00:00:00.0000000Z",
|
||||
"updated": "2020-01-01T00:00:00.0000000Z"
|
||||
}
|
||||
]
|
||||
```
|
||||
@@ -25,7 +25,6 @@ class Book
|
||||
Optional<string> libraryThingId,
|
||||
Optional<string> googleBooksId,
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> koboId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
@@ -85,7 +84,6 @@ class Book
|
||||
"libraryThingId": "3203347",
|
||||
"googleBooksId": "aWZzLPhY4o0C",
|
||||
"barnesAndNobleId": "1100307790",
|
||||
"koboId": "the-fellowship-of-the-ring",
|
||||
"appleBooksId": "id395211",
|
||||
"isbns": [
|
||||
{
|
||||
|
||||
@@ -45,13 +45,12 @@ Content-Type: application/json
|
||||
},
|
||||
"asin": "B007978NPG",
|
||||
"goodreadsId": "3",
|
||||
"lccn": "2001025199",
|
||||
"oclcNumber": "48494995",
|
||||
"lccn": "54009621",
|
||||
"oclcNumber": "ocm00012345",
|
||||
"openLibraryId": "OL7603910M",
|
||||
"libraryThingId": "3203347",
|
||||
"googleBooksId": "aWZzLPhY4o0C",
|
||||
"barnesAndNobleId": "1100307790",
|
||||
"koboId": "the-fellowship-of-the-ring",
|
||||
"appleBooksId": "id395211",
|
||||
"isbns": [
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@ public record BookDto(
|
||||
string? LibraryThingId,
|
||||
string? GoogleBooksId,
|
||||
string? BarnesAndNobleId,
|
||||
string? KoboId,
|
||||
string? AppleBooksId,
|
||||
List<IsbnDto> ISBNs,
|
||||
List<Guid> Contributors,
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ public record AddBookCommand(
|
||||
string? LibraryThingId,
|
||||
string? GoogleBooksId,
|
||||
string? BarnesAndNobleId,
|
||||
string? KoboId,
|
||||
string? AppleBooksId,
|
||||
List<IsbnDto> ISBNs,
|
||||
List<MediaContributorDto> Contributors,
|
||||
|
||||
+1
-1
@@ -28,6 +28,7 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<Book>> Handle(AddBookCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: update Api.Book.md documentation when the functionality is fully implemented
|
||||
List<MediaContributorId> contributorIds = new();
|
||||
foreach(var mediaContributor in request.Contributors)
|
||||
{
|
||||
@@ -129,7 +130,6 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
Optional<string>.FromNullable(request.LibraryThingId),
|
||||
Optional<string>.FromNullable(request.GoogleBooksId),
|
||||
Optional<string>.FromNullable(request.BarnesAndNobleId),
|
||||
Optional<string>.FromNullable(request.KoboId),
|
||||
Optional<string>.FromNullable(request.AppleBooksId),
|
||||
domainIsbns,
|
||||
contributorIds,
|
||||
|
||||
+2
-7
@@ -128,11 +128,10 @@ public class AddBookCommandValidator : AbstractValidator<AddBookCommand>
|
||||
.Matches(@"^\d+$").When(x => x.GoodreadsId is not null)
|
||||
.WithMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Code);
|
||||
RuleFor(x => x.LCCN)
|
||||
.Length(12).WithMessage(Errors.WrittenContent.LccnMustBe12CharactersLong.Code)
|
||||
.Matches(@"^[a-z]{0,3}\d{8}$").WithMessage(Errors.WrittenContent.InvalidLccnFormat.Code)
|
||||
.Matches(@"^[a-z]{0,3}\d{8,10}$").WithMessage(Errors.WrittenContent.InvalidLccnFormat.Code)
|
||||
.When(x => x.LCCN is not null);
|
||||
RuleFor(x => x.OCLCNumber)
|
||||
.Matches(@"^(ocm\d{8} |ocn\d{9,}|\(OCoLC\)\d+)$").When(x => x.OCLCNumber is not null)
|
||||
.Matches(@"^(ocm\d{8}|ocn\d{9,}|on\d{10,}|\(OCoLC\)\d{8,}|\d{8,})$").When(x => x.OCLCNumber is not null)
|
||||
.WithMessage(Errors.WrittenContent.InvalidOclcFormat.Code);
|
||||
RuleFor(x => x.OpenLibraryId)
|
||||
.Matches(@"^OL[1-9]\d*[AMW]$").When(x => x.OpenLibraryId is not null)
|
||||
@@ -148,10 +147,6 @@ public class AddBookCommandValidator : AbstractValidator<AddBookCommand>
|
||||
.Length(10).WithMessage(Errors.WrittenContent.BarnesAndNoblesIdMustBe10CharactersLong.Code)
|
||||
.Matches(@"^\d{10}$").WithMessage(Errors.WrittenContent.InvalidBarnesAndNoblesIdFormat.Code)
|
||||
.When(x => x.BarnesAndNobleId is not null);
|
||||
RuleFor(x => x.KoboId)
|
||||
.Matches(@"^\d+$").WithMessage(Errors.WrittenContent.KoboIdMustBeNumeric.Code)
|
||||
.Length(3, 5).WithMessage(Errors.WrittenContent.KoboIdMustBeBetween3And5CharactersLong.Code)
|
||||
.When(x => x.KoboId is not null);
|
||||
RuleFor(x => x.AppleBooksId)
|
||||
.Matches(@"^id\d+$").When(x => x.AppleBooksId is not null)
|
||||
.WithMessage(Errors.WrittenContent.InvalidAppleBooksIdFormat.Code);
|
||||
|
||||
@@ -21,7 +21,6 @@ public static partial class Errors
|
||||
public static Error TheBookIsNotInTheSeries => Error.Forbidden(nameof(TheBookIsNotInTheSeries));
|
||||
public static Error AsinMustBe10CharactersLong => Error.Validation(nameof(AsinMustBe10CharactersLong));
|
||||
public static Error GoodreadsIdMustBeNumeric => Error.Validation(nameof(GoodreadsIdMustBeNumeric));
|
||||
public static Error LccnMustBe12CharactersLong => Error.Validation(nameof(LccnMustBe12CharactersLong));
|
||||
public static Error InvalidLccnFormat => Error.Validation(nameof(InvalidLccnFormat));
|
||||
public static Error InvalidOclcFormat => Error.Validation(nameof(InvalidOclcFormat));
|
||||
public static Error InvalidOpenLibraryId => Error.Validation(nameof(InvalidOpenLibraryId));
|
||||
@@ -30,8 +29,6 @@ public static partial class Errors
|
||||
public static Error InvalidGoogleBooksIdFormat => Error.Validation(nameof(InvalidGoogleBooksIdFormat));
|
||||
public static Error BarnesAndNoblesIdMustBe10CharactersLong => Error.Validation(nameof(BarnesAndNoblesIdMustBe10CharactersLong));
|
||||
public static Error InvalidBarnesAndNoblesIdFormat => Error.Validation(nameof(InvalidBarnesAndNoblesIdFormat));
|
||||
public static Error KoboIdMustBeNumeric => Error.Validation(nameof(KoboIdMustBeNumeric));
|
||||
public static Error KoboIdMustBeBetween3And5CharactersLong => Error.Validation(nameof(KoboIdMustBeBetween3And5CharactersLong));
|
||||
public static Error InvalidAppleBooksIdFormat => Error.Validation(nameof(InvalidAppleBooksIdFormat));
|
||||
public static Error PublisherMustBeMaximum100CharactersLong => Error.Validation(nameof(PublisherMustBeMaximum100CharactersLong));
|
||||
public static Error PageCountMustBeGreaterThanZero => Error.Validation(nameof(PageCountMustBeGreaterThanZero));
|
||||
|
||||
@@ -90,11 +90,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
/// </summary>
|
||||
public Optional<string> BarnesAndNobleId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Kobo ID of the book.
|
||||
/// </summary>
|
||||
public Optional<string> KoboId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Apple Books ID of the book.
|
||||
/// </summary>
|
||||
@@ -143,7 +138,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
/// <param name="libraryThingId">The optional LibraryThing ID of the book.</param>
|
||||
/// <param name="googleBooksId">The optional Google Books ID of the book.</param>
|
||||
/// <param name="barnesAndNobleId">The optional Barnes & Noble ID of the book.</param>
|
||||
/// <param name="koboId">The optional Kobo ID of the book.</param>
|
||||
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
|
||||
/// <param name="isbns">The list of ISBNs of the book.</param>
|
||||
/// <param name="contributors">The list of media contributors of the book.</param>
|
||||
@@ -163,7 +157,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> libraryThingId,
|
||||
Optional<string> googleBooksId,
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> koboId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
@@ -183,7 +176,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
LibraryThingId = libraryThingId;
|
||||
GoogleBooksId = googleBooksId;
|
||||
BarnesAndNobleId = barnesAndNobleId;
|
||||
KoboId = koboId;
|
||||
AppleBooksId = appleBooksId;
|
||||
_isbns = isbns;
|
||||
_contributors = contributors;
|
||||
@@ -218,7 +210,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
/// <param name="libraryThingId">The optional LibraryThing ID of the book.</param>
|
||||
/// <param name="googleBooksId">The optional Google Books ID of the book.</param>
|
||||
/// <param name="barnesAndNobleId">The optional Barnes & Noble ID of the book.</param>
|
||||
/// <param name="koboId">The optional Kobo ID of the book.</param>
|
||||
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
|
||||
/// <param name="isbns">The list of ISBNs of the book.</param>
|
||||
/// <param name="contributors">The list of media contributors of the book.</param>
|
||||
@@ -240,7 +231,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> libraryThingId,
|
||||
Optional<string> googleBooksId,
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> koboId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
@@ -262,7 +252,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
libraryThingId,
|
||||
googleBooksId,
|
||||
barnesAndNobleId,
|
||||
koboId,
|
||||
appleBooksId,
|
||||
isbns,
|
||||
contributors,
|
||||
@@ -286,7 +275,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
/// <param name="libraryThingId">The optional LibraryThing ID of the book.</param>
|
||||
/// <param name="googleBooksId">The optional Google Books ID of the book.</param>
|
||||
/// <param name="barnesAndNobleId">The optional Barnes & Noble ID of the book.</param>
|
||||
/// <param name="koboId">The optional Kobo ID of the book.</param>
|
||||
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
|
||||
/// <param name="isbns">The list of ISBNs of the book.</param>
|
||||
/// <param name="contributors">The list of media contributors of the book.</param>
|
||||
@@ -309,7 +297,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
Optional<string> libraryThingId,
|
||||
Optional<string> googleBooksId,
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> koboId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<MediaContributorId> contributors,
|
||||
@@ -331,7 +318,6 @@ public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
libraryThingId,
|
||||
googleBooksId,
|
||||
barnesAndNobleId,
|
||||
koboId,
|
||||
appleBooksId,
|
||||
isbns,
|
||||
contributors,
|
||||
|
||||
@@ -23,7 +23,6 @@ public record AddBookRequest(
|
||||
string? LibraryThingId,
|
||||
string? GoogleBooksId,
|
||||
string? BarnesAndNobleId,
|
||||
string? KoboId,
|
||||
string? AppleBooksId,
|
||||
List<IsbnDto> ISBNs,
|
||||
List<MediaContributorDto> Contributors,
|
||||
|
||||
Reference in new issue
Block a user