implement frameworks solution

loesung_frameworks
michael 2025-02-03 01:42:16 +01:00
parent 3193960125
commit a34db9ad2c
4 changed files with 29 additions and 6 deletions

View File

@ -31,8 +31,12 @@ def delete_table(conn, table_name):
def main():
database = "framework_driver/db/shop.db"
#TODO: Create User Table
sql_user_table = """
sql_user_table = """CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL
)
"""
sql_product_table = """CREATE TABLE IF NOT EXISTS products (

View File

@ -2,8 +2,11 @@
const Controller = {
async createUser(name, email, password){
//TODO: use model to send request to backend, then call View to render response
alert('User Creation functionality not implemented.');
const userCreateResponse = await Model.createUser(name, email, password);
if(userCreateResponse.status=="success"){
const user = userCreateResponse.data;
View.renderUser(user);
}
},
async showProducts() {

View File

@ -1,6 +1,16 @@
// Model: Handles data fetching
const Model = {
//TODO: Add function to send CreateUserRequest to Backend
async createUser(name, email, password) {
const response = await fetch(`http://127.0.0.1:8000/create_user`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ user_name: name, user_email: email, user_password: password }),
});
return response.json();
},
async fetchProducts() {
const response = await fetch('http://127.0.0.1:8000/view_products');

View File

@ -1,6 +1,12 @@
// View: Handles rendering
const View = {
//TODO: Add function to render UserCreateResponse
renderUser(user) {
const main = document.getElementById('main');
main.innerHTML = `
<h1>${user.name}</h1>
<p>email: ${user.email}</p>
`;
},
renderProducts(products) {
const main = document.getElementById('main');