Compare commits

...

2 Commits

Author SHA1 Message Date
Felix Jan Michael Mucha d1f0ff3375 updated readme 2025-01-27 14:31:41 +01:00
michael 569589a4f5 add Setup Test 2025-01-26 13:24:46 +01:00
6 changed files with 67 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
/env

BIN
HelloWorld.db 100644

Binary file not shown.

View File

@ -1,4 +1,13 @@
# IWS_clean_architecture # IWS_clean_architecture
** Master MDS HSMA ** ** Master MDS HSMA **
Clean Architecture - Architekturstil am praktischen Beispiel z.B. in Python. Clean Architecture - Architekturstil am praktischen Beispiel z.B. in Python.
## Setup Test
1. falls python noch nicht installiert, installieren
2. navigiere zum repo ```cd IWS_WS24_clean_architecture```
3. ```pip install -r requirements.txt```
4. ```python main.py``` ausführen und Terminal offen lassen
5. index.html mit Browser öffnen
6. Wenn alles geklappt hat sollte die index.html Hello World anzeigen
7. mit ```STRG + C``` kann das script im Terminal gestoppt werden

26
index.html 100644
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup Test</title>
</head>
<body>
<h1 id="greetings">Not Working</h1>
<script>
// Fetch Hello World from the FastAPI endpoint
fetch('http://127.0.0.1:8000/greetings')
.then(response => response.json())
.then(data => {
const greetingsContainer = document.getElementById('greetings');
greetingsContainer.innerHTML = '';
data.greetings.forEach(greeting => {
const div = document.createElement('div');
div.textContent = `${greeting[1]}`;
greetingsContainer.appendChild(div);
});
});
</script>
</body>
</html>

26
main.py 100644
View File

@ -0,0 +1,26 @@
import sqlite3
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
app = FastAPI()
# Allow CORS for all origins (for simplicity)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/greetings")
async def get_greetings():
connection = sqlite3.connect("HelloWorld.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM greetings")
rows = cursor.fetchall()
return {"greetings": rows}
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)

2
requirements.txt 100644
View File

@ -0,0 +1,2 @@
fastapi
uvicorn