Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0278822
Initial
andrelcunha Feb 14, 2024
78c3499
Hello world
andrelcunha Feb 14, 2024
ca55edf
Connecting to mongoDB
andrelcunha Feb 14, 2024
2045c6d
Created POST route for products
andrelcunha Feb 15, 2024
f519511
Added POST route for categories
andrelcunha Feb 15, 2024
7330535
implemented catalog Routes and Controller
andrelcunha Feb 15, 2024
e7a11a2
Implemented product routes and controller
andrelcunha Feb 15, 2024
dfe02f8
created category DTOs and service
andrelcunha Feb 17, 2024
78b3c4a
created product DTOs and service
andrelcunha Feb 18, 2024
c20dfdc
added auto reload configuration
andrelcunha Feb 18, 2024
201557c
added necessary modules to convert it to TS
andrelcunha Feb 19, 2024
b41f472
modified app file
andrelcunha Feb 19, 2024
b439cf4
modified db file
andrelcunha Feb 19, 2024
a3d805b
Modified app and db files to use TS
andrelcunha Feb 19, 2024
dbe17a1
modified category files to use TS
andrelcunha Feb 19, 2024
38e4c22
modified product files to work with TS
andrelcunha Feb 19, 2024
b041067
Converted product files to TS
andrelcunha Feb 19, 2024
e09738a
Added build and prod configurations
andrelcunha Feb 19, 2024
09ecbcd
Update README.md
andrelcunha Feb 19, 2024
3d7c4af
Created Category Repository
andrelcunha Feb 19, 2024
3a83e26
Category Controller, Service and Repository working properly
andrelcunha Feb 20, 2024
8296dd1
Created Product Repository
andrelcunha Feb 20, 2024
5b94103
Implemented custom error
andrelcunha Feb 20, 2024
fda11ab
implemented usage of Product Repository
andrelcunha Feb 20, 2024
bb900b1
Fixed bug: price not multiplied after update
andrelcunha Feb 20, 2024
f51f14b
Handling errors "bad request" - Id not foud
andrelcunha Feb 20, 2024
6726fcf
AWS SDK v2 configuration
andrelcunha Feb 20, 2024
85abc28
AWS SNS Service implemented
andrelcunha Feb 20, 2024
86df177
initial jest configuration
andrelcunha Feb 20, 2024
fe1f0c7
Add jest test for publish sns message
andrelcunha Feb 21, 2024
c6a5b12
Created structure to versioning and deploing of AWS Lambda function '…
andrelcunha Feb 21, 2024
23755e3
Created AWS Lambda function
andrelcunha Feb 21, 2024
a2a2db6
Fixed typo on deploy.yml
andrelcunha Feb 21, 2024
5d58d97
Added client-sns
andrelcunha Feb 21, 2024
8a8137d
Fixed malformed fields on package.json
andrelcunha Feb 21, 2024
5e3760e
New deploy trial
andrelcunha Feb 21, 2024
7a3d934
Updated nodejs for actions
andrelcunha Feb 21, 2024
04e0b58
Updated node version
andrelcunha Feb 21, 2024
46159fe
Removed test from deploy.
andrelcunha Feb 21, 2024
6a08b4a
Fixed directory name on deploy file
andrelcunha Feb 21, 2024
783968a
Update deploy.yml
andrelcunha Feb 21, 2024
6972f13
Testing path for deploy
andrelcunha Feb 21, 2024
c3412e7
Added listing step for trobleshooting
andrelcunha Feb 21, 2024
a31e522
removed path key from deploy file
andrelcunha Feb 21, 2024
6ec8d4c
Especifiying path for zip
andrelcunha Feb 21, 2024
c6031c2
Fixing typo on path
andrelcunha Feb 21, 2024
c0200bf
Added path to narrow down the deploy
andrelcunha Feb 21, 2024
cc37c43
Changed path filter
andrelcunha Feb 21, 2024
4c1ba23
Removed paths filter
andrelcunha Feb 21, 2024
bc00634
Fixed deploy variables
andrelcunha Feb 21, 2024
3eece20
Fixed typo on deploy file
andrelcunha Feb 21, 2024
c08b7ec
Removed list step
andrelcunha Feb 21, 2024
43659f5
Fixed bugs on lambda functio
andrelcunha Feb 21, 2024
b927a9a
Added "Deploy to AWS Lambda" badge on README
andrelcunha Feb 21, 2024
3cb1f71
Added badge on README
andrelcunha Feb 22, 2024
5e762ed
Fixed deploy file extension
andrelcunha Feb 22, 2024
ea7f57e
Addes step to set env vars on AWS Lambda
andrelcunha Feb 22, 2024
7b1468d
Fixed command line for setting the environment variables
andrelcunha Feb 22, 2024
465f325
Fixed command line sintaxe to set env vars
andrelcunha Feb 22, 2024
780741d
Lambda function working on AWS SAM
andrelcunha Feb 23, 2024
3ef297c
Fixed function ARN on template
andrelcunha Feb 23, 2024
6b98fa7
Fixed variable setting syntax
andrelcunha Feb 23, 2024
adae6c9
Delayed deploy step
andrelcunha Feb 23, 2024
af81823
Delete .vscode/settings.json
andrelcunha Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy to AWS Lambda

