Skip to content

build-week-ptct-nov-2019-dadjokes/backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dad Jokes v1.0.0

Dad Jokes API for PTCT Build Week, November 2019, deployed at https://lambda-dad-jokes.herokuapp.com

Auth

Logs in a registered user

Back to top

Log an user in, receive token on successful login

POST /api/auth/login

Parameter Parameters

Name Type Description
username String

The User's username

password String

The User's password

Param Examples

(json) Sample-Request:

{
    "username": "johndoe",
    "password": "123456"
}

Success Response

Success-Response:

{
    "message": "Welcome back johndoe!",
    "token": "Generated Token"
}

200

Name Type Description
message json

Welcome Message

Error Response

Error-Response:

{
    "username": "Required"
}

Error-Response:

{
    "code": 404,
    "error": "User Not Found"
}

Error-Response:

{
    "code": 401,
    "error": "Invalid Credentials"
}

Registers a New User

Back to top

Registers a New User to the Database

POST /api/auth/register

Parameter Parameters

Name Type Description
email String

The User's Email

username String

The User's Username

password String

The User's Password

Param Examples

(json) Sample-Request:

{
    "email": "john@doe.com",
    "username": "johndoe",
    "password": "123456"
}

Success Response

Success-Response:

{
    "message": "Welcome to Dad Jokes johndoe"
}

201

Name Type Description
message json

Welcome Message

Error Response

Error-Response:

{
    "username": "Required"
}

Error-Response:

{
    "code": 400,
    "error": "Username is already taken"
}

Error-Response:

{
    "code": 400,
    "error": "Email is already taken"
}

Jokes

Deletes the Joke with the Provided Id

Back to top

Delete the Joke with the Provided Id

DELETE /api/jokes/:id

Parameter Parameters

Name Type Description
id Integer

The Id of the joke, passed in the URL

Success Response

Success-Response:

7

200

Name Type Description
joke json

The Updated Joke

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

Error-Response:

{
  "message": "Your DAD Joke was not found"
}

Error-Response:

{
  "message": "You may only DELETE your own jokes"
}

Get All Public and Private Jokes in the Database

Back to top

Get All Public and Private Jokes in the Database

GET /api/jokes

Success Response

Success-Response:

[
  {
     "id": 1,
     "joke": "Today, my son asked \"Can I have a book mark?\" and I burst into tears.",
     "punchline": "11 years old and he still doesn't know my name is Brian",
     "created_by": 1,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
  {
     "id": 2,
     "joke": "My wife is really mad at the fact that I have no sense of direction.",
     "punchline": "So I packed up my stuff and right.",
     "created_by": 2,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
  {
     "id": 3,
     "joke": "How do you make holy water?",
     "punchline": "You boil the hell out of it.",
     "created_by": 1,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
]

200

Name Type Description
AllJokes json[]

All the Public and Private Jokes

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

Get All Public Jokes in the Database

Back to top

Get All Public Jokes in the Database

GET /api/jokes/public

Success Response

Success-Response:

[
  {
     "id": 1,
     "joke": "Today, my son asked \"Can I have a book mark?\" and I burst into tears.",
     "punchline": "11 years old and he still doesn't know my name is Brian",
     "created_by": 1,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
  {
     "id": 2,
     "joke": "My wife is really mad at the fact that I have no sense of direction.",
     "punchline": "So I packed up my stuff and right.",
     "created_by": 2,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
  {
     "id": 3,
     "joke": "How do you make holy water?",
     "punchline": "You boil the hell out of it.",
     "created_by": 1,
     "privateJoke": false,
     "created_at": "2019-11-18T00:51:52.515Z",
     "updated_at": "2019-11-18T00:51:52.515Z"
   },
]

200

Name Type Description
PublicJokes json[]

All the Public Jokes

Add Joke To the Database

Back to top

Add Joke To the Database

POST /api/jokes

Parameter Parameters

Name Type Description
joke String

The joke.

punchline String

The punchline of the Joke

privateJoke Boolean

Is the Joke Private?

Param Examples

(json) Sample-Request:

{
	"joke": "Why did the developer cross the road?",
	"punchline": "The code was cleaner on the other side.",
	"privateJoke": true
}

Success Response

Success-Response:

{
  "id": 7,
  "joke": "Why did the developer cross the road?",
  "punchline": "The code was cleaner on the other side.",
  "created_by": 5,
  "privateJoke": true,
  "created_at": "2019-11-18T01:58:29.354Z",
  "updated_at": "2019-11-18T01:58:29.354Z"
}

201

Name Type Description
Joke json

The newly created Joke

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

Update the Joke with the Provided Id

Back to top

Update the Joke with the Provided Id

PUT /api/jokes/:id

Parameter Parameters

Name Type Description
id Integer

The Id of the joke, passed in the URL

joke String

The joke.

punchline String

The punchline of the Joke

privateJoke Boolean

Is the Joke Private?

Param Examples

(json) Sample-Request:

{
	"privateJoke": false
}

Success Response

Success-Response:

{
  "id": 7,
  "joke": "Why did the developer cross the road?",
  "punchline": "The code was cleaner on the other side.",
  "created_by": 5,
  "privateJoke": false,
  "created_at": "2019-11-18T01:58:29.354Z",
  "updated_at": "2019-11-18T01:58:29.354Z"
}

200

Name Type Description
joke json

The Updated Joke

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

Error-Response:

{
  "message": "Your DAD Joke was not found"
}

Error-Response:

{
  "message": "You may only EDIT your own jokes"
}

User

Deletes the User

Back to top

Delete's the User based on the provided token

DELETE /api/user

Success Response

Success-Response:

6

200

Name Type Description
Return json

the ID of the User Deleted

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

Updates the User with provided information

Back to top

Updates the User with provided information

PUT /api/user

Parameter Parameters

Name Type Description
email String

The User's Email

username String

The User's Username

password String

The User's Password

Param Examples

(json) Sample-Request:

{
    "username": "johndoe2",
}

Success Response

Success-Response:

{
   "id": 6,
   "email": "john@doe.com",
   "username": "johndoe2",
   "created_at": "2019-11-18T20:52:38.944Z",
   "updated_at": "2019-11-18T20:52:38.944Z"
}

200

Name Type Description
user json

The Updated User

Error Response

Error-Response:

{
  "message": "YOU SHALL NOT PASS"
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published