Skip to content

Commit

Permalink
feat: add start time and station in order
Browse files Browse the repository at this point in the history
  • Loading branch information
katyastan committed Aug 25, 2024
1 parent aaea018 commit e4cb2c1
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 31 deletions.
2 changes: 0 additions & 2 deletions src/app/api/models/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export interface Order {
schedule: {
segments: Segment[];
};
stationStart: number;
stationEnd: number;
}

export interface User extends Profile {
Expand Down
86 changes: 86 additions & 0 deletions src/app/api/ordersService/orders.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Order } from '@/app/api/models/order';

export const ordersDummyData: Order[] = [
{
id: 64,
rideId: 45,
routeId: 18,
seatId: 33,
userId: 3,
status: 'active',
path: [33, 5, 62, 11, 48, 34],
carriages: [
'carriage_type_2',
'carriage_type_2',
'carriage_type_2',
'carriage_type_2',
'carriage_type_7',
'carriage_type_7',
'carriage_type_7',
'carriage_type_7',
],
schedule: {
segments: [
{
time: ['2021-08-10T08:00:00', '2021-08-10T08:30:00'],
price: {
adult: 1000,
child: 500,
student: 700,
},
occupiedSeats: [32],
},
{
time: ['2021-08-10T08:30:00', '2021-08-10T09:00:00'],
price: {
adult: 1000,
child: 500,
student: 700,
},
occupiedSeats: [32],
},
],
},
},
{
id: 65,
rideId: 46,
routeId: 19,
seatId: 34,
userId: 3,
status: 'active',
path: [33, 5, 62, 11, 48, 34],
carriages: [
'carriage_type_2',
'carriage_type_2',
'carriage_type_2',
'carriage_type_2',
'carriage_type_7',
'carriage_type_7',
'carriage_type_7',
'carriage_type_7',
],
schedule: {
segments: [
{
time: ['2021-08-11T08:00:00', '2021-08-11T08:30:00'],
price: {
adult: 1000,
child: 500,
student: 700,
},
occupiedSeats: [33],
},
{
time: ['2021-08-11T08:30:00', '2021-08-11T09:00:00'],
price: {
adult: 1000,
child: 500,
student: 700,
},
occupiedSeats: [33],
},
],
},
},
];
15 changes: 11 additions & 4 deletions src/app/api/ordersService/orders.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { inject, Injectable, signal } from '@angular/core';

import { Observable } from 'rxjs';
import { Observable, shareReplay, tap } from 'rxjs';

import ENDPOINTS from '../constants/constants';
import { Order, OrderId, OrderRequest, User } from '../models/order';
import { ordersDummyData } from './orders.data';

@Injectable({
providedIn: 'root',
})
export class OrdersService {
private httpClient = inject(HttpClient);
public allOrders = signal<Order[]>([]);

public getAllOrders(): Observable<Order[]> {
return this.httpClient.get<Order[]>(ENDPOINTS.ORDER);
public getOrders(): Observable<Order[]> {
return this.httpClient.get<Order[]>(ENDPOINTS.ORDER).pipe(
shareReplay(1),
// Temporar solution with hardcoded data
// tap((orders) => this.allOrders.set(orders)),
tap(() => this.allOrders.set(ordersDummyData)),
);
}

public makeOrder(order: OrderRequest): Observable<OrderId> {
Expand Down
13 changes: 13 additions & 0 deletions src/app/orders/components/order/order.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<hr />
<div class="wrapper">
<p>Order ID: {{ order.id }}</p>
<p>
Start Time: <b>{{ order.schedule.segments[0].time[0] | date: 'MMMM dd HH:mm' }}</b>
</p>
<p>
Start Station:
@if (stationsService.findStationById(order.path[0]); as startStation) {
<b>{{ startStation.city }}</b>
}
</p>
</div>
File renamed without changes.
27 changes: 27 additions & 0 deletions src/app/orders/components/order/order.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, Input, OnDestroy } from '@angular/core';

import { ButtonModule } from 'primeng/button';
import { RippleModule } from 'primeng/ripple';
import { Subscription } from 'rxjs';

import { Order } from '@/app/api/models/order';
import { StationsService } from '@/app/api/stationsService/stations.service';

@Component({
selector: 'app-order',
standalone: true,
imports: [ButtonModule, RippleModule, DatePipe],
templateUrl: './order.component.html',
styleUrl: './order.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrderComponent implements OnDestroy {
@Input() public order!: Order;
public stationsService = inject(StationsService);
private subsciption = new Subscription();

public ngOnDestroy(): void {
this.subsciption.unsubscribe();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
orders-list works!
<div>
@for (order of orders; track order.id) {
<app-order [order]="order"></app-order>
}
</div>
</div>
Empty file.
17 changes: 17 additions & 0 deletions src/app/orders/components/orders-list/orders-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';

import { Order } from '@/app/api/models/order';

import { OrderComponent } from '../order/order.component';

@Component({
selector: 'app-orders-list',
standalone: true,
imports: [OrderComponent],
templateUrl: './orders-list.component.html',
styleUrl: './orders-list.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrdersListComponent {
@Input() public orders!: Order[];
}
7 changes: 7 additions & 0 deletions src/app/orders/pages/orders/orders.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<p>orders works!</p>

<div class="wrapper">
@let orders = ordersService.allOrders();
@if (orders.length) {
<app-orders-list [orders]="orders"></app-orders-list>
}
</div>
22 changes: 0 additions & 22 deletions src/app/orders/pages/orders/orders.component.spec.ts

This file was deleted.

28 changes: 25 additions & 3 deletions src/app/orders/pages/orders/orders.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, OnDestroy, OnInit } from '@angular/core';

import { Subscription } from 'rxjs';

import { OrdersService } from '@/app/api/ordersService/orders.service';
import { StationsService } from '@/app/api/stationsService/stations.service';

import { OrdersListComponent } from '../../components/orders-list/orders-list.component';

@Component({
selector: 'app-orders',
standalone: true,
imports: [],
imports: [CommonModule, OrdersListComponent],
templateUrl: './orders.component.html',
styleUrl: './orders.component.scss',
providers: [DatePipe],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrdersComponent {}
export class OrdersComponent implements OnInit, OnDestroy {
public ordersService = inject(OrdersService);
public stationsService = inject(StationsService);
private subsciption = new Subscription();

public ngOnInit(): void {
this.subsciption.add(this.ordersService.getOrders().subscribe());
this.subsciption.add(this.stationsService.getStations().subscribe());
}

public ngOnDestroy(): void {
this.subsciption.unsubscribe();
}
}

0 comments on commit e4cb2c1

Please sign in to comment.