-
Notifications
You must be signed in to change notification settings - Fork 91
Liten leap project #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VariaSlu
wants to merge
12
commits into
Technigo:main
Choose a base branch
from
VariaSlu:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Liten leap project #133
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
16025f5
backend express db conneced
VariaSlu d0e909b
added User model, JWT middleware, and register/login routes
VariaSlu 0168cbc
set front and connected with back
VariaSlu caca83c
added iteems
VariaSlu e17ef63
fixed kid backend model import + frontend page adjustments
VariaSlu 5904f1e
added kid selector, prediction chart, and upcoming needsonn dashboard
VariaSlu a5d0ee3
add height field tokids model + form, use in dashboard predic
VariaSlu 061eba4
style: labels, focus, mobile form spacing; chart container height; me…
VariaSlu 2042b35
updated prediction
VariaSlu 89407cd
api:cors and health db status
VariaSlu f649e53
added redirectsfor netlify
VariaSlu 2b30e8d
title change
VariaSlu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ node_modules | |
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| backend/.env | ||
|
|
||
| build | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import jwt from "jsonwebtoken"; | ||
|
|
||
| export default function auth(req, res, next) { | ||
| const h = req.headers.authorization || ""; | ||
| const token = h.startsWith("Bearer ") ? h.slice(7) : null; | ||
| if (!token) return res.status(401).json({ error: "No token" }); | ||
| try { | ||
| req.user = jwt.verify(token, process.env.JWT_SECRET); // { id, iat, exp } | ||
| next(); | ||
| } catch { | ||
| res.status(401).json({ error: "Invalid token" }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import mongoose from "mongoose"; | ||
|
|
||
| const itemSchema = new mongoose.Schema( | ||
| { | ||
| userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true, index: true }, | ||
| childId: { type: mongoose.Schema.Types.ObjectId, ref: "Kid", required: true }, | ||
| type: { type: String, enum: ["jacket", "pants", "boots", "hat", "top", "gloves", "other"], default: "other" }, | ||
| size: { type: String, required: true }, | ||
| season: { type: String, enum: ["winter", "spring", "summer", "autumn", "all"], default: "all" }, | ||
| status: { type: String, enum: ["current", "needed", "stored", "to-sell"], default: "current" }, | ||
| notes: String | ||
| }, | ||
| { timestamps: true } | ||
| ); | ||
|
|
||
| export default mongoose.model("Item", itemSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import mongoose from "mongoose"; | ||
|
|
||
| const kidSchema = new mongoose.Schema({ | ||
| name: { type: String, required: true }, | ||
| birthdate: { type: Date, required: true }, | ||
|
|
||
| // optional: male/female/other | ||
| sex: { type: String, enum: ["boy", "girl", "other"], default: "other" }, | ||
|
|
||
| // optional: current height in cm | ||
| height: { type: Number, min: 40, max: 200 }, | ||
|
|
||
| owner: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true }, | ||
| }, { timestamps: true }); | ||
|
|
||
| export default mongoose.model("Kid", kidSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import mongoose from "mongoose"; | ||
|
|
||
| const userSchema = new mongoose.Schema( | ||
| { | ||
| email: { type: String, required: true, unique: true, trim: true }, | ||
| passwordHash: { type: String, required: true } | ||
| }, | ||
| { timestamps: true } | ||
| ); | ||
|
|
||
| export default mongoose.model("User", userSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import express from "express"; | ||
| import bcrypt from "bcrypt"; | ||
| import jwt from "jsonwebtoken"; | ||
| import mongoose from "mongoose"; | ||
| import User from "../models/User.js"; | ||
|
|
||
| const router = express.Router(); | ||
| const sign = (id) => jwt.sign({ id }, process.env.JWT_SECRET, { expiresIn: "7d" }); | ||
|
|
||
| // POST /auth/register | ||
| router.post("/register", async (req, res) => { | ||
| try { | ||
| const { email, password } = req.body; | ||
|
|
||
| // basic validation | ||
| if (!email || !password) return res.status(400).json({ error: "Email and password required" }); | ||
| if (password.length < 6) return res.status(400).json({ error: "Password must be ≥ 6 chars" }); | ||
|
|
||
| // unique email | ||
| const exists = await User.findOne({ email: email.toLowerCase().trim() }); | ||
| if (exists) return res.status(409).json({ error: "Email already registered" }); | ||
|
|
||
| // hash & save | ||
| const passwordHash = await bcrypt.hash(password, 10); | ||
| const user = await User.create({ email: email.toLowerCase().trim(), passwordHash }); | ||
|
|
||
| // return a token immediately (so the FE can log in) | ||
| return res.status(201).json({ token: sign(user._id) }); | ||
| } catch (e) { | ||
| // handle duplicate key race condition | ||
| if (e.code === 11000) return res.status(409).json({ error: "Email already registered" }); | ||
| console.error(e); | ||
| return res.status(500).json({ error: "Register failed" }); | ||
| } | ||
| }); | ||
|
|
||
| // POST /auth/login | ||
| router.post("/login", async (req, res) => { | ||
| try { | ||
| const { email, password } = req.body; | ||
| if (!email || !password) return res.status(400).json({ error: "Email and password required" }); | ||
|
|
||
| const user = await User.findOne({ email: email.toLowerCase().trim() }); | ||
| if (!user) return res.status(401).json({ error: "Invalid credentials" }); | ||
|
|
||
| const ok = await bcrypt.compare(password, user.passwordHash); | ||
| if (!ok) return res.status(401).json({ error: "Invalid credentials" }); | ||
|
|
||
| return res.json({ token: sign(user._id) }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| return res.status(500).json({ error: "Login failed" }); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import express from "express"; | ||
| import Item from "../models/Item.js"; | ||
| import auth from "../middlewares/auth.js"; | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| // list items for user | ||
| router.get("/", auth, async (req, res) => { | ||
| const items = await Item.find({ userId: req.user.id }).lean(); | ||
| res.json(items); | ||
| }); | ||
|
|
||
| // create | ||
| router.post("/", auth, async (req, res) => { | ||
| const { childId, type, size, season, status, notes } = req.body; | ||
| const item = await Item.create({ userId: req.user.id, childId, type, size, season, status, notes }); | ||
| res.status(201).json(item); | ||
| }); | ||
|
|
||
| // update | ||
| router.patch("/:id", auth, async (req, res) => { | ||
| const item = await Item.findOneAndUpdate( | ||
| { _id: req.params.id, userId: req.user.id }, | ||
| req.body, | ||
| { new: true } | ||
| ); | ||
| if (!item) return res.status(404).json({ error: "Not found" }); | ||
| res.json(item); | ||
| }); | ||
|
|
||
| // delete | ||
| router.delete("/:id", auth, async (req, res) => { | ||
| const ok = await Item.deleteOne({ _id: req.params.id, userId: req.user.id }); | ||
| if (!ok.deletedCount) return res.status(404).json({ error: "Not found" }); | ||
| res.json({ ok: true }); | ||
| }); | ||
|
|
||
| export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import express from "express"; | ||
| import auth from "../middlewares/auth.js"; | ||
| import Kid from "../models/Kid.js"; | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| router.get("/", auth, async (req, res) => { | ||
| try { | ||
| const kids = await Kid.find({ owner: req.user.id }).lean(); | ||
| res.json(kids); | ||
| } catch (e) { | ||
| console.error(e); | ||
| res.status(500).json({ error: "Failed to fetch kids" }); | ||
| } | ||
| }); | ||
|
|
||
| router.post("/", auth, async (req, res) => { | ||
| try { | ||
| const { name, birthdate } = req.body; | ||
| const kid = await Kid.create({ name, birthdate, owner: req.user.id }); | ||
| res.status(201).json(kid); | ||
| } catch (e) { | ||
| console.error(e); | ||
| res.status(500).json({ error: "Failed to create kid" }); | ||
| } | ||
| }); | ||
|
|
||
| export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,62 @@ | ||
| import dotenv from "dotenv"; | ||
| import express from "express"; | ||
| import cors from "cors"; | ||
| import mongoose from "mongoose"; | ||
| import morgan from "morgan"; | ||
| import authRouter from "./routes/auth.js"; | ||
| import "./models/User.js"; | ||
| import kidsRouter from "./routes/kids.js"; | ||
| import itemsRouter from "./routes/items.js"; | ||
| import auth from "./middlewares/auth.js"; | ||
|
|
||
| const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/final-project"; | ||
| mongoose.connect(mongoUrl); | ||
| mongoose.Promise = Promise; | ||
|
|
||
| const port = process.env.PORT || 8080; | ||
|
|
||
| dotenv.config(); // 1) Load backend/.env | ||
|
|
||
| const app = express(); | ||
| const PORT = process.env.PORT || 8081; | ||
| const MONGO_URL = process.env.MONGO_URL || "mongodb://localhost/final-project"; | ||
| //local dev site and hosted frontend | ||
| const allowed = [process.env.FRONTEND_URL, "http://localhost:5173"].filter(Boolean); | ||
| app.use(cors({ origin: allowed })); | ||
|
|
||
| app.use(cors()); | ||
| // 2) Middleware | ||
| //app.use(cors()); | ||
| app.use(express.json()); | ||
| app.use(morgan("dev")); // handy request logs during dev | ||
|
|
||
| app.use("/auth", authRouter); | ||
|
|
||
| app.use("/kids", kidsRouter); | ||
|
|
||
| app.use("/items", itemsRouter); | ||
|
|
||
|
|
||
| app.get("/", (req, res) => { | ||
|
|
||
| // 3) Mongo connect (with clear logs) | ||
| mongoose | ||
| .connect(MONGO_URL) | ||
| .then(() => console.log("✅ MongoDB connected")) | ||
| .catch((err) => console.error("❌ MongoDB connection error:", err.message)); | ||
|
|
||
| // Helper: human-readable DB status | ||
| const dbStatus = () => { | ||
| const states = ["disconnected", "connected", "connecting", "disconnecting"]; | ||
| return states[mongoose.connection.readyState] || "unknown"; | ||
| }; | ||
|
|
||
| // 4) Routes | ||
| app.get("/", (_req, res) => { | ||
| res.send("Hello Technigo!"); | ||
| }); | ||
|
|
||
| // Start the server | ||
| app.listen(port, () => { | ||
| console.log(`Server running on http://localhost:${port}`); | ||
| app.get("/health", (_req, res) => { | ||
| res.json({ ok: true, db: dbStatus() }); | ||
| }); | ||
|
|
||
| app.get("/me", auth, (req, res) => res.json({ userId: req.user.id })); | ||
|
|
||
| // 5) Start the server | ||
| app.listen(PORT, () => { | ||
| console.log(`🚀 Server running on http://localhost:${PORT}`); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Technigo React Vite Boiler Plate</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.jsx"></script> | ||
| </body> | ||
| </html> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <meta name="description" | ||
| content="LitenLeap keeps you ahead of kids' clothing needs with size prediction and seasonal planning." /> | ||
| <title>Technigo React Vite Boiler Plate</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.jsx"></script> | ||
| </body> | ||
|
|
||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /* /index.html 200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,34 @@ | ||
| export const App = () => { | ||
| import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom"; | ||
| import { useAuth } from "./store/auth"; | ||
| import Login from "./pages/Login"; | ||
| import Register from "./pages/Register"; | ||
| import Dashboard from "./pages/Dashboard"; | ||
| import Kids from "./pages/Kids"; | ||
| import Items from "./pages/Items"; | ||
| import Nav from "./components/Nav"; | ||
|
|
||
|
|
||
| const Protected = ({ children }) => { | ||
| const token = useAuth((s) => s.token); | ||
| return token ? children : <Navigate to="/login" replace />; | ||
| }; | ||
|
|
||
| const App = () => { | ||
| return ( | ||
| <> | ||
| <h1>Welcome to Final Project!</h1> | ||
| </> | ||
| <BrowserRouter> | ||
| <Nav /> {/* 👈 always visible */} | ||
| <Routes> | ||
| <Route path="/login" element={<Login />} /> | ||
| <Route path="/register" element={<Register />} /> | ||
| <Route path="/" element={<Protected><Dashboard /></Protected>} /> | ||
| <Route path="*" element={<Navigate to="/" />} /> | ||
| <Route path="/kids" element={<Protected><Kids /></Protected>} /> | ||
| <Route path="/items" element={<Protected><Items /></Protected>} /> | ||
| <Route path="*" element={<Navigate to="/" />} /> | ||
|
|
||
| </Routes> | ||
| </BrowserRouter> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done :)