Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gugutz/stairs-backend-challenge
Backend Challenge for Stairs Studio, written in Go.
https://github.com/gugutz/stairs-backend-challenge
Last synced: 27 days ago
JSON representation
Backend Challenge for Stairs Studio, written in Go.
- Host: GitHub
- URL: https://github.com/gugutz/stairs-backend-challenge
- Owner: gugutz
- Created: 2019-09-21T13:42:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-22T16:36:47.000Z (over 3 years ago)
- Last Synced: 2023-03-03T06:20:15.477Z (almost 2 years ago)
- Language: Go
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Stairs Backend Challenge
This is my solution for the Stairs Backend Challenge.
Written in Go, using MongoDB and Go Modules mode.
## Install and Run
This API uses [Go](http://golang.org) and [MongoDB](https://mongodb.com).
The MongoDB is instanced using [Docker Compose](https://github.com/docker/compose).
### Setting up the Database
The MongoDB is instanced using docker-compose.Navigate to the API folder and raise the database with:
```sh
$ docker-compose-up
```### Creating the database and a collection
Once MongoDB is up, you must create a database and a collection.
This setup also raises a **Mongo Express** instance to make this easier.The address to the Mongo Express configuration page is: **`localhost:8081`**
### Updating the configuration file
After creating the database and the collection, open the `config.toml` file in the root folder and update the fields to match the name of the database and the collection you created.
### Run the API
After raising the database instance, run the API:
```sh
$ go run main.go
```## API Description
This is a REST API made with Go that exposes 5 endpoints:
POST
/wines
Get all wines
*Parameters:*
```
No parameters
```
GET
/wines
Get all wines
*Parameters:*
```
No parameters
```
POST
/wines/new
Add wines
*Parameters:*
name string
harvestinteger
countrystring
amountint
descriptionstring
*Usage Example:*
```json
{
"name": "Petrus",
"harvest": 1984,
"country": "France",
"ammount": 0,
"description": "This wine comes from the regions of..."
}
```
NOTE: MongoDB adds the ObjectID automatically if its not specified
PUT
/wines/{id}
Update a wine
*Parameters:*
idint
wineStruct
*Usage Example:*
```json
{
"id": "5d881cf1d663f81498131a81",
"wine": {
"name": "New Name",
"harvest": 2005,
"country": "New Country",
"ammount": 0,
"description": "New description for the wine..."
}
}
```
DELETE
/wines/{id}
Deletes a wine
*Parameters:*
idint