on:
push:
branches:
- master
- development

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
run: npm ci

- name: Package Lambda function
run: |
zip -r ./function.zip ./catalog-emit-consumer/.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Update Lambda environment variables
env:
MONGO_URI: ${{ secrets.MONGO_URI }}
AWS_SQS_QUEUE_URL: ${{ vars.AWS_SQS_QUEUE_URL }}
AWS_S3_BUCKET: ${{ vars.AWS_S3_BUCKET }}
run: |
aws lambda update-function-configuration --function-name catalog-emit-consumer --environment Variables="{MONGO_URI=$MONGO_URI,AWS_SQS_QUEUE_URL=$AWS_SQS_QUEUE_URL,AWS_S3_BUCKET=$AWS_S3_BUCKET}"

- name: Deploy to AWS Lambda
run: |
aws s3 cp function.zip s3://ifood-product-catalog-bucket
aws lambda update-function-code --function-name catalog-emit-consumer --s3-bucket ifood-product-catalog-bucket --s3-key function.zip
132 changes: 132 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

api.http
94 changes: 48 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
# Product Catalog Management System API
[![Deploy to AWS Lambda](https://github.com/andrelcunha/new-test-backend-nodejs/actions/workflows/deploy.yml/badge.svg)](https://github.com/andrelcunha/new-test-backend-nodejs/actions/workflows/deploy.yml)

<h1>Backend Analyst Candidate Test</h1>
Dear developer,
## Overview

Welcome to the Backend Analyst Candidate Test. This test aims to assess your general knowledge and development speed. Below, you will find the details and requirements for this test.
This is a Node.js backend API for a product catalog management system in a marketplace application. The API is built with TypeScript and Express.js, and uses MongoDB for data persistence. It provides basic CRUD operations for data entities (products, categories), and includes error handling and middleware for a better user experience.


<strong>The Challenge</strong>
This is a Node.js backend API for a product catalog management system in a marketplace application. The API provides basic CRUD operations for data entities (products, categories), database connection using MongoDB, and error handling and middleware for a better user experience.

Your task is to develop an API using Node.js for a product catalog management system in a marketplace application. You should analyze and convert the following user stories into routes for the application:
## Installation

<strong>User Stories:</strong>
1. Clone the repository: `git clone https://github.com//your-repo-name.git`
2. Navigate to the project directory: `cd your-repo-name`
3. Install the dependencies: `npm install`
4. Create a `.env` file in the root of your project and insert your key-value pairs in the following format of `KEY=VALUE`:
```env
MONGO_URI=your_mongodb_uri
PORT=your_port_number
```
5. Run the build script: `npm run build`

- As a user, I want to register a product with its owner, so that I can access its data in the future (title, description, price, category, owner ID).
- As a user, I want to register a category with its owner, so that I can access its data in the future (title, description, owner ID).
- As a user, I want to associate a product with a category.
- As a user, I want to update the data of a product or category.
- As a user, I want to delete a product or category from my catalog.
- A product can only be associated with one category at a time.
- Assume that products and categories belong only to one owner.
## Usage

- Keep in mind that this is an online product catalog, which means there will be multiple requests for editing items/categories per second, as well as accessing the catalog search endpoint.
- Consider the product catalog as a JSON compilation of all available categories and items owned by a user. This way, the catalog search endpoint does not need to fetch information from the database.
- Whenever there is a change in the product catalog, publish this change to the "catalog-emit" topic in the AWS SQS service.
- Implement a consumer that listens to catalog changes for a specific owner.
- When the consumer receives a message, search the database for that owner's catalog, generate the catalog JSON, and publish it to an AWS S3 service bucket.
1. To start the application in development mode, run: `npm run start:dev`
2. To start the application in production mode, run: `npm run start:prod`

<strong>You need to develop this test using the following technologies:</strong>
## Environment Variables

- MongoDB for the database.
- AWS SQS for the catalog change notifications.
- AWS S3 for storing the catalog JSON.
- Node.js for the backend.
- Express.js as the web framework.
The application uses the following environment variables:

<hr>
<strong>Diagram representing the final structure of the project:</strong> <br><br>
![image](https://github.com/githubanotaai/new-test-backend-nodejs/assets/52219768/504ba448-f128-41db-ae86-18dc19c0dc9d)
- `MONGO_URI`: Your MongoDB URI.
- `PORT`: The port number on which your application will run.

## Future Work

<hr>
- **User Stories Implementation**: Ensure all user stories are implemented, including associating a product with a category and ensuring a product can only be associated with one category at a time.
- **AWS SQS for Catalog Change Notifications**: Implement a feature to publish changes to the "catalog-emit" topic in the AWS SQS service whenever there is a change in the product catalog.
- **AWS S3 for Storing the Catalog JSON**: Implement a consumer that listens to catalog changes for a specific owner. When the consumer receives a message, search the database for that owner's catalog, generate the catalog JSON, and publish it to an AWS S3 service bucket.
- **Unit Tests**: Implement unit tests to ensure the functionality of your application.
- **Logging Mechanisms**: Implement logging mechanisms to track the operations and possible errors in your application.
- **Documentation**: Improve the documentation quality, including instructions on how to run your application and an explanation of your code.
- **Code Organization and Readability**: Enhance code readability and maintainability through refactoring and documentation. Ensure proper structure of the application layers and effective use of environment variables.

<strong>Instructions</strong>
## Contributing

<strong>To begin the test, fork this repository, create a branch with your full name, and send us the link to your completed test (link to your repository). If you only clone the repository, you won't be able to push changes, making the pull request more complicated.</strong>
- Use your own AWS account to set up the required services.
- Update the README file with instructions on how to run your application.
- Paste the branch name into the GUPY system and indicate the completion of the test.
- Feel free to provide us with feedback regarding the test.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

<strong>Our Evaluation Criteria</strong>
We will assess the following aspects of your solution:
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

- Knowledge of JavaScript, Node.js, and Express.js.
- Proper structure of the application layers.
- Handling of outgoing calls.
- Effective use of environment variables.
- Implementation of unit tests.
- Logging mechanisms.
- Error handling strategies.
- Documentation quality.
- Code organization, module separation, readability, and comments.
- Commit history.
Please ensure your pull request adheres to the following guidelines:

- Write clear meaningful git commit messages (Do read this).
- Make sure your PR's description contains GitHub's special keyword references that automatically close the related issue when the PR is merged. (More info at this link).
- When you create a Pull Request, make sure to review the changes you are proposing, tell us why you are proposing them, and how you tested that the changes you are introducing work as expected.
- Provide tests for your changes.
- End all files with a newline.

## License

This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Loading