Skip to content

Commit

Permalink
Merge pull request #70 from agiledev-students-spring2024/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
ShiwenFang authored Apr 19, 2024
2 parents 42cdedc + 4690777 commit b38fa68
Show file tree
Hide file tree
Showing 39 changed files with 83 additions and 342 deletions.
18 changes: 2 additions & 16 deletions back-end/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ const User = mongoose.model("User", username_password);


const clothing_item = new mongoose.Schema({
// id: {
// type: Number,
// required: true,
// unique: true
// },

articleType: {
type: String,
required: true
Expand Down Expand Up @@ -110,17 +106,7 @@ const outfitSchema = new mongoose.Schema({
type: String,
required: false
},
items: [{
itemName: {
type: String,
required: true
},
itemType: {
type: String,
required: true
},
_id: false // Prevents Mongoose from creating an _id for each subdocument
}],
Clothes:[clothing_item],
user: {
type: String,
required: true
Expand Down
Binary file removed back-end/public/accessories/accessory_1.jpg
Binary file not shown.
Binary file removed back-end/public/accessories/accessory_2.jpg
Binary file not shown.
Binary file removed back-end/public/accessories/accessory_3.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed back-end/public/jackets/jacket_1.jpg
Binary file not shown.
Binary file removed back-end/public/jackets/jacket_2.jpg
Binary file not shown.
Binary file removed back-end/public/jackets/jacket_3.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed back-end/public/pants/brown_pants.webp
Binary file not shown.
Binary file removed back-end/public/pants/comfy.webp
Binary file not shown.
Binary file removed back-end/public/pants/extra_pants.jpg
Binary file not shown.
Binary file not shown.
Binary file removed back-end/public/shirts/casual_shirt.webp
Binary file not shown.
Binary file removed back-end/public/shirts/favorite_shirt.webp
Binary file not shown.
Binary file removed back-end/public/shirts/formal_shirt.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file removed back-end/public/shoes/shoes_1.avif
Binary file not shown.
Binary file removed back-end/public/shoes/shoes_2.webp
Binary file not shown.
Binary file removed back-end/public/shoes/shoes_3.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file removed back-end/public/skirts/skirt_1.webp
Binary file not shown.
Binary file removed back-end/public/skirts/skirt_2.webp
Binary file not shown.
Binary file removed back-end/public/skirts/skirt_3.webp
Binary file not shown.
330 changes: 29 additions & 301 deletions back-end/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,293 +8,11 @@ import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
import models from './db.js';
const {User, Clothes } = models;
const {User, Clothes,Outfit } = models;

import auth from './routes/protected-content-routes.js'; // Import your protected routes


let clothcount=18;

// call express's listen function to start listening to the port
const accounts = [
{
"username": "tester",
"password": "tester"
},
{
"username": "example",
"password": "login"
}
];

const shirts = [
{ id: 1,
name: 'Casual Shirt',
brand: 'Awesome Brand',
type: 'Casual',
color: 'Blue',
notes: 'Note 1',
img: '/public/shirts/casual_shirt.webp'
},
{ id: 2,
name: 'Formal Shirt',
brand: 'Formal Brand',
type: 'Formal',
color: 'White',
notes: 'Note 2',
img: '/public/shirts/formal_shirt.webp'
},
{ id: 18,
name: 'Favorite Shirt',
brand: 'Awesome Brand',
type: 'Casual',
color: 'Grey',
notes: 'Note 3',
img: '/public/shirts/favorite_shirt.webp'
}
]

const pants = [
{ id: 3,
name: 'Casual Pants',
brand: 'Awesome Brand',
type: 'Casual',
color:'Orange',
notes: 'Note 1',
img: '/public/pants/brown_pants.webp'
},
{ id: 4,
name: 'Least Favorite Pants',
brand: 'Fake Brand 3',
type: 'Casual',
color: 'Brown',
notes: 'Note 2',
img: '/public/pants/extra_pants.jpg'
},
{ id: 5,
name: 'Favorite Pants',
brand: 'Cool Brand',
type: 'Casual',
color: 'Grey',
notes: 'Note 3',
img: '/public/pants/comfy.webp'
}
]

const skirts = [
{ id: 6,
name: 'Best Dress',
brand: 'Awesome Brand',
type: 'Formal',
color: 'Emerald Green',
notes: 'Note 1',
img: '/public/skirts/skirt_1.webp'
},
{ id: 7,
name: 'Least Favorite Dress',
brand: 'Fake Brand 170',
type: 'Formal',
color: 'Blue',
notes: 'Note 2',
img: '/public/skirts/skirt_2.webp'
},
{ id: 8,
name: '2nd Favorite Dress',
brand: 'Cool Brand',
type: 'Formal',
color: 'Pink',
notes: 'Note 3',
img: '/public/skirts/skirt_3.webp'
}
]

const jackets = [
{ id: 9,
name: 'Ugly Jacket',
brand: 'Awful Brand',
type: 'Casual',
color: 'Green',
notes: 'Note 1',
img: '/public/jackets/jacket_1.jpg'
},
{
id: 10,
name: 'Coolest Jacket',
brand: 'Fake Brand 170',
type: 'Formal',
color: 'White',
notes: 'Note 2',
img: '/public/jackets/jacket_2.jpg'
},
{ id: 11,
name: 'Okay Jacket',
brand: 'Cool Brand',
type: 'Casual',
color: 'Blue',
notes: 'Note 3',
img: '/public/jackets/jacket_3.webp'
}
]

const shoes = [
{ id: 12,
name: 'Nice Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
notes: 'Note 1',
img: '/public/shoes/shoes_1.avif'
},
{ id: 13,
name: 'Decent Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
notes: 'Note 2',
img: '/public/shoes/shoes_2.webp'
},
{ id: 14,
name: 'Okay Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Grey',
notes: 'Note 3',
img: '/public/shoes/shoes_3.webp'
}
]

const accessories = [
{ id: 15,
name: 'Most Expensive',
brand: 'Cheap-O',
type: 'Formal',
color: 'Gold',
notes: 'Note 1',
img: '/public/accessories/accessory_1.jpg'
},
{ id: 16,
name: 'Best Accessory',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
notes: 'Note 2',
img: '/public/accessories/accessory_2.jpg'
},
{ id: 17,
name: 'Pretty Cool',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Silver',
notes: 'Note 3',
img: '/public/accessories/accessory_3.webp'
}
]

const outfits = [
{
outfitName: 'Business Casual Look',
notes: 'A comfortable yet professional look for everyday business.',
items: [
{ id:2,
name: 'Formal Shirt',
brand: 'Formal Brand',
type: 'Formal',
color: 'White',
img: '/public/shirts/formal_shirt.webp',
},
{ id:5,
name: 'Favorite Pants',
brand: 'Cool Brand',
type: 'Casual',
color: 'Grey',
img: '/public/pants/comfy.webp',
},
{ id: 13,
name: 'Decent Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
img: '/public/shoes/shoes_2.webp',
},
{ id: 16,
name: 'Best Accessory',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
img: '/public/accessories/accessory_2.jpg',
}
],
},
{
outfitName: 'Summer Vibes',
notes: 'Perfect for the beach or a sunny day in the park.',
items: [
{ id: 1,
name: 'Casual Shirt',
brand: 'Awesome Brand',
type: 'Casual',
color: 'Blue',
img: '/public/shirts/casual_shirt.webp',
},
{ id: 3,
name: 'Casual Pants',
brand: 'Awesome Brand',
type: 'Casual',
color: 'Orange',
img: '/public/pants/brown_pants.webp',
},
{ id:12,
name: 'Nice Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Black',
img: '/public/shoes/shoes_1.avif',
},
{ id: 17,
name: 'Pretty Cool',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Silver',
img: '/public/accessories/accessory_3.webp',
}
],
},
{
outfitName: 'Evening Elegance',
notes: 'Elegant attire for dinner parties or a night out.',
items: [
{ id: 8,
name: '2nd Favorite Dress',
brand: 'Cool Brand',
type: 'Formal',
color: 'Pink',
img: '/public/skirts/skirt_3.webp',
},
{ id:10,
name: 'Coolest Jacket',
brand: 'Fake Brand 170',
type: 'Formal',
color: 'White',
img: '/public/jackets/jacket_2.jpg',
},
{ id:14,
name: 'Okay Shoes',
brand: 'Definitely Awesome',
type: 'Casual',
color: 'Grey',
img: '/public/shoes/shoes_3.webp',
},
{ id:15,
name: 'Most Expensive',
brand: 'Cheap-O',
type: 'Formal',
color: 'Gold',
img: '/public/accessories/accessory_1.jpg',
}
],
},
];


server.post('/login', async (req,res) => {
const u = req.body.username;
Expand Down Expand Up @@ -360,14 +78,14 @@ server.get('/shirts', auth, async (req, res) => {
user: userId,
articleType: 'Shirts'
});

// Check if shirts array is not empty
if (shirts.length > 0) {
res.json(shirts);
} else {
// If the array is empty, it may mean no shirts were found for the user
res.status(404).json({ message: 'No shirts found for this user.' });
}
res.json(shirts)
// // Check if shirts array is not empty
// if (shirts.length > 0) {
// res.json(shirts);
// } else {
// // If the array is empty, it may mean no shirts were found for the user
// res.status(404).json({ message: 'No shirts found for this user.' });
// }

} catch (error) {
console.error('Server error when fetching shirts:', error);
Expand Down Expand Up @@ -714,17 +432,27 @@ server.post('/additem', auth, upload.single('picture'), async(req, res) => {


// POST route to save a new outfit
server.post('/generator', (req, res) => {
const { outfitName, items } = req.body;
if (!outfitName || !items || items.length === 0) {
return res.status(400).json({ message: 'Outfit name and items are required.' });
server.post('/generator', auth, async(req, res) => {
try {
const { outfitName, outfitNotes, items } = req.body;
const newOutfit = new Outfit({
outfitName:req.body.outfitName,
outfitNotes:req.body.outfitNotes,
Clothes:req.body.items,
user: req.user.id,
});

if (!outfitName || !items || items.length === 0) {
return res.status(400).json({ message: 'Outfit name and items are required.' });
}
await newOutfit.save();
res.status(201).json({ message: 'Outfit saved successfully' });

} catch ( error ) {
res.status(500).json({ message: 'Failed to add outfit', error: error });
}
outfits.push({
outfitName,
notes:'',
items
});
res.status(201).json({ message: 'Outfit saved successfully' });


});

server.post('/random', (req, res) => {
Expand Down
Loading

0 comments on commit b38fa68

Please sign in to comment.