Skip to content

Task 3 (First API with AWS API Gateway and AWS Lambda)#1

Open
mrCrab2024 wants to merge 2 commits intomainfrom
task-3
Open

Task 3 (First API with AWS API Gateway and AWS Lambda)#1
mrCrab2024 wants to merge 2 commits intomainfrom
task-3

Conversation

@mrCrab2024
Copy link
Copy Markdown
Owner

@mrCrab2024 mrCrab2024 commented Sep 25, 2022

Service done

Link to Product Service API - https://cm3jpo1x3b.execute-api.eu-west-1.amazonaws.com/dev/products
Link to FE website - https://d3pqms05kkm99n.cloudfront.net/
Link to FE PR - mrCrab2024/shop-angular-cloudfront#2

PR for FE

Product schema:
Product = {
count: number;
description: string;
id: string;
price: number;
title: string;
cover: string;
};

Self-checking:

Evaluation criteria (each mark includes previous mark criteria)

1 - Product Service Serverless config contains configuration for 2 lambda functions, API is not working at all, but YAML configuration is correct
2 - The getProductsList OR getProductsById lambda function returns a correct response (POINT1)
3 - The getProductsById AND getProductsList lambda functions return a correct response code (POINT2)
4 - Your own Frontend application is integrated with Product Service (/products API) and products from Product Service are represented on Frontend. AND POINT1 and POINT2 are done.

Additional (optional) tasks
+1 - Async/await is used in lambda functions
+1 - ES6 modules are used for Product Service implementation
+1 - Custom Webpack/ESBuild/etc is manually configured for Product Service. Not applicable for preconfigured/built-in bundlers that come with templates, plugins, etc.
Not implemented (All languages) - SWAGGER documentation is created for Product Service
Not implemented (All languages) - Lambda handlers are covered by basic UNIT tests (NO infrastructure logic is needed to be covered)
+1 (All languages) - Lambda handlers (getProductsList, getProductsById) code is written not in 1 single module (file) and separated in codebase.
+1 (All languages) - Main error scenarios are handled by API ("Product not found" error).

Total: 9

import { Product } from '@functions/ProductType';

export const findProduct = (arr: Product[], id: string) =>
arr.find((product) => product.id === id) ?? 'product not found';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest returning null for a not found product. It'd be more expected.


const getProductsById = async (event: APIGatewayProxyEvent) => {
const { productId } = event.pathParameters;
return formatJSONResponse(findProduct(products, productId));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a product is not found, it would be appropriate to return 404 status code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants