-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5b06db
commit 4ec322e
Showing
7 changed files
with
120 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.dashboard { | ||
background-color: #333; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|