Skip to content

Commit

Permalink
example item list is working
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasBeck777 committed Oct 23, 2022
1 parent c5b06db commit 4ec322e
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src4/AngularUi/src/app/checkout/checkout.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ <h2>Checkout</h2>
</li>
</ul>


<table>
<tbody>
<tr>
<th>Menge</th>
<th>Artikel</th>
<th>Preis</th>
<th>Total</th>
</tr>
<tr *ngFor="let item of items">
<td>{{item.amount}}</td>
<td>{{item.name}}</td>
<td>{{item.cost}}</td>
<td>{{item.total}}</td>
</tr>
</tbody>
</table>

<app-order-detail [order]="selectedOrder"></app-order-detail>

</div>
10 changes: 9 additions & 1 deletion src4/AngularUi/src/app/checkout/checkout.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Order } from '../order';
import { Item } from '../item';
import { OrderService } from '../order.service';
import { ItemService } from '../item.service';

@Component({
selector: 'app-checkout',
Expand All @@ -9,18 +11,24 @@ import { OrderService } from '../order.service';
})
export class CheckoutComponent implements OnInit {

constructor(private orderService: OrderService) { }
constructor(private orderService: OrderService, private itemService: ItemService) { }

orders: Order[] = [];
items: Item[] = [];
selectedOrder?: Order;

ngOnInit(): void {
this.getOrders();
this.getItems();
}

getOrders(): void {
this.orderService.getOrders().subscribe(orders => this.orders = orders);
}

getItems(): void {
this.itemService.getItems().subscribe(items => this.items = items);
}

onSelect(order: Order): void {
this.selectedOrder = order;
Expand Down
3 changes: 3 additions & 0 deletions src4/AngularUi/src/app/dashboard/dashboard.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dashboard {
background-color: #333;
}
16 changes: 16 additions & 0 deletions src4/AngularUi/src/app/item.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ItemService } from './item.service';

describe('ItemService', () => {
let service: ItemService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ItemService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions src4/AngularUi/src/app/item.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';
import { Item } from './item';
import { Observable, of } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
providedIn: 'root'
})
export class ItemService {

constructor(
private http: HttpClient) { }

private itemsUrl = 'http://localhost:5000/api/items';

getItems(): Observable<Item[]> {
return this.http.get<Item[]>(this.itemsUrl)
}

}
8 changes: 8 additions & 0 deletions src4/AngularUi/src/app/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Item {
id: number;
amount: number;
name: string;
cost: number;
discount: number;
total: number;
}
66 changes: 46 additions & 20 deletions src4/PythonServer/SaeuliServerStartup.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
# app.py
from flask import Flask, request, jsonify
from flask_cors import CORS
import json

app = Flask(__name__)
CORS(app)

countries = [
{"id": 1, "name": "Thailand", "capital": "Bangkok", "area": 513120},
{"id": 2, "name": "Australia", "capital": "Canberra", "area": 7617930},
{"id": 3, "name": "Egypt", "capital": "Cairo", "area": 1010408},
]

orders = [
{"id": 1, "cost": 1.50},
{"id": 2, "cost": 9.30}
]

def _find_next_id():
return max(country["id"] for country in countries) + 1
items = [
{"id":1, "amount": 1, "name": "Polenta Maisgriess", "cost":1.95, "discount": 0.95, "total": 0.95},
{"id":2, "amount": 1, "name": "P.G. Haferfloeckli", "cost":0.70, "total": 0.70},
{"id":3, "amount": 1, "name": "N.F. Eier 6 St.", "cost":4.95, "total": 4.95},
{"id":4, "amount": 1, "name": "P.G. Gouda", "cost":1.85, "total": 1.95}
]

checkouts = [
{"id" : 1, "toPay": 13.70, "available": 13.20 }
]

def _find_next_order_id():
return max(orders["id"] for order in orders) + 1

def _find_checkout_order_id():
return max(checkouts["id"] for order in orders) + 1

@app.get("/api/countries")
def get_countries():
return jsonify(countries)

@app.post("/api/countries")
def add_country():
if request.is_json:
country = request.get_json()
country["id"] = _find_next_id()
countries.append(country)
return country, 201
return {"error": "Request must be JSON"}, 415

# @app.post("/api/countries")
# def add_country():
# if request.is_json:
# country = request.get_json()
# country["id"] = _find_next_id()
# countries.append(country)
# return country, 201
# return {"error": "Request must be JSON"}, 415


@app.get("/api/orders")
def get_orders():
return jsonify(orders)
return jsonify(orders)


@app.get("/api/checkout")
def get_checkouts():
return jsonify(checkouts)



@app.get("/api/items")
def get_items():
return jsonify(items)

@app.post("/api/donate")
def do_checkout():
if request.is_json:
checkout = request.get_json()

return "OK", 200
return {"error": "Request must be JSON"}, 415

0 comments on commit 4ec322e

Please sign in to comment.