Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

87 show personalized favorites #131

Merged
merged 62 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
351f12a
Add UserContract table to database
JacobBredin May 7, 2022
71ad5b3
Add services and infrastructure
JacobBredin May 7, 2022
341f881
Add server side endpoints
JacobBredin May 7, 2022
2df1222
Add client endpoints
JacobBredin May 7, 2022
eb4c535
Fix broken tests
JacobBredin May 7, 2022
f0fd186
Remove IsFavorite from contract
JacobBredin May 7, 2022
44485ba
Fix documentation
pkasinski May 7, 2022
ec3928d
Remove unnecessary method from FavoritesController
pkasinski May 7, 2022
c2c24b0
Rename methods in FavoritesController
pkasinski May 7, 2022
c807fc1
Move unit tests to separate files
JacobBredin May 7, 2022
2c5f846
Merge branch '87-show-personalized-favorites-2' of https://github.com…
JacobBredin May 7, 2022
4e745bf
Incomplete tests for FavoritesController
JacobBredin May 7, 2022
dac7dfa
Add tests to FavoriteContractServiceTests
pkasinski May 7, 2022
fbc8178
Add FavoriteButton unit tests
JacobBredin May 8, 2022
87c7d3b
Merge branch '87-show-personalized-favorites-2' of https://github.com…
JacobBredin May 8, 2022
9e69123
Fix incorrect logger in EFFavoriteRepository
JacobBredin May 8, 2022
8b60139
Change a test in FavoriteContractServiceTests
pkasinski May 8, 2022
10bf183
Rename method in FavoritesController
pkasinski May 8, 2022
5dc8b76
Add tests to FavoritesControllerTests
pkasinski May 8, 2022
b185b5b
Add exception handling
JacobBredin May 8, 2022
c7aa5a7
Add unit tests
JacobBredin May 8, 2022
ca74421
Merge branch '87-show-personalized-favorites-2' of https://github.com…
JacobBredin May 8, 2022
bb75820
Add and fix unit tests
JacobBredin May 9, 2022
d4573e4
Add exception handling to FavoritesController
JacobBredin May 9, 2022
672125d
Add migration for removing IsFavorite in contract
JacobBredin May 9, 2022
7607af5
Merge master into branch
JacobBredin May 9, 2022
cb5b599
Refactor FavoritesService to be smarter
JacobBredin May 9, 2022
6c52986
Rename method
JacobBredin May 9, 2022
2e0ca4a
Fix tests
JacobBredin May 9, 2022
a4127d0
Fix tests
JacobBredin May 9, 2022
fa58bcc
merge master into branch
JacobBredin May 9, 2022
df710e1
Apply suggestions from code review
JacobBredin May 9, 2022
7c83eeb
Fix broken test
JacobBredin May 9, 2022
7db80af
Rename FetchAllFavorites to FetchAll
pkasinski May 9, 2022
07d84d8
Hide user collection in contract
JacobBredin May 9, 2022
79c42ec
Merge branch '87-show-personalized-favorites-2' of https://github.com…
JacobBredin May 9, 2022
74d2501
Add documentation to EF navigation property
JacobBredin May 10, 2022
0e9c90e
Rename database table
JacobBredin May 11, 2022
560944d
Move favorite methods to user service and repo
JacobBredin May 11, 2022
9ba4b44
Change the structure of endpoint URLs in FavoritesController
pkasinski May 11, 2022
3a534d4
Remove Favorite service and repo
JacobBredin May 11, 2022
ebf003f
Fix broken test for contract repo
JacobBredin May 11, 2022
6628e1b
Make adjustments in FavoritesController
pkasinski May 11, 2022
14b9cfd
Add tests to FavoritesControllerTests
pkasinski May 11, 2022
57af96f
Fix broken favorites tests
JacobBredin May 11, 2022
e1c7208
Move SetFavoriteContract.cs to Application/Users
pkasinski May 11, 2022
c9d7608
Fix broken tests
JacobBredin May 11, 2022
674e641
Fix merge conflicts
JacobBredin May 11, 2022
74e281f
Fix build error
JacobBredin May 11, 2022
e890421
Rename method in ContractCard
pkasinski May 11, 2022
c50a836
Remove null-forgiving operator
pkasinski May 11, 2022
f295b5c
Rename SetFavoriteContract to FavoriteContractDto
JacobBredin May 12, 2022
87fad1c
Fix favorite controller endpoint bug
JacobBredin May 12, 2022
ac9d14a
Add check to LoggedInUser
JacobBredin May 12, 2022
9ec7c15
Make adjustments in FavoriteButtonTests
pkasinski May 12, 2022
5aba061
Apply suggestions from code review
JacobBredin May 12, 2022
038569b
Merge branch 'master' into 87-show-personalized-favorites-2
JacobBredin May 12, 2022
2f706ff
Rewrite documentation in unit test
JacobBredin May 12, 2022
b62ca10
Inject ISessionService
pkasinski May 13, 2022
58d2c1e
Fix tests in FavoriteButtonTests and FavoriteCardsTests
pkasinski May 13, 2022
3c1ec80
Use the IsAuthenticated property
pkasinski May 13, 2022
137d604
Merge master into branch
JacobBredin May 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/Client/Pages/Contracts/FavoriteButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using System.Text
@using Application.Users
@inject HttpClient _http
@inject ISessionService _session

