Skip to content

Commit

Permalink
updated details of credits
Browse files Browse the repository at this point in the history
  • Loading branch information
Geertvdc committed Nov 15, 2019
1 parent 53525cf commit 501c161
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Xpirit.BeerXchange/Model/UserCredits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
9 changes: 7 additions & 2 deletions Xpirit.BeerXchange/Services/BeerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ public async Task<List<UserCredits>> GetAllUserCredits()
List<UserCredits> userCredits = new List<UserCredits>();
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ <h2>User Credit Overview</h2>
<ng-container matColumnDef="credits">
<th mat-header-cell *matHeaderCellDef> Credits </th>
<td mat-cell *matCellDef="let element"> {{element.credits}} </td>
</ng-container>
<ng-container matColumnDef="beersAdded">
<th mat-header-cell *matHeaderCellDef> Beers Added </th>
<td mat-cell *matCellDef="let element"> {{element.beersAdded}} </td>
</ng-container>
<ng-container matColumnDef="beersTaken">
<th mat-header-cell *matHeaderCellDef> Beers Taken </th>
<td mat-cell *matCellDef="let element"> {{element.beersTaken}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand All @@ -24,7 +24,7 @@ export class ListCreditComponent implements OnInit {

setUserCreditList() {
this._subscription.add(this.fridgeService.getUserCredits().subscribe((userCredits: Array<UserCredits>) => {
this.userCredits = userCredits;
this.userCredits = userCredits.sort((x,y) => x.name > y.name ? 1 : -1);
}));
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/xpirit-beerxchange/src/app/model/userCredits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface UserCredits {
name: string;
credits: number;
beersAdded: number;
beersTaken: number;
}

0 comments on commit 501c161

Please sign in to comment.