Skip to content

Commit

Permalink
Adding github workflow for checkout-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Dec 28, 2023
1 parent 08d2453 commit abee90c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/checkout-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

name: checkout-api

on:
push:
branches:
- develop
paths:
- 'src/backend/services/checkout-api/**'
- '.github/workflows/checkout-api.yml'

pull_request:
branches:
- develop
paths:
- 'src/backend/services/checkout-api/**'
- '.github/workflows/checkout-api.yml'


jobs:
build-release:
uses: ./.github/workflows/build-release.yml
with:
service-name: checkout-api
secrets: inherit

deploy:
if: github.ref == 'refs/heads/develop'
needs:
- build-release
uses: ./.github/workflows/deploy.yml
with:
service-name: checkout-api
version: ${{ needs.build-release.outputs.new-version }}

7 changes: 0 additions & 7 deletions k8s-kustomize/services/basket-api/dev/http_route_patch.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions k8s-kustomize/services/basket-api/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ configMapGenerator:
name: basket-api
resources:
- ../base
patches:
- path: http_route_patch.yaml
4 changes: 2 additions & 2 deletions src/backend/services/checkout-api/src/checkout/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as api from '@opentelemetry/api';
import { randomUUID } from "crypto";
import { CartItem, CheckoutEvent, UserCheckout } from "../model";
import { CartItem, CheckoutEvent, UserCheckoutReq } from "../model";
import getCustomerCartItems from "../cart/cartService";
import Payment from "../payment/paymentService";
import { logger } from "../logger";
import checkoutPublisher from "../messagging/publisher";

export default async function Checkout(checkout: UserCheckout) {
export default async function Checkout(checkout: UserCheckoutReq) {
const span = api.trace.getTracer('checkout-api').startSpan('checkout-api.Checkout');
await api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), async () => {
try {
Expand Down
12 changes: 6 additions & 6 deletions src/backend/services/checkout-api/src/model.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export interface UserCheckout {
address: Address;
credit_card: CreditCard;
export interface UserCheckoutReq {
address: AddressReq;
credit_card: CreditCardReq;
customer_id: string;
email: string;
user_currency: string;
}

export interface Address {
export interface AddressReq {
city: string;
country: string;
state: string;
street_address: string;
zip_code: number;
}

export interface CreditCard {
export interface CreditCardReq {
credit_card_cvv: number;
credit_card_expiration_month: number;
credit_card_expiration_year: number;
Expand All @@ -34,6 +34,6 @@ export interface CartItem {

export interface CheckoutEvent {
transaction_id?: string;
user_checkout: UserCheckout;
user_checkout: UserCheckoutReq;
customer_cart: CustomerCart
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sinon from 'sinon';
import { expect } from "chai";
import type * as grpc from '@grpc/grpc-js'
import { paymentService, pay } from "./paymentService";
import { CartItem, UserCheckout } from "../model";
import { CartItem, UserCheckoutReq } from "../model";
import { PaymentResponse } from '../gen/payment/PaymentResponse';
import { PaymentRequest } from '../gen/payment/PaymentRequest';

Expand All @@ -26,7 +26,7 @@ describe("pay", () => {
{ item_id: "item1", price: 9.99, quantity: 2 },
{ item_id: "item2", price: 14.99, quantity: 1 },
];
const userCheckout: UserCheckout = {
const userCheckout: UserCheckoutReq = {
address: {
street_address: "123 Main St",
city: "Anytown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as grpc from '@grpc/grpc-js'
import * as protoLoader from '@grpc/proto-loader'
import { ProtoGrpcType } from '../gen/payments';
import path from 'path'
import { UserCheckout } from '../model';
import { UserCheckoutReq } from '../model';
import { PaymentResponse } from '../gen/payment/PaymentResponse';
import { PaymentRequest } from '../gen/payment/PaymentRequest';
import { CartItem } from '../gen/cart/CartItem';
Expand Down Expand Up @@ -32,13 +32,13 @@ const asyncPayment = (req: PaymentRequest): Promise<PaymentResponse> => {

export default function Payment(
checkoutID: string,
userCheckout: UserCheckout,
userCheckout: UserCheckoutReq,
cartItems: CartItem[],
): Promise<PaymentResponse> {
return pay(cartItems, userCheckout, checkoutID);
}

export function pay(cartItems: CartItem[], userCheckout: UserCheckout, orderId: string): Promise<PaymentResponse> {
export function pay(cartItems: CartItem[], userCheckout: UserCheckoutReq, orderId: string): Promise<PaymentResponse> {
let amount = 0;
for (const cartItem of cartItems) {
const totalPrice = Number(cartItem.price) * Number(cartItem.quantity);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/services/checkout-api/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express, { Request, Response } from "express";
import { UserCheckout } from "./model";
import { UserCheckoutReq } from "./model";
import Checkout from "./checkout/checkout";

const router = express.Router();

router.post('/api/v1/checkout', async (req: Request<{}, {}, UserCheckout>, res: Response) => {
router.post('/api/v1/checkout', async (req: Request<{}, {}, UserCheckoutReq>, res: Response) => {
try {
await Checkout(req.body);
res.send('Checkout OK');
Expand Down
1 change: 1 addition & 0 deletions src/backend/services/checkout-api/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1

0 comments on commit abee90c

Please sign in to comment.