Skip to content

Commit

Permalink
Merge pull request #131 from COS301-SE-2023/bugfixing
Browse files Browse the repository at this point in the history
🐛 price display and saving fix
  • Loading branch information
SkulderLock authored Sep 26, 2023
2 parents 07dd422 + 653b1c0 commit aaf62a5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ public class FoodModel {

private String unit;

public FoodModel(String name, double quantity, String unit, UUID id) {
private double price;

public FoodModel(String name, double quantity, String unit, double price, UUID id) {
this.id = id;
this.name = name;
this.quantity = quantity;
this.unit = unit;
this.price = price;
}

public FoodModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PantryControllerTest {

@Test
public void addToPantrySuccessTest() throws Exception {
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", null);
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", 5.99, null);

// When addToPantry method is called with any FoodModel and any String, it
// returns foodModel
Expand All @@ -64,7 +64,7 @@ public void addToPantrySuccessTest() throws Exception {

@Test
public void addToPantryBadRequestTest() throws Exception {
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", null);
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", 5.99, null);

// When addToPantry method is called with any FoodModel and any String, it
// returns foodModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ShoppingListControllerTest {

@Test
public void addToShoppingListSuccessTest() throws Exception {
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", null);
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", 5.99, null);

// When addToShoppingList method is called with any FoodModel and any String, it
// returns foodModel
Expand All @@ -65,7 +65,7 @@ public void addToShoppingListSuccessTest() throws Exception {

@Test
public void addToShoppingListBadRequestTest() throws Exception {
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", null);
FoodModel foodModel = new FoodModel("testFood", 2, "testUnit", 5.99, null);

// When addToShoppingList method is called with any FoodModel and any String, it
// returns foodModel
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/pages/pantry/pantry.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@
</ion-item>
</ion-col>
</ion-row>
<ion-row>
<ion-item
*ngIf="newItem.price !== -1 && newItem.price !== undefined"
>
<ion-label class="price">Price: R{{newItem.price}}</ion-label>
</ion-item>
</ion-row>
</ion-grid>
</ion-content>
</ng-template>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/pages/pantry/pantry.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ ion-item.fixed-price {
color: #656565;
font-size: 20px;
}

ion-label.price {
font-weight: bold;
font-family: "Roboto", sans-serif;
color: #656565;
font-size: 20px;
}
7 changes: 3 additions & 4 deletions frontend/src/app/pages/pantry/pantry.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ export class PantryPage implements OnInit, ViewWillEnter {
private alertController: AlertController
) {}


async ngOnInit() {
BarcodeScanner.isSupported().then((result) => {
this.isBarcodeSupported = result.supported;

Check warning on line 75 in frontend/src/app/pages/pantry/pantry.page.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/pages/pantry/pantry.page.ts#L75

Added line #L75 was not covered by tests
});
}


async ionViewWillEnter() {
if (!this.loginService.isPantryRefreshed()) {
this.fetchItems();
Expand Down Expand Up @@ -315,6 +313,7 @@ export class PantryPage implements OnInit, ViewWillEnter {
this.totalShoppingPrice += item.price;
}
});
this.totalShoppingPrice = Math.round(this.totalShoppingPrice * 100) / 100;
}

closeSlidingItems() {
Expand Down Expand Up @@ -489,7 +488,7 @@ export class PantryPage implements OnInit, ViewWillEnter {
const granted = await this.requestPermissions();

Check warning on line 488 in frontend/src/app/pages/pantry/pantry.page.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/pages/pantry/pantry.page.ts#L488

Added line #L488 was not covered by tests
if (!granted) {
this.errorHandlerService.presentErrorToast(

Check warning on line 490 in frontend/src/app/pages/pantry/pantry.page.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/pages/pantry/pantry.page.ts#L490

Added line #L490 was not covered by tests
'Please grant camera permissions to use this feature',
'No camera permissions',
'Camera permissions not granted'
);
return;

Check warning on line 494 in frontend/src/app/pages/pantry/pantry.page.ts

View check run for this annotation

Codecov / codecov/patch

frontend/src/app/pages/pantry/pantry.page.ts#L494

Added line #L494 was not covered by tests
Expand All @@ -508,7 +507,7 @@ export class PantryPage implements OnInit, ViewWillEnter {
// let result = {
// barcodes: [
// {
// displayValue: '13761238123', // for testing
// displayValue: '6003678902458', // for testing
// },
// ],
// };
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/services/pantry-api/pantry-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PantryApiService {
name: item.name,
quantity: item.quantity,
unit: item.unit,
price: item.price,
},
{ observe: 'response' }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ShoppingListApiService {
name: item.name,
quantity: item.quantity,
unit: item.unit,
price: item.price,
},
{ observe: 'response' }
);
Expand Down

0 comments on commit aaf62a5

Please sign in to comment.