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(): def main():
database = "framework_driver/db/shop.db" database = "framework_driver/db/shop.db"
#TODO: Create User Table sql_user_table = """CREATE TABLE IF NOT EXISTS users (
sql_user_table = """ 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 ( sql_product_table = """CREATE TABLE IF NOT EXISTS products (

View File

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

View File

@ -1,6 +1,16 @@
// Model: Handles data fetching // Model: Handles data fetching
const Model = { 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() { async fetchProducts() {
const response = await fetch('http://127.0.0.1:8000/view_products'); const response = await fetch('http://127.0.0.1:8000/view_products');

View File

@ -1,6 +1,12 @@
// View: Handles rendering // View: Handles rendering
const View = { 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) { renderProducts(products) {
const main = document.getElementById('main'); const main = document.getElementById('main');