From 501c161fb5f5f1455fca5be367e447f72b2e83aa Mon Sep 17 00:00:00 2001 From: Geert van der Cruijsen Date: Fri, 15 Nov 2019 21:46:29 +0100 Subject: [PATCH] updated details of credits --- Xpirit.BeerXchange/Model/UserCredits.cs | 2 ++ Xpirit.BeerXchange/Services/BeerService.cs | 9 +++++++-- .../components/list-credit/list-credit.component.html | 8 ++++++++ .../app/components/list-credit/list-credit.component.ts | 4 ++-- frontend/xpirit-beerxchange/src/app/model/userCredits.ts | 2 ++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Xpirit.BeerXchange/Model/UserCredits.cs b/Xpirit.BeerXchange/Model/UserCredits.cs index 59f6b34..794f3e2 100644 --- a/Xpirit.BeerXchange/Model/UserCredits.cs +++ b/Xpirit.BeerXchange/Model/UserCredits.cs @@ -9,5 +9,7 @@ public class UserCredits { public string Name { get; set; } public int Credits { get; set; } + public int BeersAdded { get; set; } + public int BeersTaken { get; set; } } } diff --git a/Xpirit.BeerXchange/Services/BeerService.cs b/Xpirit.BeerXchange/Services/BeerService.cs index 55d7ae3..3af28df 100644 --- a/Xpirit.BeerXchange/Services/BeerService.cs +++ b/Xpirit.BeerXchange/Services/BeerService.cs @@ -74,15 +74,20 @@ public async Task> GetAllUserCredits() List userCredits = new List(); foreach (var user in beers.Select(b => b.CreatedBy).Distinct()) { + var beersAdded = beers.Count(b => b.CreatedBy == user); + var beersTaken = beers.Count(b => b.RemovedBy == user); + UserCredits credit = new UserCredits() { Name = user, - Credits = beers.Count(b => b.CreatedBy == user) - beers.Count(b => b.RemovedBy == user) + BeersAdded = beersAdded, + BeersTaken = beersTaken, + Credits = beersAdded - beersTaken }; userCredits.Add(credit); } - return userCredits; + return userCredits.OrderBy(c => c.Name).ToList(); } } } diff --git a/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.html b/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.html index cf17654..eb02ed0 100644 --- a/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.html +++ b/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.html @@ -11,6 +11,14 @@

User Credit Overview

Credits {{element.credits}} + + + Beers Added + {{element.beersAdded}} + + + Beers Taken + {{element.beersTaken}} diff --git a/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.ts b/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.ts index 754d548..8dfa2f2 100644 --- a/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.ts +++ b/frontend/xpirit-beerxchange/src/app/components/list-credit/list-credit.component.ts @@ -9,7 +9,7 @@ import { UserCredits } from '../../model/userCredits'; styleUrls: ['./list-credit.component.css'] }) export class ListCreditComponent implements OnInit { - displayedColumns: string[] = ['name', 'credits']; + displayedColumns: string[] = ['name', 'credits', 'beersAdded', 'beersTaken']; private readonly _subscription: Subscription = new Subscription(); constructor(private fridgeService: FridgeService) { } @@ -24,7 +24,7 @@ export class ListCreditComponent implements OnInit { setUserCreditList() { this._subscription.add(this.fridgeService.getUserCredits().subscribe((userCredits: Array) => { - this.userCredits = userCredits; + this.userCredits = userCredits.sort((x,y) => x.name > y.name ? 1 : -1); })); } diff --git a/frontend/xpirit-beerxchange/src/app/model/userCredits.ts b/frontend/xpirit-beerxchange/src/app/model/userCredits.ts index c36af62..667ba04 100644 --- a/frontend/xpirit-beerxchange/src/app/model/userCredits.ts +++ b/frontend/xpirit-beerxchange/src/app/model/userCredits.ts @@ -1,4 +1,6 @@ export interface UserCredits { name: string; credits: number; + beersAdded: number; + beersTaken: number; } \ No newline at end of file