Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-sa committed Aug 29, 2024
1 parent 8c93b4f commit 2587082
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 211 deletions.
4 changes: 2 additions & 2 deletions kitchen-service-api/src/lib/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export interface KitchenRpcController {
createdTickets(): Promise<Observable<TicketCreated>>;
rejectedTickets(): Promise<Observable<TicketRejected>>;
confirmedTickets(): Promise<Observable<TicketConfirmed>>;
confirmTicket(id: UUID, readyAt: Date): Promise<void>;
rejectTicket(id: UUID, reason: string): Promise<void>;
confirmTicket(id: UUID, readyAt: Date): Promise<TicketConfirmed>;
rejectTicket(id: UUID, reason: string): Promise<TicketRejected>;
}
1 change: 0 additions & 1 deletion kitchen-service/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class Ticket {
) {}

reject(this: Writable<this>, reason: string): TicketRejected {
console.log('reject');
if (this.state !== TicketState.CREATED) {
throw new UnsupportedStateTransitionException(this.state);
}
Expand Down
10 changes: 4 additions & 6 deletions kitchen-service/src/kitchen.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ export class KitchenController implements KitchenRpcController {
}

@rpc.action()
async confirmTicket(id: UUID, readyAt: Date): Promise<void> {
// return await this.client.rpc(this.kitchen.confirmTicket(id, readyAt));
await this.client.send(this.kitchen.confirmTicket(id, readyAt));
async confirmTicket(id: UUID, readyAt: Date): Promise<TicketConfirmed> {
return await this.client.rpc(this.kitchen.confirmTicket(id, readyAt));
}

@rpc.action()
async rejectTicket(id: UUID, reason: string): Promise<void> {
// return await this.client.rpc(this.kitchen.rejectTicket(id, reason));
await this.client.send(this.kitchen.rejectTicket(id, reason));
async rejectTicket(id: UUID, reason: string): Promise<TicketRejected> {
return await this.client.rpc(this.kitchen.rejectTicket(id, reason));
}
}
5 changes: 0 additions & 5 deletions order-history-service/.env

This file was deleted.

18 changes: 0 additions & 18 deletions order-history-service/.eslintrc.json

This file was deleted.

100 changes: 0 additions & 100 deletions order-history-service/project.json

This file was deleted.

3 changes: 0 additions & 3 deletions order-history-service/src/config.ts

This file was deleted.

17 changes: 0 additions & 17 deletions order-history-service/src/main.ts

This file was deleted.

4 changes: 0 additions & 4 deletions order-history-service/src/order-history.controller.ts

This file was deleted.

9 changes: 0 additions & 9 deletions order-history-service/tsconfig.app.json

This file was deleted.

16 changes: 0 additions & 16 deletions order-history-service/tsconfig.json

This file was deleted.

8 changes: 0 additions & 8 deletions order-history-service/tsconfig.spec.json

This file was deleted.

6 changes: 0 additions & 6 deletions order-history-service/vite.config.ts

This file was deleted.

18 changes: 16 additions & 2 deletions order-service-api/src/lib/replies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@ export class OrderNotFound extends Error {
}
}

export class OrderApproved {}
export class OrderCreated {
constructor(public readonly orderId: UUID) {}
}

export class OrderApproved {
constructor(
public readonly orderId: UUID,
public readonly approvedAt: Date,
) {}
}

export class OrderRejected {}
export class OrderRejected {
constructor(
public readonly orderId: UUID,
public readonly rejectedAt: Date,
) {}
}

export class OrderRevisionProposed {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions order-service-api/src/lib/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { UUID } from '@deepkit/type';
import { RestaurantCreatedEvent } from '@ftgo/restaurant-service-api';

import { OrderDetails } from './entities';
import { OrderApproved, OrderRejected } from './replies';
import { OrderApproved, OrderCreated, OrderRejected } from './replies';

export interface OrderServiceHandlers {
create(orderId: UUID, details: OrderDetails): Promise<UUID>;
create(orderId: UUID, details: OrderDetails): Promise<OrderCreated>;
beginCancel(id: UUID): Promise<void>;
undoBeginCancel(id: UUID): Promise<void>;
undoCancel(id: UUID): Promise<void>;
Expand Down
14 changes: 12 additions & 2 deletions order-service/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { Money, UnsupportedStateTransitionException } from '@ftgo/common';
import {
DeliveryInformation,
LineItemQuantityChange,
OrderApproved,
OrderLineItemNotFound,
OrderMinimumNotMet,
OrderRejected,
OrderRevised,
OrderRevision,
OrderRevisionProposed,
Expand All @@ -40,6 +42,7 @@ export class Order {
readonly paymentInformation?: PaymentInformation;
readonly lineItems: OrderLineItems;
readonly rejectedAt?: Date;
readonly approvedAt?: Date;

constructor(
public readonly id: UUID & PrimaryKey,
Expand Down Expand Up @@ -72,19 +75,26 @@ export class Order {
this.state = OrderState.CANCELLED;
}

noteApproved(this: Writable<this>): void {
approve(this: Writable<this>): OrderApproved {
if (this.state !== OrderState.APPROVAL_PENDING) {
throw new UnsupportedStateTransitionException(this.state);
}

this.state = OrderState.APPROVED;
this.approvedAt = new Date();

return new OrderApproved(this.id, this.approvedAt);
}

noteRejected(this: Writable<this>) {
reject(this: Writable<this>): OrderRejected {
if (this.state !== OrderState.APPROVAL_PENDING) {
throw new UnsupportedStateTransitionException(this.state);
}

this.state = OrderState.REJECTED;
this.rejectedAt = new Date();

return new OrderRejected(this.id, this.rejectedAt);
}

noteReservingPayment() {}
Expand Down
14 changes: 9 additions & 5 deletions order-service/src/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UUID } from '@deepkit/type';
import { RestaurantCreatedEvent } from '@ftgo/restaurant-service-api';
import {
OrderApproved,
OrderCreated,
OrderDetails,
OrderRejected,
OrderServiceApi,
Expand Down Expand Up @@ -31,15 +32,18 @@ export class OrderService implements OrderServiceHandlers {

@restate.handler()
async approve(id: UUID): Promise<OrderApproved> {
throw new Error('Not yet implemented');
const order = await this.order.findById(id);
const orderApproved = order.approve();
await this.order.save(order);
return orderApproved;
}

@restate.handler()
async reject(id: UUID): Promise<OrderRejected> {
const order = await this.order.findById(id);
order.noteRejected();
const orderRejected = order.reject();
await this.order.save(order);
return new OrderRejected();
return orderRejected;
}

@restate.handler()
Expand Down Expand Up @@ -68,13 +72,13 @@ export class OrderService implements OrderServiceHandlers {
async create(
orderId: UUID,
{ customerId, restaurantId, lineItems }: OrderDetails,
): Promise<UUID> {
): Promise<OrderCreated> {
const order = await this.order.create(
orderId,
customerId,
restaurantId,
lineItems,
);
return order.id;
return new OrderCreated(order.id);
}
}
Loading

0 comments on commit 2587082

Please sign in to comment.