forked from r-spacex/SpaceX-API
-
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.
Add fairing model + route for r-spacex#594
- Loading branch information
1 parent
0aa8efd
commit 797a974
Showing
11 changed files
with
411 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Get all fairings | ||
|
||
**Method** : `GET` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings` | ||
|
||
**Auth required** : `False` | ||
|
||
## Success Responses | ||
|
||
**Code** : `200 OK` | ||
|
||
```json | ||
[ | ||
{ | ||
"serial": "ff13b75ee72046ea8b00e9f4ac242f0b", | ||
"version": "2.1", | ||
"status": "active", | ||
"reuse_count": 3, | ||
"net_landing_attempts": 2, | ||
"net_landing": 1, | ||
"water_landing_attempts": 1, | ||
"water_landing": 1, | ||
"last_update": "2020-12-20T21:01:14.606Z", | ||
"launches": [ | ||
"e7ba84e6294145a1bec0b684a6ca9aa6", | ||
"9daa1cebfedc41199e9ef5747d17d5c4", | ||
"9120aff3571e4af18dba1021dac4dfdd" | ||
] | ||
} | ||
... | ||
] | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Create a fairing | ||
|
||
**Method** : `POST` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings` | ||
|
||
**Auth required** : `True` | ||
|
||
**Body** : | ||
|
||
```json | ||
{ | ||
"serial": "ff13b75ee72046ea8b00e9f4ac242f0b", | ||
"version": "2.1", | ||
"status": "active", | ||
"reuse_count": 3, | ||
"net_landing_attempts": 2, | ||
"net_landing": 1, | ||
"water_landing_attempts": 1, | ||
"water_landing": 1, | ||
"last_update": "2020-12-20T21:01:14.606Z", | ||
} | ||
``` | ||
|
||
## Success Response | ||
|
||
**Code** : `201 Created` | ||
|
||
**Content example** : `Created` | ||
|
||
## Error Responses | ||
|
||
**Code** : `400 Bad Request` | ||
|
||
**Content** : Mongoose error is shown, with suggestions to fix the query. |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Delete a fairing | ||
|
||
**Method** : `DELETE` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings/:id` | ||
|
||
**URL Parameters** : `id=[string]` where `id` is the ID of the fairing | ||
|
||
**Auth required** : `True` | ||
|
||
## Success Response | ||
|
||
**Code** : `200 OK` | ||
|
||
**Content example** : `OK` | ||
|
||
## Error Responses | ||
|
||
**Code** : `400 Bad Request` | ||
|
||
**Content** : Mongoose error is shown, with suggestions to fix the query. |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Get one fairing | ||
|
||
**Method** : `GET` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings/:id` | ||
|
||
**URL Parameters** : `id=[string]` where `id` is the ID of the fairing | ||
|
||
**Auth required** : `False` | ||
|
||
## Success Response | ||
|
||
**Code** : `200 OK` | ||
|
||
**Content example** : | ||
|
||
```json | ||
{ | ||
"serial": "ff13b75ee72046ea8b00e9f4ac242f0b", | ||
"version": "2.1", | ||
"status": "active", | ||
"reuse_count": 3, | ||
"net_landing_attempts": 2, | ||
"net_landing": 1, | ||
"water_landing_attempts": 1, | ||
"water_landing": 1, | ||
"last_update": "2020-12-20T21:01:14.606Z", | ||
"launches": [ | ||
"e7ba84e6294145a1bec0b684a6ca9aa6", | ||
"9daa1cebfedc41199e9ef5747d17d5c4", | ||
"9120aff3571e4af18dba1021dac4dfdd" | ||
] | ||
} | ||
``` | ||
|
||
## Error Responses | ||
|
||
**Code** : `404 NOT FOUND` | ||
|
||
**Content** : `Not Found` |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Query fairings | ||
|
||
**Method** : `POST` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings/query` | ||
|
||
**Auth required** : `False` | ||
|
||
**Body** : | ||
|
||
See [query](../queries.md) guide for more details on building queries and paginating results. | ||
|
||
```json | ||
{ | ||
"query": {}, | ||
"options": {} | ||
} | ||
``` | ||
|
||
## Success Response | ||
|
||
**Code** : `200 OK` | ||
|
||
**Content example** : | ||
|
||
```json | ||
{ | ||
"docs": [ | ||
{ | ||
"serial": "ff13b75ee72046ea8b00e9f4ac242f0b", | ||
"version": "2.1", | ||
"status": "active", | ||
"reuse_count": 3, | ||
"net_landing_attempts": 2, | ||
"net_landing": 1, | ||
"water_landing_attempts": 1, | ||
"water_landing": 1, | ||
"last_update": "2020-12-20T21:01:14.606Z", | ||
"launches": [ | ||
"e7ba84e6294145a1bec0b684a6ca9aa6", | ||
"9daa1cebfedc41199e9ef5747d17d5c4", | ||
"9120aff3571e4af18dba1021dac4dfdd" | ||
] | ||
} | ||
... | ||
], | ||
"totalDocs": 7, | ||
"offset": 0, | ||
"limit": 10, | ||
"totalPages": 1, | ||
"page": 1, | ||
"pagingCounter": 1, | ||
"hasPrevPage": false, | ||
"hasNextPage": false, | ||
"prevPage": null, | ||
"nextPage": null | ||
} | ||
``` | ||
|
||
## Error Responses | ||
|
||
**Code** : `400 Bad Request` | ||
|
||
**Content** : Mongoose error is shown, with suggestions to fix the query. |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Fairing Schema | ||
|
||
```json | ||
{ | ||
"serial": { | ||
"type": "String", | ||
"unique": true, | ||
"required": true, | ||
}, | ||
"version": { | ||
"enum": ["1.0", "2.0", "2.1"], | ||
"default": null, | ||
}, | ||
"status": { | ||
"type": "String", | ||
"enum": ["active", "inactive", "unknown", "expended", "lost", "retired"], | ||
"required": true, | ||
}, | ||
"reuse_count": { | ||
"type": "Number", | ||
"default": 0, | ||
}, | ||
"net_landing_attempts": { | ||
"type": "Number", | ||
"default": 0, | ||
}, | ||
"net_landing": { | ||
"type": "Number", | ||
"default": 0, | ||
}, | ||
"water_landing_attempts": { | ||
"type": "Number", | ||
"default": 0, | ||
}, | ||
"water_landing": { | ||
"type": "Number", | ||
"default": 0, | ||
}, | ||
"last_update": { | ||
"type": "String", | ||
"default": null, | ||
}, | ||
"launches": [{ | ||
"type": "UUID", | ||
}], | ||
} | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Update a fairing | ||
|
||
**Method** : `PATCH` | ||
|
||
**URL** : `https://api.spacexdata.com/v4/fairings/:id` | ||
|
||
**URL Parameters** : `id=[string]` where `id` is the ID of the fairing | ||
|
||
**Auth required** : `True` | ||
|
||
**Body** : | ||
|
||
```json | ||
{ | ||
"reuse_count": 3, | ||
} | ||
``` | ||
|
||
## Success Response | ||
|
||
**Code** : `200 OK` | ||
|
||
**Content example** : `OK` | ||
|
||
## Error Responses | ||
|
||
**Code** : `400 Bad Request` | ||
|
||
**Content** : Mongoose error is shown, with suggestions to fix the query. |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const mongoose = require('mongoose'); | ||
const mongoosePaginate = require('mongoose-paginate-v2'); | ||
const idPlugin = require('mongoose-id'); | ||
|
||
const fairingSchema = new mongoose.Schema({ | ||
serial: { | ||
type: String, | ||
unique: true, | ||
required: true, | ||
}, | ||
version: { | ||
type: String, | ||
enum: ['1.0', '2.0', '2.1'], | ||
required: true, | ||
}, | ||
status: { | ||
type: String, | ||
enum: ['active', 'inactive', 'unknown', 'expended', 'lost', 'retired'], | ||
required: true, | ||
}, | ||
reuse_count: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
net_landing_attempts: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
net_landing: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
water_landing_attempts: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
water_landing: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
last_update: { | ||
type: String, | ||
default: null, | ||
}, | ||
launches: [{ | ||
type: mongoose.ObjectId, | ||
ref: 'Launch', | ||
}], | ||
}, { autoCreate: true }); | ||
|
||
fairingSchema.plugin(mongoosePaginate); | ||
fairingSchema.plugin(idPlugin); | ||
|
||
const Fairing = mongoose.model('Fairing', fairingSchema); | ||
|
||
module.exports = Fairing; |
Oops, something went wrong.