Skip to content

Commit

Permalink
Development (#70)
Browse files Browse the repository at this point in the history
* closes #31

* Signed-off-by: jvanderbiest <[email protected]>

* closes #19

* closes #30

* stackexchange exceptional removed, elmah added

* elmah

* closes #29

* close #25

* close

* #33

* #33

* issue

* #33 first test

* Signed-off-by: jvanderbiest <[email protected]>

* #34

* #34

* fix error handling

* fix build

* add jasmine locally for build

* add packages for build

* try to fix build

* code coverage #34

* fix build

* closes #34

* shields

* code cov

* fix coverage

* fix code coverage

* fix coverage

* splitting components + accountservice cleanup (1)

* #27

* #27

* #23

* #23 add more

* #27

* closes #36

* #27 #21

* #27 order docdb logic

* fix tests #27

* tests

* codecov

* fix backend build

* fix codecov?

* #21

* test

* various fixes

* fixes menu

* fix observable package

* resolve implicit any type

* resolve implicit any type 2

* #closes 54, reads from package.json and replace in component

* closes #58

* closes #52

* closes #60

* closes #41

* #41

* closes #47, adds send email

* #47

* fix price to display always in #.00 notation
price is also visible in popup when ordering

* fix disposed object on ApplicationUserManager

* Fixed:
 - changed "Pasta kip - kaassaus" from decription to name in list
 - Issue when user has more than 5 orders 
 - balance is updated after placing an order
 - cannot order 2 times on same day 
 
Added:
 - List of 5 latest orders.
  • Loading branch information
jvanderbiest authored Aug 10, 2016
1 parent deb032d commit 4dd02e1
Show file tree
Hide file tree
Showing 30 changed files with 169 additions and 45 deletions.
20 changes: 20 additions & 0 deletions backend/WebApi/Lunchorder.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web.Http;
using Lunchorder.Common.Interfaces;
using Lunchorder.Domain.Constants;
using Lunchorder.Domain.Dtos;
using Lunchorder.Domain.Dtos.Responses;
using Microsoft.AspNet.Identity;
using Swashbuckle.Swagger.Annotations;
Expand Down Expand Up @@ -40,6 +42,24 @@ public async Task<IHttpActionResult> Get()
return Ok(await _accountControllerService.GetUserInfo(claimsIdentity));
}

/// <summary>
/// Gets the last 5 orders for a user
/// </summary>
/// <returns></returns>
[Route("last5Orders")]
[HttpGet]
[Authorize]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<LastOrder>))]
public async Task<IHttpActionResult> GetLast5Orders()
{
var claimsIdentity = User.Identity as ClaimsIdentity;

if (claimsIdentity == null)
return InternalServerError();

return Ok(await _accountControllerService.GetLast5Orders(claimsIdentity));
}

/// <summary>
/// Gets all the users of the platform
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions backend/WebApi/Lunchorder.Api/Controllers/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<IHttpActionResult> Post(PostMenuRequest postMenuRequest)
/// <returns></returns>
[Route("")]
[HttpPut]
[SwaggerResponse(HttpStatusCode.OK)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(Domain.Dtos.Menu))]
public async Task<IHttpActionResult> Put(PutMenuRequest putMenuRequest)
{
await _menuControllerService.Update(putMenuRequest.Menu);
Expand All @@ -65,7 +65,7 @@ public async Task<IHttpActionResult> Put(PutMenuRequest putMenuRequest)
/// <returns></returns>
[Route("active/{menuId}")]
[HttpPost]
[SwaggerResponse(HttpStatusCode.OK)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(Domain.Dtos.Menu))]
public async Task<IHttpActionResult> SetActive(string menuId)
{
// todo, only authorize admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Lunchorder.Common.Extensions;
using Lunchorder.Common.Interfaces;
using Lunchorder.Domain.Dtos;
using Lunchorder.Domain.Dtos.Responses;
using Microsoft.AspNet.Identity;

Expand Down Expand Up @@ -73,5 +74,11 @@ public async Task<GetAllUsersResponse> GetAllUsers()
var users = await _databaseRepository.GetUsers();
return new GetAllUsersResponse() { Users = users };
}

public async Task<IEnumerable<LastOrder>> GetLast5Orders(ClaimsIdentity claimsIdentity)
{
var userInfo = await _databaseRepository.GetUserInfo(claimsIdentity.GetUserName());
return userInfo.Last5Orders;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Lunchorder.Domain.Constants;
using Lunchorder.Domain.Dtos;
using Lunchorder.Domain.Entities.Eventing;
using Lunchorder.Domain.Exceptions;
using Newtonsoft.Json;
using Menu = Lunchorder.Domain.Dtos.Menu;
using UserOrderHistory = Lunchorder.Domain.Dtos.UserOrderHistory;
Expand Down Expand Up @@ -47,13 +48,37 @@ public Task Delete(Guid orderId)

public async Task Add(string userId, string userName, IEnumerable<MenuOrder> menuOrders)
{
var vendorId = await GetVendorId();
var menuOrderHistoryEntries = _mapper.Map<IEnumerable<MenuOrder>, IEnumerable<UserOrderHistoryEntry>>(menuOrders);
var menu = await GetMenu();

if (!string.IsNullOrEmpty(menu.Vendor.SubmitOrderTime))
{
DateTime parsedOrderDateTime;
if (DateTime.TryParse(menu.Vendor.SubmitOrderTime, out parsedOrderDateTime))
{
if (TimeSpan.Compare(parsedOrderDateTime.TimeOfDay, DateTime.UtcNow.TimeOfDay) <= 0)
{
throw new BusinessException($"Sorry, you were too late to submit your order for today");
}
}
}
else
{
var menuOrderHistoryEntries =
_mapper.Map<IEnumerable<MenuOrder>, IEnumerable<UserOrderHistoryEntry>>(menuOrders);

var userOrderHistory = new UserOrderHistory { Id = Guid.NewGuid(), OrderTime = DateTime.UtcNow, Entries = menuOrderHistoryEntries };
var userOrderHistory = new UserOrderHistory
{
Id = Guid.NewGuid(),
OrderTime = DateTime.UtcNow,
Entries = menuOrderHistoryEntries
};

await _databaseRepository.AddOrder(userId, userName, vendorId, new DateGenerator().GenerateDateFormat(DateTime.UtcNow), userOrderHistory);
_eventingService.SendMessage(new Message(ServicebusType.AddUserOrder, JsonConvert.SerializeObject(userOrderHistory)));
await
_databaseRepository.AddOrder(userId, userName, menu.Vendor.Id,
new DateGenerator().GenerateDateFormat(DateTime.UtcNow), userOrderHistory);
_eventingService.SendMessage(new Message(ServicebusType.AddUserOrder,
JsonConvert.SerializeObject(userOrderHistory)));
}
}

public async Task<string> GetEmailVendorHistory(DateTime dateTime)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Lunchorder.Domain.Dtos;
using Lunchorder.Domain.Dtos.Responses;

namespace Lunchorder.Common.Interfaces
Expand All @@ -8,5 +10,6 @@ public interface IAccountControllerService
{
Task<GetUserInfoResponse> GetUserInfo(ClaimsIdentity claimsIdentity);
Task<GetAllUsersResponse> GetAllUsers();
Task<IEnumerable<LastOrder>> GetLast5Orders(ClaimsIdentity claimsIdentity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lunchorder.Common.Interfaces
{
public interface IDatabaseRepository
{
Task<GetUserInfoResponse> GetUserInfo(string userId);
Task<GetUserInfoResponse> GetUserInfo(string userName);
Task<IEnumerable<Badge>> GetBadges();
Task AddMenu(Menu menu);
Task<Menu> GetEnabledMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
function updateUserOrders(userDocument) {
// we only keep track of the last 10 orders for a user
if (userDocument.Last5Orders && userDocument.Last5Orders.length >= 5) {
userDocument.shift();
userDocument.Last5Orders.shift();
}

// insert at beginning
Expand Down
8 changes: 1 addition & 7 deletions backend/WebApi/Lunchorder.Domain/Dtos/LastOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Lunchorder.Domain.Dtos
/// </summary>
public class LastOrder
{
private IEnumerable<LastOrderEntry> _lastOrderEntries;

public string Id { get; set; }

/// <summary>
Expand All @@ -25,11 +23,7 @@ public class LastOrder
/// <summary>
/// The items associated with the order
/// </summary>
public IEnumerable<LastOrderEntry> LastOrderEntries
{
get { return _lastOrderEntries ?? (_lastOrderEntries = new List<LastOrderEntry>()); }
set { _lastOrderEntries = value; }
}
public IEnumerable<LastOrderEntry> LastOrderEntries { get; set; }

/// <summary>
/// The total price of all entries of this order including rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MenuVendor
/// <summary>
/// The ultimate time limit that an order should be submitted to the vendor
/// </summary>
public TimeSpan SubmitOrderTime { get; set; }
public DateTime SubmitOrderTime { get; set; }

/// <summary>
/// Logo of the vendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ namespace Lunchorder.Domain.Exceptions
{
public class BusinessException : Exception
{
public BusinessException(string message) : base(message)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Lunchorder.Common;
Expand Down Expand Up @@ -655,7 +656,7 @@ public async Task AddBiteMeMenu()
Street = string.Empty,
StreetNumber = string.Empty
},
SubmitOrderTime = new TimeSpan(9, 30, 0).ToString()
SubmitOrderTime = new DateTime(0, 0, 0, 7, 30, 0).ToString(CultureInfo.InvariantCulture)
};

var categoryBroodjesId = "83af0051-c407-4936-a8f6-e1e292b992ed";
Expand Down Expand Up @@ -1477,8 +1478,7 @@ public async Task AddBiteMeMenu()
Enabled = true,
Id = "512e6e00-9d0c-499e-ac0d-0015e4fec42d",
Picture = null,
Name = "",
Description = "Pasta kip - kaassaus",
Name = "Pasta kip - kaassaus",
Price = 4.50M
},
new MenuEntry
Expand Down
1 change: 0 additions & 1 deletion frontend/app/app.admin-prepay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class AdminPrepayComponent implements OnInit {
this.isBusy = true;
this.userBalanceError = "";

debugger;
this.balanceService.putBalance(selectedUser.userId, balanceAmount).subscribe(
newBalance => {
this.toasterService.pop('success', 'Success', `Balance updated to ${newBalance}`);
Expand Down
1 change: 0 additions & 1 deletion frontend/app/app.badge-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export class BadgeRow implements OnInit {
badgeItem : Badge;

ngOnInit() {
console.log(`badge: ${this.badgeItem.name}`)
}
}
1 change: 0 additions & 1 deletion frontend/app/app.badges-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class BadgesList implements OnInit {
ngOnInit() {
this.badgeService.getBadges().subscribe(
badges => {
console.log(`badges received: ${badges}`);
this.badges = badges;
// todo map badges with current user badges
},
Expand Down
26 changes: 25 additions & 1 deletion frontend/app/app.balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BalanceService } from './services/balanceService';
<div class="row">
<div class="col-md-6 col-md-offset-3 text-center wrap_title ">
<h2>About you</h2>
<p class="lead" style="margin-top:0">Check your balance and other options.</p>
<p class="lead" style="margin-top:0">Check your balance and last 5 orders.</p>
<div class="row">
<div class="col-md-6">
<p><i class="fa fa-user" style="padding-right: 13px;padding-left: 7px;font-size: 24px;"></i>{{accountService.user.userName}}</p>
Expand All @@ -17,6 +17,30 @@ import { BalanceService } from './services/balanceService';
<p><i class="fa fa-balance-scale" style="padding-right: 10px;font-size: 24px;"></i>{{accountService.user.balance | currency:'EUR':true:'1.2-2'}}</p>
</div>
</div>
<div class="row">
<table class="table history table-striped">
<thead>
<tr>
<th>Date</th>
<th>Name</th>
<th>Total Price</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let lastOrder of accountService.user.last5Orders">
<td>{{lastOrder.orderTime | date: 'medium'}}</td>
<td>
<div *ngFor="let entry of lastOrder.lastOrderEntries">
<span>{{ entry.name }} ({{entry.price | currency:'EUR':true:'1.2-2' }})</span>
<span class="detail">{{ entry.appliedRules }}</span>
</div>
</td>
<td>{{ lastOrder.finalPrice | currency:'EUR':true:'1.2-2' }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>`})
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ export class AppComponent implements OnInit {
}

public login() {
debugger;

this.accountService.login();
}
}
2 changes: 1 addition & 1 deletion frontend/app/app.information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Menu } from './domain/dto/menu';
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="css/images/icon/watch.svg" alt="Generic placeholder image">
<h3>On Time</h3>
<p class="lead">Orders are sent to the venue @ {{menu?.vendor?.submitOrderTime}}. Late orders are your own responsibility and should be made by giving them a call. </p>
<p class="lead">Orders are sent to the venue @ {{menu?.vendor?.submitOrderTime | date: 'shortTime' }}. Late orders are your own responsibility and should be made by giving them a call. </p>
</div>
<div class="col-sm-4 wow fadeInDown text-center">
<img class="rotate" src="css/images/icon/map.svg" alt="Generic placeholder image">
Expand Down
1 change: 0 additions & 1 deletion frontend/app/app.menu-category-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ export class MenuCategoryRow implements OnInit {
menuEntries: MenuEntry[];

ngOnInit() {
debugger;
}
}
3 changes: 0 additions & 3 deletions frontend/app/app.menu-entry-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ export class MenuEntryRow implements OnInit {
isModalOpen: boolean;

ngOnInit() {
console.log(`-- menu entryyyy: ${this.menuEntry.name}`);
console.log(`-- menu rules: ${this.menuEntry.rules}`);
}

openModal() {
this.isModalOpen = true;
console.log("rules" + this.menuEntry.rules);
}

addOrder(event : any, value : any) {
Expand Down
20 changes: 16 additions & 4 deletions frontend/app/app.menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class MenuComponent implements OnInit {
}

removeOrder(menuOrder: MenuOrder) {
debugger;
var matchIndex: number = -1;
for (var i = 0; i < this.orderService.menuOrders.length; i++) {
if (menuOrder.id === this.orderService.menuOrders[i].id) {
Expand All @@ -116,20 +115,33 @@ export class MenuComponent implements OnInit {
openCheckout() {
this.isModalOpen = true;
}

closeModal() {
this.isModalOpen = false;
}

finalizeOrder() {
this.isBusy = true;

this.orderService.postMenuOrders().subscribe(menu => {
this.isBusy = true;
this.orderService.menuOrders = new Array<MenuOrder>();
this.toasterService.pop('success', 'Success', 'Order submitted');
console.log("current balance: " + this.accountService.user.balance);
console.log("total price: " + this.orderService.totalPrice())
this.accountService.user.balance -= this.orderService.totalPrice();
console.log("differnt balance: " + this.accountService.user.balance);
this.orderService.menuOrders = new Array<MenuOrder>();
this.closeModal();

this.accountService.getLast5Orders().subscribe(lastOrders => {
this.accountService.user.last5Orders = lastOrders;
});
},
error => {
this.error = <any>error;
this.toasterService.pop('error', 'Failure', 'Something went wrong :(');
this.toasterService.pop('error', 'Failure', error);
this.isBusy = false;
}, () => {
this.isBusy = false;
});
}
}
1 change: 1 addition & 0 deletions frontend/app/domain/dto/dtos.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare module app.domain.dto {
id: string;
userOrderHistoryId: string;
orderTime: Date;
lastOrderEntries: ILastOrderEntry[];
finalPrice: number;
}

Expand Down
Loading

0 comments on commit 4dd02e1

Please sign in to comment.