-
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
103 additions
and
78 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,8 +1,11 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer> | ||
<Assembly Path="/home/andreas/.nuget/packages/erroror/1.3.0/lib/net6.0/ErrorOr.dll" /> | ||
</AssemblyExplorer></s:String> | ||
|
||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=56f95705_002D69f0_002D4d78_002D9fec_002Db8596a7edfd4/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="Create_inserts_value_into_repository" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=56f95705_002D69f0_002D4d78_002D9fec_002Db8596a7edfd4/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Create_inserts_value_into_repository" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> | ||
<Project Location="/home/andreas/code/HotwiredBooks/HotwiredBooksTests" Presentation="&lt;HotwiredBooksTests&gt;" /> | ||
</SessionState></s:String> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7a5365d0_002Db616_002D4d4b_002D83e3_002Df6bda9b641db/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Create_inserts_value_into_repository #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7a5365d0_002Db616_002D4d4b_002D83e3_002Df6bda9b641db/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="Create_inserts_value_into_repository #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> | ||
<Project Location="/home/andreas/code/HotwiredBooks/HotwiredBooksTests" Presentation="&lt;HotwiredBooksTests&gt;" /> | ||
</SessionState></s:String></wpf:ResourceDictionary> |
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 HotwiredBooks.Models; | ||
using MonadicBits; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.Components; | ||
|
||
public interface IBooksRepository | ||
{ | ||
Task<Maybe<Book>> Lookup(Guid id); | ||
Task<ErrorOr<Book>> Lookup(Guid id); | ||
Task<IEnumerable<Book>> All(); | ||
Task<Maybe<Book>> Create(string title, string author); | ||
Task<Maybe<Book>> Update(Book book); | ||
Task<Maybe<Book>> Delete(Book book); | ||
Task<ErrorOr<Book>> Create(string title, string author); | ||
Task<ErrorOr<Book>> Update(Book book); | ||
Task<ErrorOr<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,7 @@ | ||
namespace HotwiredBooks.Extensions; | ||
|
||
public static class AsyncExtensions | ||
{ | ||
public static Task<T> AsTask<T>(this T value) => | ||
Task.FromResult(value); | ||
} |
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,9 @@ | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.Extensions; | ||
|
||
public static class ErrorOrExtensions | ||
{ | ||
public static ErrorOr<T> Success<T>(this T value) => | ||
ErrorOrFactory.From(value); | ||
} |
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,26 +1,27 @@ | ||
using Microsoft.Extensions.Primitives; | ||
using MonadicBits; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.Extensions; | ||
|
||
using static Functional; | ||
|
||
public static class FunctionalExtensions | ||
{ | ||
public static Maybe<T> ToMaybe<T>(this T value) => value?.Just() ?? Nothing; | ||
public static ErrorOr<T> ToErrorOr<T>(this T value) => | ||
value is not null ? ErrorOrFactory.From(value) : ErrorOr<T>.From([Error.Failure()]); | ||
|
||
public static Maybe<StringValues> JustGetValue(this IFormCollection collection, string key) => | ||
collection.TryGetValue(key, out var value) ? value.Just() : Nothing; | ||
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 T OrElse<T>(this Maybe<T> maybe, T orElse) => | ||
maybe.Match(value => value, () => orElse); | ||
public static T OrElse<T>(this ErrorOr<T> maybe, T orElse) => | ||
maybe.Match(value => value, _ => orElse); | ||
|
||
public static T OrElse<T>(this Maybe<T> maybe, Func<T> orElse) => | ||
maybe.Match(value => value, orElse); | ||
public static T OrElse<T>(this ErrorOr<T> maybe, Func<T> orElse) => | ||
maybe.Match(value => value, _ => orElse()); | ||
|
||
public static async Task<T> OrElse<T>(this Task<Maybe<T>> maybe, Func<T> orElse) => | ||
(await maybe).Match(value => value, orElse); | ||
public static async Task<T> OrElse<T>(this Task<ErrorOr<T>> maybe, Func<T> orElse) => | ||
(await maybe).Match(value => value, _ => orElse()); | ||
|
||
public static async Task<T> OrElse<T>(this Task<Maybe<T>> maybe, T orElse) => | ||
(await maybe).Match(value => value, () => orElse); | ||
public static async Task<T> OrElse<T>(this Task<ErrorOr<T>> maybe, T orElse) => | ||
(await maybe).Match(value => value, _ => orElse); | ||
} |
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 HotwiredBooks.Models; | ||
using HotwiredBooks.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MonadicBits; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.ViewComponents; | ||
|
||
public sealed class BookFormViewComponent : ViewComponent | ||
{ | ||
public IViewComponentResult Invoke(Maybe<Book> book) => View(new BookFormViewModel(book)); | ||
public IViewComponentResult Invoke(ErrorOr<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 HotwiredBooks.Models; | ||
using MonadicBits; | ||
using ErrorOr; | ||
|
||
namespace HotwiredBooks.ViewModels; | ||
|
||
public sealed record BookFormViewModel(Maybe<Book> Book); | ||
public sealed record BookFormViewModel(ErrorOr<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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
@using HotwiredBooks.Extensions | ||
@using MonadicBits | ||
@using HotwiredBooks.TagHelpers | ||
@using HotwiredBooks.ViewComponents | ||
@model HotwiredBooks.ViewModels.BooksEditViewModel | ||
@{ | ||
Layout = null; | ||
} | ||
|
||
<turbo-frame id="@Html.DomId(Model.Book)"> | ||
<vc:book-form book="@Model.Book.Just()"/> | ||
<vc:book-form book="@Model.Book.Success()"/> | ||
</turbo-frame> |
11 changes: 6 additions & 5 deletions
11
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