diff --git a/src/app/mall-details/mall-details.page.ts b/src/app/mall-details/mall-details.page.ts index 63b9f65..7af7767 100644 --- a/src/app/mall-details/mall-details.page.ts +++ b/src/app/mall-details/mall-details.page.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { MallService } from '../services/mall.service'; -import Mall from '../models/mall'; +import { IMall } from '../models/mall'; import { Location } from '@angular/common'; @Component({ @@ -10,7 +10,7 @@ import { Location } from '@angular/common'; styleUrls: ['./mall-details.page.scss'], }) export class MallDetailsPage implements OnInit { - mall_details: Mall; + mall_details: IMall; selected_tab: string = 'food'; show_top_bar: boolean = false; show_sort_popup: boolean = false; @@ -26,7 +26,7 @@ export class MallDetailsPage implements OnInit { ngOnInit() { let mall_id = this.route.snapshot.paramMap.get('mall_id'); - this.mallService.getMallByID(mall_id).then((data: Mall) => { + this.mallService.getMallByID(mall_id).then((data: IMall) => { this.mall_details = data; }); } @@ -34,7 +34,7 @@ export class MallDetailsPage implements OnInit { refresh() { let mall_id = this.route.snapshot.paramMap.get('mall_id'); - this.mallService.getMallByID(mall_id).then((data: Mall) => { + this.mallService.getMallByID(mall_id).then((data: IMall) => { this.mall_details = data; }); } @@ -43,7 +43,7 @@ export class MallDetailsPage implements OnInit { this.location.back(); } - toggleBookmark(mall_details: Mall) { + toggleBookmark(mall_details: IMall) { mall_details.is_bookmarked = !mall_details.is_bookmarked; } diff --git a/src/app/malls/malls.page.ts b/src/app/malls/malls.page.ts index cbcccb5..fdfa646 100644 --- a/src/app/malls/malls.page.ts +++ b/src/app/malls/malls.page.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { MallService } from '../services/mall.service'; -import Mall from '../models/mall'; +import { IMall } from '../models/mall'; import { Router } from '@angular/router'; @Component({ @@ -10,7 +10,7 @@ import { Router } from '@angular/router'; }) export class MallsPage implements OnInit { selected_tab: string = 'you'; - malls: Array; + malls: Array; show_sort_popup: boolean = false; selected_sort: string = null; @@ -23,12 +23,12 @@ export class MallsPage implements OnInit { } ionViewDidEnter() { - this.mallService.getAllMalls().then((data: Array) => { + this.mallService.getAllMalls().then((data: Array) => { this.malls = data; }); } - showMallDetails(mall: Mall) { + showMallDetails(mall: IMall) { this.router.navigate(['/mall-details', { mall_id: mall.id }]); } diff --git a/src/app/mocks/malls.ts b/src/app/mocks/malls.ts index eb47d5a..07824fc 100644 --- a/src/app/mocks/malls.ts +++ b/src/app/mocks/malls.ts @@ -2,7 +2,7 @@ import Offer from '../models/offer'; import Mall from '../models/mall'; import { OUTLETS } from './outlets'; -export const MALLS = [new Mall({ +export const MALLS: Mall[] = [new Mall({ id: '0001', name: 'Gopalan Arcade Mall', address: 'Mysore Road, Bangalore', @@ -10,7 +10,7 @@ export const MALLS = [new Mall({ is_archived: false, image_url: 'https://www.gopalanmall.com/images/mall-arcade-01.jpg', description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - outlets: OUTLETS, + outlets: OUTLETS.map((outlet) => outlet.id), offers: [], rating: 4.1, distance: 2, diff --git a/src/app/mocks/outlets.ts b/src/app/mocks/outlets.ts index ca37760..53a50fb 100644 --- a/src/app/mocks/outlets.ts +++ b/src/app/mocks/outlets.ts @@ -1,15 +1,15 @@ -import Outlet, { OutletType } from '../models/outlet'; +import Outlet, { IOutlet, OutletType } from '../models/outlet'; import { MENU_ITEMS_1, MENU_ITEMS_2 } from './menu-items'; import { OFFERS } from './offers'; -export const OUTLETS = [new Outlet({ +export const OUTLETS: Outlet[] = [new Outlet({ id: '0001', image_url: 'https://images.markets.businessinsider.com/image/5a74835585cdd489228b47be-900/shutterstock643079686.jpg', name: 'McDonalds', description: 'Veg / Non-Veg Food Restaurant', tags: ['dinner', 'spicy', 'breakfast', 'pork'], - menu_items: MENU_ITEMS_1, - offers: OFFERS, + menu_items: MENU_ITEMS_1.map((menu_item) => menu_item.id), + offers: OFFERS.map((offer) => offer.id), outlet_type: OutletType.FOOD, is_bookmarked: false, rating: 3.5, @@ -30,7 +30,7 @@ export const OUTLETS = [new Outlet({ name: 'Cafe Coffee Day', description: 'Veg / Non-Veg Cafe', tags: ['hot', 'cold', 'pizza', 'beverage'], - menu_items: MENU_ITEMS_2, + menu_items: MENU_ITEMS_2.map((menu_item) => menu_item.id), offers: [], outlet_type: OutletType.FOOD, is_bookmarked: false, diff --git a/src/app/models/cart-item.ts b/src/app/models/cart-item.ts index c1abc57..a6647b8 100644 --- a/src/app/models/cart-item.ts +++ b/src/app/models/cart-item.ts @@ -1,5 +1,7 @@ +import MenuItem from './menu-item'; + class CartItem { - menu_item_id: string; + menu_item: string; quantity: number; pickup_time: Date; outlet_id: string; @@ -8,8 +10,8 @@ class CartItem { total_price: number; constructor(initializationObject: any) { - if (!initializationObject.hasOwnProperty('menu_item_id')) { - throw new Error('Missing Menu item ID'); + if (!initializationObject.hasOwnProperty('menu_item')) { + throw new Error('Missing Menu item'); } if (!initializationObject.hasOwnProperty('quantity')) { @@ -31,7 +33,7 @@ class CartItem { if (!initializationObject.hasOwnProperty('is_parcel')) { throw new Error('Missing Parcel Flag'); } - this.menu_item_id = initializationObject.menu_item_id; + this.menu_item = initializationObject.menu_item; this.quantity = initializationObject.quantity; this.pickup_time = initializationObject.pickup_time; this.outlet_id = initializationObject.outlet_id; @@ -41,4 +43,15 @@ class CartItem { } } +export interface ICartItem { + menu_item: MenuItem; + quantity: number; + pickup_time: Date; + outlet_id: string; + mall_id: string; + is_parcel: boolean; + total_price: number; +} + + export default CartItem; diff --git a/src/app/models/mall.ts b/src/app/models/mall.ts index df9bf66..50325df 100644 --- a/src/app/models/mall.ts +++ b/src/app/models/mall.ts @@ -1,6 +1,6 @@ import Offer from '../models/offer'; import { CoOrdinates } from '../shared/common-types'; -import Outlet from '../models/outlet'; +import { IOutlet } from '../models/outlet'; class Mall { id: string; @@ -9,8 +9,8 @@ class Mall { is_archived: boolean; image_url?: string; description: string; - offers: Array; - outlets: Array; + offers: Array; + outlets: Array; rating: number; distance: number; location: CoOrdinates; @@ -70,4 +70,19 @@ class Mall { } } +export interface IMall { + id: string; + name: string; + is_bookmarked: boolean; + is_archived: boolean; + image_url?: string; + description: string; + offers: Array; + outlets: Array; + rating: number; + distance: number; + location: CoOrdinates; + address: string; +} + export default Mall; diff --git a/src/app/models/outlet.ts b/src/app/models/outlet.ts index 43675f4..75e7cae 100644 --- a/src/app/models/outlet.ts +++ b/src/app/models/outlet.ts @@ -11,9 +11,9 @@ class Outlet { image_url?: string; name: string; description: string; - offers: Array; + offers: Array; tags: Array; - menu_items: Array; + menu_items: Array; outlet_type: OutletType; is_bookmarked: boolean; rating: number; @@ -71,4 +71,17 @@ class Outlet { } } +export interface IOutlet { + id: string; + image_url?: string; + name: string; + description: string; + offers: Array; + tags: Array; + menu_items: Array; + outlet_type: OutletType; + is_bookmarked: boolean; + rating: number; +}; + export default Outlet; diff --git a/src/app/outlet-details/outlet-details.page.ts b/src/app/outlet-details/outlet-details.page.ts index 387a29b..769e9b3 100644 --- a/src/app/outlet-details/outlet-details.page.ts +++ b/src/app/outlet-details/outlet-details.page.ts @@ -2,9 +2,9 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; import { MallService } from '../services/mall.service'; -import Mall from '../models/mall'; +import { IMall } from '../models/mall'; import CartItem from '../models/cart-item'; -import Outlet from '../models/outlet'; +import { IOutlet } from '../models/outlet'; import MenuItem from '../models/menu-item'; @Component({ @@ -13,9 +13,9 @@ import MenuItem from '../models/menu-item'; styleUrls: ['./outlet-details.page.scss'], }) export class OutletDetailsPage implements OnInit { - mall_details: Mall; - outlet_details: Outlet; - temp_outlet_details: Outlet; + mall_details: IMall; + outlet_details: IOutlet; + temp_outlet_details: IOutlet; show_top_bar: boolean = false; show_only_veg: boolean = false; selected_tag: string = null; @@ -34,7 +34,7 @@ export class OutletDetailsPage implements OnInit { let mall_id = this.route.snapshot.paramMap.get('mall_id'); let outlet_id = this.route.snapshot.paramMap.get('outlet_id'); - this.mallService.getMallByID(mall_id).then((data: Mall) => { + this.mallService.getMallByID(mall_id).then((data: IMall) => { this.mall_details = data; this.outlet_details = this.mall_details.outlets.find((outlet) => outlet.id === outlet_id); this.temp_outlet_details = JSON.parse(JSON.stringify(this.outlet_details)); diff --git a/src/app/services/mall.service.ts b/src/app/services/mall.service.ts index 92e8400..5f78cd1 100644 --- a/src/app/services/mall.service.ts +++ b/src/app/services/mall.service.ts @@ -1,13 +1,13 @@ import { Injectable } from '@angular/core'; import { MALLS } from '../mocks/malls'; import CartItem from '../models/cart-item'; -import Mall from '../models/mall'; +import Mall, { IMall } from '../models/mall'; @Injectable({ providedIn: 'root' }) export class MallService { - malls: Array; + malls: Array; cart: Array = []; constructor() { diff --git a/src/app/services/menu-item.service.ts b/src/app/services/menu-item.service.ts index c92dcef..4b2dd4f 100644 --- a/src/app/services/menu-item.service.ts +++ b/src/app/services/menu-item.service.ts @@ -1,9 +1,10 @@ import { Injectable } from '@angular/core'; +import { OUTLETS } from '../mocks/outlets'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class MenuItemService { - constructor() { } + constructor() { } } diff --git a/src/app/services/offer.service.ts b/src/app/services/offer.service.ts index f7fe516..90848f1 100644 --- a/src/app/services/offer.service.ts +++ b/src/app/services/offer.service.ts @@ -1,9 +1,19 @@ import { Injectable } from '@angular/core'; +import { OFFERS } from '../mocks/offers'; +import Offer from '../models/offer'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class OfferService { + offers: Array; + + constructor() { + this.offers = OFFERS; + } + + public async getOfferByID(id: string) { + return this.offers.find((offer) => offer.id === id); + } - constructor() { } } diff --git a/src/app/services/outlet.service.ts b/src/app/services/outlet.service.ts index c30f407..f52608d 100644 --- a/src/app/services/outlet.service.ts +++ b/src/app/services/outlet.service.ts @@ -1,9 +1,38 @@ import { Injectable } from '@angular/core'; +import Outlet, { IOutlet } from '../models/outlet'; +import { OUTLETS } from '../mocks/outlets'; +import { OfferService } from './offer.service'; +import Offer from '../models/offer'; +import MenuItem from '../models/menu-item'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class OutletService { + outlets: Array - constructor() { } + constructor( + private offerService: OfferService + ) { + this.fetchOutlets(); + } + + private async getDenormalizedOutlet(outlet: Outlet) { + const offers = await Promise.all(outlet.offers.map(offer_id => this.offerService.getOfferByID(offer_id))); + const menu_items: MenuItem[] = []; + + return { + ...outlet, + offers, + menu_items, + }; + } + + private async fetchOutlets() { + this.outlets = await Promise.all(OUTLETS.map(this.getDenormalizedOutlet)); + } + + public async getOutletByID(id: string) { + return this.outlets.find((outlet) => outlet.id === id); + } }