-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
67 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using AwesomeResult; | ||
using HotwiredBooks.Models; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.Components; | ||
|
||
public interface IBooksRepository | ||
{ | ||
Task<ErrorOr<Book>> Lookup(Guid id); | ||
Task<Result<Book>> Lookup(Guid id); | ||
Task<IEnumerable<Book>> All(); | ||
Task<ErrorOr<Book>> Create(string title, string author); | ||
Task<ErrorOr<Book>> Update(Book book); | ||
Task<ErrorOr<Book>> Delete(Book book); | ||
Task<Result<Book>> Create(string title, string author); | ||
Task<Result<Book>> Update(Book book); | ||
Task<Result<Book>> Delete(Book book); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using AwesomeResult; | ||
|
||
namespace HotwiredBooks.Errors; | ||
|
||
public sealed record Error : IError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using AwesomeResult; | ||
|
||
namespace HotwiredBooks.Errors; | ||
|
||
public sealed record NotFoundError : IError; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using AwesomeResult; | ||
using HotwiredBooks.Errors; | ||
using Microsoft.Extensions.Primitives; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.Extensions; | ||
|
||
public static class FunctionalExtensions | ||
{ | ||
public static ErrorOr<T> ToErrorOr<T>(this T value) => | ||
value is not null ? ErrorOrFactory.From(value) : ErrorOr<T>.From([Error.Failure()]); | ||
public static Result<T> ResultNotNull<T>(this T value) => | ||
value is not null ? value : new Error().Fail<T>(); | ||
|
||
public static ErrorOr<StringValues> JustGetValue(this IFormCollection collection, string key) => | ||
collection.TryGetValue(key, out var value) | ||
? ErrorOrFactory.From(value) | ||
: ErrorOr<StringValues>.From([Error.NotFound()]); | ||
public static Result<StringValues> JustGetValue(this IFormCollection collection, string key) => | ||
collection.TryGetValue(key, out var value) ? value : new NotFoundError().Fail<StringValues>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
using AwesomeResult; | ||
using HotwiredBooks.Models; | ||
using HotwiredBooks.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.ViewComponents; | ||
|
||
public sealed class BookFormViewComponent : ViewComponent | ||
{ | ||
public IViewComponentResult Invoke(ErrorOr<Book> book) => View(new BookFormViewModel(book)); | ||
public IViewComponentResult Invoke(Result<Book> book) => View(new BookFormViewModel(book)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using AwesomeResult; | ||
using HotwiredBooks.Models; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.ViewModels; | ||
|
||
public sealed record BookFormViewModel(ErrorOr<Book> Book); | ||
public sealed record BookFormViewModel(Result<Book> Book); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
HotwiredBooks/Views/Shared/Components/BookForm/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using ErrorOr.Extensions; | ||
using HotwiredBooks.Components; | ||
using AwesomeResult; | ||
|
||
namespace HotwiredBooksTests; | ||
|
||
|