Skip to content

Commit

Permalink
8 changed files from Github Desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
someone624 committed Nov 22, 2024
1 parent 871c905 commit c47501b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/models/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# db.py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from .models import Base
Expand Down
Empty file added src/views/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions src/views/error_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import render_template

def render_error_page(error_code, error_message):
# Render a generic error page
return render_template('error_template.html', error_code=error_code, error_message=error_message), error_code
18 changes: 18 additions & 0 deletions src/views/product_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import jsonify, render_template
from src.models.product_model import Product

def get_product(product_id):
# Fetch product data from the model
product = Product.query.get(product_id)
if product:
return jsonify({"id": product.id, "name": product.name, "price": product.price}), 200
else:
return jsonify({"error": "Product not found"}), 404

def render_product_template(product_id):
# Render a product details page in HTML
product = Product.query.get(product_id)
if product:
return render_template('product_template.html', product=product)
else:
return "Product not found", 404
10 changes: 10 additions & 0 deletions src/views/static/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
document.addEventListener("DOMContentLoaded", function() {
// Example function to display a welcome message on page load
const userName = document.querySelector("h1");
if (userName) {
userName.textContent = "Welcome, user!"; // Modify if needed
}

// Add any other JS functionalities as needed
console.log("App Loaded");
});
30 changes: 30 additions & 0 deletions src/views/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

header {
background-color: #333;
color: white;
padding: 10px 20px;
text-align: center;
}

section {
margin: 20px;
padding: 20px;
background-color: white;
border-radius: 8px;
}

footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px 0;
position: fixed;
width: 100%;
bottom: 0;
}
22 changes: 22 additions & 0 deletions src/views/templates/user_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<header>
<h1>Welcome, {{ user.name }}</h1>
</header>
<section>
<h2>User Information</h2>
<p><strong>ID:</strong> {{ user.id }}</p>
<p><strong>Email:</strong> {{ user.email }}</p>
</section>
<footer>
<p>&copy; 2024 Your Company</p>
</footer>
</body>
</html>
18 changes: 18 additions & 0 deletions src/views/user_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import jsonify, render_template
from src.models.user_model import User

def get_user(user_id):
# Fetch user data from the model
user = User.query.get(user_id)
if user:
return jsonify({"id": user.id, "name": user.name, "email": user.email}), 200
else:
return jsonify({"error": "User not found"}), 404

def render_user_template(user_id):
# Render a user profile page in HTML
user = User.query.get(user_id)
if user:
return render_template('user_template.html', user=user)
else:
return "User not found", 404

0 comments on commit c47501b

Please sign in to comment.