<button class="btn ms-auto p-2 flex-shrink-0" id="favorite-button" @onclick="ChangeFavorite">
@if (isFavorite)
Expand Down Expand Up @@ -34,22 +35,16 @@
[Parameter]
public EventCallback<(Guid, bool)> OnFavoriteChange { get; set; } = EventCallback<(Guid, bool)>.Empty;

/// <summary>
/// The name of the currently logged in user.
/// </summary>
[CascadingParameter(Name = nameof(LoggedInUser))]
public string? LoggedInUser { get; set; }

/// <summary>
/// Whether the contract is marked as favorite.
/// </summary>
private bool isFavorite { get; set; }

protected override async void OnInitialized()
{
if (!string.IsNullOrEmpty(LoggedInUser))
if (!string.IsNullOrEmpty(_session.Username))
pkasinski marked this conversation as resolved.
Show resolved Hide resolved
{
HttpResponseMessage response = await _http.GetAsync($"/api/v1/users/{LoggedInUser}/favorites/{Contract.Id}");
HttpResponseMessage response = await _http.GetAsync($"/api/v1/users/{_session.Username}/favorites/{Contract.Id}");
isFavorite = response.IsSuccessStatusCode;
}
else
Expand All @@ -62,11 +57,11 @@

private async Task ChangeFavorite()
{
if (!string.IsNullOrEmpty(LoggedInUser))
if (!string.IsNullOrEmpty(_session.Username))
pkasinski marked this conversation as resolved.
Show resolved Hide resolved
{
FavoriteContractDto favoriteContract = new() { UserName = LoggedInUser, ContractId = Contract.Id, IsFavorite = !isFavorite };
FavoriteContractDto favoriteContract = new() { UserName = _session.Username, ContractId = Contract.Id, IsFavorite = !isFavorite };

HttpResponseMessage response = await _http.PostAsJsonAsync($"/api/v1/users/{LoggedInUser}/favorites", favoriteContract);
HttpResponseMessage response = await _http.PostAsJsonAsync($"/api/v1/users/{_session.Username}/favorites", favoriteContract);
if (response.IsSuccessStatusCode)
{
isFavorite = !isFavorite;
Expand Down
9 changes: 2 additions & 7 deletions src/Client/Pages/Dashboard/FavoriteCards.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@using Domain.Contracts
@using Newtonsoft.Json
@inject HttpClient _http
@inject ISessionService _session

<div id="favorite-contracts" style="padding-top: 30px;">
<h3>Favoriter</h3>
<FetchData @ref="_dataFetcher"
TData="List<Contract>"
Url=@($"/api/v1/users/{LoggedInUser}/favorites")
Url=@($"/api/v1/users/{_session.Username}/favorites")
Context="contracts">
@{
var contractsList = contracts.ToList();
Expand Down Expand Up @@ -34,12 +35,6 @@
@code {
private FetchData<List<Contract>> _dataFetcher = null!;

/// <summary>
/// The name of the currently logged in user.
/// </summary>
[CascadingParameter(Name = nameof(LoggedInUser))]
public string? LoggedInUser { get; set; }

private async Task OnFavoriteChange((Guid Id, bool IsFavorite)args)
{
if (args.IsFavorite) return;
Expand Down