implement frameworks solution
parent
3193960125
commit
a34db9ad2c
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue