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