Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dazaev added a README to his API #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
65 changes: 65 additions & 0 deletions UFC-API-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# UFC API DOCUMENTATION
### By Dazaev

Welcome to my UFC API! Here you will find the documentation you need to start retrieving, creating, updating and even deleting data! (But please... don't erase data)

## About my UFC API:
The API built on the principles of REST keeps track of current and past UFC fighters, you can access data like their fighting records, what country are they fighting from and if they're currently holding the title belt.

# PUBLIC ENDPOINTS

## This is the url where you can access all the data: https://guarded-mesa-21535.herokuapp.com/

## GET "/"
This will get you to the **homepage** where a welcome message will be displayed in the form of JSON data.
```
https://guarded-mesa-21535.herokuapp.com/
```

## GET "/fighters"
The fighters endpoint allows you to browse **all** published posts existing on the database.
```
https://guarded-mesa-21535.herokuapp.com/fighters
```
## GET "/fighters/:id"
This endpoint allows you to fetch a specific fighter based on its **id**.
```
https://guarded-mesa-21535.herokuapp.com/fighters/59dcdb5bd7aca80012cf1078
```

# PRIVATE ENDPOINTS
(This is the endpoints only **Admins** should be authorized to use, but hey feel free to contribute!)

## POST "/fighters"
With this method and this endpoint users can create via **Postman** new fighter entrees using the following guidelines:

```
{
firstName: String,
lastName: String,
titleHolder: Boolean,
country: String,
record: String,
}
```
They key "record" must have a value written like in this example "10-5", 10 being the fights the fighter has won and 5 being the ones he has lost.

## PUT "fighter/:id"
Using **PUT** in this endpoint allows users to modify the data of a specific previously created fighter entree by fetching it by its id. This is useful to keep all of their record data up to date. The guidelines on how to update their info are the same as the POST method mentioned above.
```
https://guarded-mesa-21535.herokuapp.com/fighters/59dcdb5bd7aca80012cf1078
```
```
{
titleHolder: true
record: "12-2"
}
```

## DELETE "fighter/:id"
**CAUTION!** I would suggest being careful with this method, avoid using it if you are not sure of how to use it. This endpoint looks for a fighter using its id and deletes it from the API.
```
https://guarded-mesa-21535.herokuapp.com/fighters/59dcdb5bd7aca80012cf1078
```

# This site is still in the works so hopefully when I get the chance I'll continue updating it since I'm a really big fan of MMA. Thanks for reading and have fun using it!
8 changes: 6 additions & 2 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const mongoose = require('mongoose');
require('dotenv').config();
// TODO: include all model files here (and export models together below)
const testModels = require('./test');
const fighterModels = require('./test');
const leagueModels = require('./league');
const teamModels = require('./team');

// connect to Mongo DB
mongoose.connection.openUri(process.env.MONGODB_URI || process.env.DB_CONN, {}, function(err, conn) {
Expand All @@ -14,5 +16,7 @@ mongoose.connection.openUri(process.env.MONGODB_URI || process.env.DB_CONN, {},

module.exports = {
// TODO: add references to all models here
Test: testModels.Test
Fighter: fighterModels.Fighter,
League: leagueModels.League,
Team: teamModels.Team,
};
25 changes: 25 additions & 0 deletions models/league.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

//LEAGUE SCHEMA
const LeagueSchema = new Schema ({
name: String,
established: Number,
headquarters: String,
owner: String
});

// var ufcLeague = new db.League ({
// name: "Ultimate Fighting Championship",
// established: 1993,
// headquarters: "Las Vegas",
// owner: "Danna White"
// })

//LEAGUE MODEL
const League = mongoose.model("League", LeagueSchema);

//MODULE EXPORT
module.exports = {
League: League
}
17 changes: 17 additions & 0 deletions models/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

//TEAM SCHEMA
const TeamSchema = new Schema ({
established: Number,
foundedBy: String,
facilities: String
});

//TEAM MODULE
const Team = mongoose.model('Team', TeamSchema);

//EXPORT MODULE
module.exports = {
Team: Team
}
30 changes: 17 additions & 13 deletions models/test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const TestSchema = new mongoose.Schema({
name: {
type: String,
required: true
//FIGHTER SCHEMA
const FighterSchema = new Schema ({
firstName: String,
lastName: String,
league: {
type: Schema.ObjectId,
ref: "League"
},
count: {
type: Number,
default: 42
titleHolder: Boolean,
country: String,
team: {
type: Schema.ObjectId,
ref: "Team"
},
time: {
type: Date,
default: Date.now
}
record: String
});

const Test = mongoose.model('Test', TestSchema);
//FIGHTER MODEL
const Fighter = mongoose.model('Fighter', FighterSchema);

module.exports = {
Test: Test
Fighter: Fighter
}
Loading