forked from espiers13/hidden-gems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b594167
commit d93a091
Showing
1 changed file
with
57 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,255 +1,76 @@ | ||
# Hidden Gems API | ||
|
||
## Hosted on Supabase and Render | ||
|
||
### [View Hidden Gems API](https://hidden-gems-backend-vuh3.onrender.com/api) | ||
|
||
## **Table of Contents** | ||
- [**Introduction**](#introduction) | ||
- [**Endpoints and Example Responses**](#endpoints-and-example-responses) | ||
- [**Database Setup**](#database-setup) | ||
- [**Installation**](#installation) | ||
- [**Dev Dependencies used**](#dev-dependencies-used) | ||
- [**Dependencies**](#dependencies) | ||
|
||
## **Introduction** | ||
|
||
Hidden Gems is a RESTful API built for the purpose of accessing application data programatically for a front end application. | ||
- [**About This Project**](#about-this-project) | ||
- [**Project Links**](#project-links) | ||
- [**Available Endpoints**](#available-endpoints) | ||
- [**Running This Project Locally**](#running-this-project-locally) | ||
* [**Database Setup**](#database-setup) | ||
* [**Installation**](#installation) | ||
- [**Technology**](#technology) | ||
- [**Dependencies and Software Requirements**](#dependencies-and-softwares-requirements) | ||
* [**Dev Dependencies**](#dev-dependencies) | ||
* [**Dependencies**](#dependencies) | ||
|
||
## **About This Project** | ||
|
||
Hidden Gems API is a RESTful API built for the purpose of accessing application data programatically for a front end application. | ||
This is the backend service which provides information about events and places in Manchester, user information, and comment information, and provides this information to the front end architecture. | ||
The backend is built with PostgreSQL, node-postgres and Node.js, using the Express framework. | ||
|
||
## Project Links | ||
|
||
Backend API: https://hidden-gems-cd0h.onrender.com/api <br> | ||
Backend Repo: https://github.com/christianaao/hidden-gems-backend <br> | ||
Original Repo Link: https://github.com/espiers13/hidden-gems <br> | ||
|
||
## **Endpoints and Example Responses** | ||
|
||
- `GET /api` | ||
Responds with a JSON object of available endpoints. | ||
|
||
- `GET /api/users` | ||
Responds with a list of all users. | ||
Example response: | ||
```json | ||
{ | ||
"name": "John Doe", | ||
"username": "johndoe123", | ||
"email": "[email protected]", | ||
"password": "P@ssw0rd123!", | ||
"avatar_url": | ||
"https://avatar.iran.liara.run/public/59", | ||
"user_type": "regular", | ||
} | ||
``` | ||
|
||
- `GET /api/users/:user_id` | ||
Responds with a single user specified by user id. | ||
Example response: | ||
```json | ||
{ | ||
"name": "Michael Brown", | ||
"username": "mikebrown789", | ||
"email": "[email protected]", | ||
"password": "Browny2024#", | ||
"avatar_url": | ||
"https://avatar.iran.liara.run/public/59", | ||
"user_type": "regular", | ||
} | ||
``` | ||
Frontend APP: https://hidden-gems-frontend.vercel.app/ <br> | ||
Frontend Repo: https://github.com/christianaao/hidden-gems-frontend <br> | ||
Original Repo Link: https://github.com/flynnjim/hidden-gems-frontend <br> | ||
|
||
- `POST /api/users` | ||
Adds a new user. | ||
Request body containing name, username, email, password, avatar_url and user_type. | ||
Example response: | ||
```json | ||
{ | ||
"user_id": 1, | ||
"name": "Emily Davis", | ||
"username": "emilyd202", | ||
"email": "[email protected]", | ||
"password": "Eml!DavS9987", | ||
"avatar_url": | ||
"https://avatar.iran.liara.run/public/59", | ||
"user_type": "regular", | ||
} | ||
``` | ||
## Available Endpoints | ||
|
||
- `PATCH /api/users` | ||
Updates a user. | ||
Accepts an object of one or more key-value pairs for: name, username, email, password, avatar_url and user_type. | ||
Constraints: does not accept changes to username. | ||
Example response: | ||
```json | ||
{ | ||
"user_id": 5, | ||
"name": "Emily Spiers", | ||
"username": "emilys123", | ||
"user_type": "regular", | ||
"email": "[email protected]", | ||
"password": "testpassword", | ||
"avatar_url": "https://avatar.iran.liara.run/public/59" | ||
} | ||
``` | ||
- `GET /api/comments` | ||
Serves an array of all comments. | ||
Queries: sort_by & order. | ||
Example response: | ||
```json | ||
{ | ||
"comments": [ | ||
{ | ||
"username": "emilyd202", | ||
"body": "The Foraging Adventure was such a unique experience! I learned so much about wild edibles. Highly recommend!", | ||
"gem_id": 4, | ||
"date": 1728166800 | ||
} | ||
] | ||
} | ||
``` | ||
* GET /api <br> | ||
* GET /api/users <br> | ||
* GET /api/users/:user_id <br> | ||
* POST /api/users <br> | ||
* PATCH /api/users <br> | ||
* GET /api/comments <br> | ||
* GET /api/comments/:gem_id <br> | ||
* POST /api/comments <br> | ||
* DELETE /api/comments/:comment_id <br> | ||
* GET /api/gems <br> | ||
* GET /api/gems/:gem_id <br> | ||
* POST /api/gems <br> | ||
* PATCH /api/gems <br> | ||
|
||
- `GET /api/comments/:gem_id` | ||
serves an array of all comments for specified gem_id. | ||
Queries: sort_by & order. | ||
Example response: | ||
```json | ||
{ | ||
"comments": [ | ||
{ | ||
"username": "laurajohn01", | ||
"body": "The City Lights Photography Tour was spectacular! The guide offered amazing tips and I got some incredible shots.", | ||
"gem_id": 6, | ||
"date": 1727622000 | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- `POST /api/comments` | ||
Adds a new comment to specific gem. | ||
Example response: | ||
```json | ||
{ | ||
"comments": [ | ||
{ | ||
"username": "jamesc890", | ||
"body": "Moonlit Rooftop Bar is a gem! The view of the city skyline at night is stunning and the cocktails are top-notch.", | ||
"gem_id": 9, | ||
"date": 1728330600 | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- `DELETE /api/comments/:comment_id` | ||
Deletes comment by comment_id. | ||
Example response: | ||
```json | ||
{} | ||
``` | ||
_Please see `endpoints.json` for all available endpoints and example responses_ | ||
|
||
- `GET /api/gems` | ||
Serves an array of all gems. | ||
Queries: sort_by, order, category, date, type. | ||
Example response: | ||
```json | ||
[ | ||
{ | ||
"title": "The Secret Garden Cafe", | ||
"description": "I stumbled upon this little gem while wandering around the neighborhood. The garden patio is such a peaceful escape from the city, and the coffee? Absolutely the best I've had in a long time! The pastries are homemade and pair perfectly with their artisan brews. I'll definitely be back to enjoy more quiet mornings here.", | ||
"category": "food", | ||
"img_url": ["https://firebasestorage.googleapis.com/v0/b/fir-project-28217.appspot.com/o/gems%2Frooftop-bar.jpg?alt=media&token=85c35ee4-006c-4f20-922f-e4e84b205731"], | ||
"latitude": 53.4642, | ||
"longitude": -2.2365, | ||
"address": "12a Levenshulme Rd, Manchester M19 2BA, United Kingdom", | ||
"date": null, | ||
"user_id": 3, | ||
"gem_id": 3, | ||
"type": "place", | ||
"rating": 1.5 | ||
} | ||
] | ||
``` | ||
|
||
- `GET /api/gems/:gem_id` | ||
Serves a single gem by gem_id. | ||
Example response: | ||
```json | ||
{ | ||
"title": "Foraging Adventure", | ||
"description": "Join a foraging expert on a walk through nature, learning about what you can eat from nature!", | ||
"category": "nature", | ||
"img_url": [ | ||
"https://firebasestorage.googleapis.com/v0/b/fir-project-28217.appspot.com/o/gems%2Fforaging-adventure.webp?alt=media&token=5799c51d-0062-457d-9be9-26e2789b76b2" | ||
], | ||
"latitude": 53.40998, | ||
"longitude": -2.231808, | ||
"address": "18 Stenner Ln, Didsbury, Manchester M20 2RQ", | ||
"date": "2023-10-05T07:00:00.000Z", | ||
"user_id": 1, | ||
"gem_id": 2, | ||
"type": "event", | ||
"rating": "2.7" | ||
} | ||
``` | ||
|
||
- `POST /api/gems` | ||
Adds a new gem. | ||
Request body containing: title, description, category, img_url, latitude, longitude, address, date, user_id, type. | ||
Example response: | ||
```json | ||
{ | ||
"gem_id": 10, | ||
"description": "accepts an object as a gem and adds it to gems", | ||
"queries": [], | ||
"accepts": { | ||
"title": "Example Event Title", | ||
"description": "Example event description", | ||
"category": "culture", | ||
"img_url": ["https://example-img-url.com/"], | ||
"latitude": 53.4783, | ||
"longitude": -2.248, | ||
"address": "1 Hardman Square, Spinningfields, Manchester M3 3EB, United Kingdom", | ||
"date": "2025-01-17T18:00", | ||
"user_id": 4, | ||
"rating": [], | ||
"type": "event" | ||
} | ||
} | ||
``` | ||
|
||
|
||
- `PATCH /api/gems` | ||
accepts a key-value pair of a rating and adds it to the gems rating array, returning the new average rating. | ||
Example response: | ||
```json | ||
{ "rating": 3 } | ||
``` | ||
|
||
## **Database Setup** | ||
## Running This Project Locally | ||
### Database Setup | ||
|
||
To set up PostgreSQL on your system, follow this guide: [Install PostgreSQL](https://www.w3schools.com/postgresql/postgresql_install.php) | ||
|
||
To install npm: run `npm install npm@latest -g` un your terminal | ||
|
||
## **Installation** | ||
### Installation | ||
|
||
1. **Clone the repository** | ||
1. In your terminal, locate the directory you would like to save the code to and enter the following. This command will clone this repo: | ||
```bash | ||
git clone https://github.com/flynnjim/hidden-gems | ||
git clone https://github.com/christianaao/hidden-gems-backend | ||
``` | ||
|
||
2. **Install dependencies** | ||
```bash | ||
npm install | ||
``` | ||
2. In the cloned directory, type `npm install` in your terminal to install all dependencies. | ||
|
||
3. **Scripts** | ||
3. Enter the following Dev-Dependency Scripts into your packet.json file: | ||
- "setup-dbs": "psql -f ./db/setup.sql", | ||
- "seed": "node ./db/seeds/run-seed.js", | ||
- "test": "jest", | ||
- "prepare": "husky install", | ||
- "start": "node listen.js", | ||
- "seed-prod": "NODE_ENV=production npm run seed" | ||
|
||
4. **Create .env files** | ||
To connect to the databases locally, you need two .env files: | ||
4. To connect to the databases locally, create two dotenv files: | ||
|
||
- .env.development: | ||
```makefile | ||
|
@@ -258,54 +79,50 @@ To set up PostgreSQL on your system, follow this guide: [Install PostgreSQL](htt | |
- .env.test: | ||
```makefile | ||
PGDATABASE=hidden_gems_test | ||
``` | ||
5. **Setup the database** | ||
To create the necessary databases, run: | ||
``` | ||
|
||
5. To create the necessary databases, run: | ||
```bash | ||
npm run setup-dbs | ||
``` | ||
These files should point to your local PostgreSQL databases for development and testing environments. | ||
|
||
6. **Seed the database** | ||
Populate the development database with initial data by running: | ||
6. Populate the development database with initial data by running: | ||
```bash | ||
npm run seed | ||
``` | ||
Ensure that the database is correctly seeded before running any tests. | ||
|
||
7. **Run the Server** | ||
Start the application locally with: | ||
7. To start the application locally, run: | ||
```bash | ||
npm start | ||
``` | ||
This will start the Express server on your local machine. | ||
This will start the Express server on your local machine. _Please see `endpoints.json` for all available endpoints_ | ||
|
||
8. **Run tests** | ||
To run the test suite and verify the application’s functionality, use: | ||
8. To run the test suite and verify the application’s functionality, run: | ||
```bash | ||
npm test | ||
``` | ||
Tests are run using Jest and Supertest for API endpoint validation. | ||
|
||
## **Technologies Used** | ||
## **Technology** | ||
|
||
- **Node.js**: JavaScript runtime for building the backend. | ||
- **Express**: Web framework for handling routing and HTTP requests. | ||
- **PostgreSQL**: Relational database for storing data. | ||
- **node-postgres (pg)**: PostgreSQL client for Node.js. | ||
- **Jest & Supertest**: For testing the API endpoints. | ||
|
||
|
||
|
||
## **Dev Dependencies used** | ||
## Dependencies and Software Requirements | ||
### **Dev Dependencies** | ||
|
||
- `"husky": "^9.1.6",` | ||
- `"jest": "^29.7.0",` | ||
- `"jest-extended": "^4.0.2",` | ||
- `"jest-sorted": "^1.0.15",` | ||
- `"supertest": "^7.0.0"` | ||
|
||
## **Dependencies** | ||
### **Dependencies** | ||
|
||
- `"cors": "^2.8.5",` | ||
- `"dotenv": "^16.4.5",` | ||
|
@@ -314,6 +131,4 @@ To set up PostgreSQL on your system, follow this guide: [Install PostgreSQL](htt | |
- `"pg": "^8.13.0",` | ||
- `"pg-format": "^1.0.4"` | ||
|
||
--- | ||
|
||
This portfolio project was created as part of a Digital Skills Bootcamp in Software Development provided by [Northcoders](https://northcoders.com/) | ||
☺ I hope you enjoy testing my server ☺ |