Skip to content

Commit

Permalink
Add fairing model + route for r-spacex#594
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Dec 20, 2020
1 parent 0aa8efd commit 797a974
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/v4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ Detailed info about launch payloads
* 🔒 [Update a payload](payloads/update.md) : `PATCH /payloads/:id`
* 🔒 [Delete a payload](payloads/delete.md) : `DELETE /payloads/:id`

### Fairings - [Schema](fairings/schema.md)

Detailed info on SpaceX fairings

* [Get all fairings](fairings/all.md) : `GET /fairings`
* [Get one fairing](fairings/one.md) : `GET /fairings/:id`
* [Query fairings](fairings/query.md) : `POST /fairings/query`
* 🔒 [Create a fairing](fairings/create.md) : `POST /fairings`
* 🔒 [Update a fairing](fairings/update.md) : `PATCH /fairings/:id`
* 🔒 [Delete a fairing](fairings/delete.md) : `DELETE /fairings/:id`

### Roadster info - [Schema](roadster/schema.md)

Detailed info about Elon's Tesla roadster's current position
Expand Down
33 changes: 33 additions & 0 deletions docs/v4/fairings/all.md
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"
]
}
...
]
```
35 changes: 35 additions & 0 deletions docs/v4/fairings/create.md
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.
21 changes: 21 additions & 0 deletions docs/v4/fairings/delete.md
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.
40 changes: 40 additions & 0 deletions docs/v4/fairings/one.md
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`
64 changes: 64 additions & 0 deletions docs/v4/fairings/query.md
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.
47 changes: 47 additions & 0 deletions docs/v4/fairings/schema.md
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",
}],
}
```
29 changes: 29 additions & 0 deletions docs/v4/fairings/update.md
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.
56 changes: 56 additions & 0 deletions services/v4/fairings/model.js
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;
Loading

0 comments on commit 797a974

Please sign in to comment.