bonzzy / project3_mobility

NestJs CRUD API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

Api requirements:

A user should be able to:

  • Do CRUD actions for folders, subfolders and files
  • Search files by their exact name within a parent folder or across all folders List the top 10 files that start with a search string. This will be used in the search box to show possible matches when the user is typing. Only “start with” logic is required.

Installation

$ npm install

Running the app

# run local db (make sure that your local Docker is up and running)
$ cd docker && docker-compose up && cd -

# prepare the env values (preffered way is to create a file in root .env with the content taken from .env.example file)
$ cp .env.example .env

# deploy database migrations
$ npm run migrations:run

# development
$ npm run start

# development with a watcher
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Swagger API docs

Folder API

http://localhost:3000/api/folder

File API

http://localhost:3000/api/file

How to use the filesystem API

Assumption is that the API is running on http://localhost/3000

Test if the API is up and running

curl --location --request GET 'http://localhost:3000/healthz'

Create a new folder in root

curl --location --request POST 'http://localhost:3000/folder' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Folder Name"
}'

CRUD operations are available for the /folder endpoint (POST, GET, PUT, DELETE)

Find folders by query

curl --location --request GET 'http://localhost:3000/folder/find?parentFolderId=2fc85585-a1f7-4138-b867-fd70c0234433&name=Folder Name'

Create a new file in the created folder

curl --location --request POST 'http://localhost:3000/file' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "File",
    "parentFolderId": "d0b16064-db18-4969-8a12-433d25a6ce14",
    "content": "this is the content of a file"
}'

CRUD operations are available for the /file endpoint (POST, GET, PUT, DELETE)

Find files by query

curl --location --request GET 'http://localhost:3000/file/find?name=File&parentFolderId=f4b958c2-d0ab-4db2-a0dd-fb920a14b3c5&limit=2'

Find files by query and where name starts with

curl --location --request GET 'http://localhost:3000/file/find/starts-with/?parentFolderId=8e691f14-1f80-4262-8071-db4847ae082d&name=Fi'

About

NestJs CRUD API


Languages

Language:TypeScript 97.1%Language:JavaScript 1.6%Language:Shell 1.3%