| @@ -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; | |||
| } | |||
| @@ -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<Mall>; | |||
| malls: Array<IMall>; | |||
| 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<Mall>) => { | |||
| this.mallService.getAllMalls().then((data: Array<IMall>) => { | |||
| this.malls = data; | |||
| }); | |||
| } | |||
| showMallDetails(mall: Mall) { | |||
| showMallDetails(mall: IMall) { | |||
| this.router.navigate(['/mall-details', { mall_id: mall.id }]); | |||
| } | |||
| @@ -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, | |||
| @@ -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, | |||
| @@ -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; | |||
| @@ -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<Offer>; | |||
| outlets: Array<Outlet>; | |||
| offers: Array<string>; | |||
| outlets: Array<string>; | |||
| 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<Offer>; | |||
| outlets: Array<IOutlet>; | |||
| rating: number; | |||
| distance: number; | |||
| location: CoOrdinates; | |||
| address: string; | |||
| } | |||
| export default Mall; | |||
| @@ -11,9 +11,9 @@ class Outlet { | |||
| image_url?: string; | |||
| name: string; | |||
| description: string; | |||
| offers: Array<Offer>; | |||
| offers: Array<string>; | |||
| tags: Array<string>; | |||
| menu_items: Array<MenuItem>; | |||
| menu_items: Array<string>; | |||
| 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<Offer>; | |||
| tags: Array<string>; | |||
| menu_items: Array<MenuItem>; | |||
| outlet_type: OutletType; | |||
| is_bookmarked: boolean; | |||
| rating: number; | |||
| }; | |||
| export default Outlet; | |||
| @@ -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)); | |||
| @@ -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<Mall>; | |||
| malls: Array<IMall>; | |||
| cart: Array<CartItem> = []; | |||
| constructor() { | |||
| @@ -1,9 +1,10 @@ | |||
| import { Injectable } from '@angular/core'; | |||
| import { OUTLETS } from '../mocks/outlets'; | |||
| @Injectable({ | |||
| providedIn: 'root' | |||
| providedIn: 'root' | |||
| }) | |||
| export class MenuItemService { | |||
| constructor() { } | |||
| constructor() { } | |||
| } | |||
| @@ -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<Offer>; | |||
| constructor() { | |||
| this.offers = OFFERS; | |||
| } | |||
| public async getOfferByID(id: string) { | |||
| return this.offers.find((offer) => offer.id === id); | |||
| } | |||
| constructor() { } | |||
| } | |||
| @@ -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<IOutlet> | |||
| 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); | |||
| } | |||
| } | |||