nhan0504 / CS326

0 stars 1 forks source link

Create WardrobeRepositoryService #13

Closed sophia-hubscher closed 3 weeks ago

sophia-hubscher commented 4 weeks ago

Created WardrobeRepositoryService based on Anisha's OutfitRepositoryService.

Example use: (in app.js)

import { WardrobeRepositoryService } from "./services/WardrobeRepositoryService.js";
import { OutfitRepositoryService } from "./services/OutfitRepositoryService.js";
import { WardrobeItem } from "./models/WardrobeItem.js";
import { OutfitEntry } from "./models/OutfitEntry.js";

const wardrobeService = new WardrobeRepositoryService();
const outfitService = new OutfitRepositoryService();

async function testServices() {
  try {
    await wardrobeService.initDB();
    console.log('Wardrobe database initialized successfully.');

    const testWardrobeItem = new WardrobeItem(
      'abcd',
      1,
      'https://example.com/image.jpg',
      'Blue T-shirt',
      20.00,
      'M',
      'T-shirt',
      'Casual',
      ['Summer', 'Spring'],
      'Brand A',
      false,
      0
    );

    const storeMessage = await wardrobeService.storeWardrobeItem(testWardrobeItem.toJSON());
    console.log(storeMessage);

    const items = await wardrobeService.loadWardrobeItemsFromDB();
    console.log('Wardrobe Items:', items);

    const clearMessage = await wardrobeService.clearWardrobeItems();
    console.log(clearMessage);

    await outfitService.initDB();
    console.log('Outfit database initialized successfully.');

    const testOutfit = new OutfitEntry(
      'outfit1',
      'user1',
      [items[0].item_id],
      'Casual outfit'
    );

    const storeOutfitMessage = await outfitService.storeOutfit(testOutfit.toJSON());
    console.log(storeOutfitMessage);

    const outfits = await outfitService.loadOutfitFromDB();
    console.log('Outfits:', outfits);

    const clearOutfitMessage = await outfitService.clearOutfit();
    console.log(clearOutfitMessage);

  } catch (error) {
    console.error('Error:', error);
  }
}

testServices();