Skip to content

amlane/artsy-be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Artsy API Documentation

BaseURL: https://artsy-be.herokuapp.com/api

A REST API using Node.js, Express, knex.js, and PostgresQL.
Authentication implemented using bcrypt and JSON web token.

Endpoints

Authentication

POST - Register a new user

Endpoint: /auth/register
Requires an object with an email, password and username:

{
  "email": "[email protected]",
  "password": "password",
  "username": "amanda"
}

When successful will return status code of 201 (CREATED), the new user object and a token (example):

{
  "newUser": {
    "id": 2,
    "username": "amanda",
    "email": "[email protected]",
    "created_at": "2019-11-24 22:30:29",
    "avatar_url": "https://static.wixstat...",
    "location": null,
    "about": "Share your story about your art."
  },
  "token": "eyJhbGciOiJ..."
}
POST - Login an existing user

Endpoint: /auth/login
Requires an object with a valid email and password:

{
  "email": "[email protected]",
  "password": "password"
}

When successful will return status code of 201 (CREATED), the new user object and a token (example):

{
  "user": {
    "id": 2,
    "username": "amanda",
    "email": "[email protected]",
    "created_at": "2019-11-24 22:30:29",
    "avatar_url": "https://static.wixstat...",
    "location": null,
    "about": "Share your story about your art."
  },
  "token": "eyJhbGciOiJ..."
}

User

GET - Get all users

Endpoint: /users
No token or request body required.

When successful will return status code of 200 (OK) and an array of users.

[
  {
    "id": 1,
    "username": "testuser",
    "email": "[email protected]",
    "created_at": "2019-11-24 22:02:30",
    "avatar_url": "https://static.wixs...",
    "location": null,
    "about": "Share your story about your art."
  },
  {
    "id": 2,
    "username": "amanda",
    "email": "[email protected]",
    "created_at": "2019-11-24 22:30:29",
    "avatar_url": "https://static.wixs...",
    "location": null,
    "about": "Share your story about your art."
  }
]
GET - Get a single user by ID

Endpoint: /users/:id (Example: "BaseURL/users/2")
No token or request body required.

When successful will return status code of 200 (OK) and the user in an object. The user by id endpoint includes the user's bio info, as well as their array of photos, favorites, and followers.

{
  "user": {
    "id": 1,
    "username": "testuser",
    "email": "[email protected]",
    "created_at": "2019-11-24 22:02:30",
    "avatar_url": "https://static.wixs...",
    "location": null,
    "about": "Share your story about your art.",
    "photos": [
      {
        "id": 1,
        "photo_url": "www.coolphoto.com",
        "title": "cool title",
        "description": null,
        "created_at": "2019-11-24 22:04:00",
        "user_id": 1,
        "likes": 0
      }
    ],
    "favorites": [],
    "followers": []
  }
}
PUT - Edit User Bio

Endpoint: /users/:id (Example: "BaseURL/users/2")
Authorization token required in headers. Only the user is authorized to update their own bio.
Requires a request body with the updated changes. Please see Data model portion of this documentation for required fields. Here is an example:

{
  "location": "Como",
  "about": "Share your story about your art.",
  "username": "Amanda"
}

When successful will return status code of 201 (CREATED) and the updated user object:

{
  "id": 1,
  "username": "Amanda",
  "email": "[email protected]",
  "created_at": "2019-11-24 22:02:30",
  "avatar_url": "https://static.wixs...",
  "location": "Como",
  "about": "Share your story about your art."
}
DELETE - Delete User by ID

Endpoint: /users/:id (Example: "BaseURL/users/2")
Authorization token required in headers. Only the user can delete their own account.
No request body required.

When successful will return status code of 200 (OK) and a success message.

{
  "message": "1 record deleted"
}

Photos

GET - Get all photos

Endpoint: /photos
No token or request body required.

When successful will return status code of 200 (OK) and the photos array. The get all photos endpoint includes the photos details, as well as the count for likes and comments.

{
  "photos": [
    {
      "id": 2,
      "photo_url": "www.phyoto.com",
      "title": "cool yolo photo",
      "description": "I forgot the details...",
      "created_at": "2019-11-24 23:27:55",
      "user_id": 8,
      "username": "Amanda",
      "avatar_url": "https://static.wixs...",
      "likes": 0,
      "comments": 0
    },
    {
      "id": 5,
      "photo_url": "www.phyoto.com",
      "title": "this is the coolest photo everrrrr",
      "description": "Here is an updated description?",
      "created_at": "2019-11-24 23:52:14",
      "user_id": 9,
      "username": "amandalane",
      "avatar_url": "https://static.wixs...",
      "likes": 0,
      "comments": 0
    }
  ]
}
GET - Get a single photo by ID

Endpoint: /photos/:id (Example: "BaseURL/photos/27")
No token or request body required.

When successful will return status code of 200 (OK) and the photo object. The photo by id endpoint includes the photo details as well as the likes (count and list of users), and array of comments.

{
  "photo": {
    "id": 2,
    "photo_url": "www.phyoto.com",
    "title": "cool yolo photo",
    "description": "I forgot the details...",
    "created_at": "2019-11-24 23:27:55",
    "user_id": 8,
    "username": "Amanda",
    "avatar_url": "https://static.wixs...",
    "likes": {
      "count": 0,
      "list": []
    },
    "comments": []
  }
}
POST - Add a new photo post

Endpoint: /photos
Authorization token required in headers. This is how the user's id is assigned to their post.
Requires a request body with the post info. Please see Data model portion of this documentation for required fields. Here is an example:

{
  "photo_url": "www.phyoto.com",
  "title": "cool yolo photo"
}

When successful will return status code of 201 (CREATED) and the new photo object:

{
  "newPhoto": {
    "id": 2,
    "photo_url": "www.phyoto.com",
    "title": "cool yolo photo",
    "description": null,
    "created_at": "2019-11-24 23:27:55",
    "user_id": 8,
    "username": "Amanda",
    "avatar_url": "https://static.wixs...",
    "likes": {
      "count": 0,
      "list": []
    }
  }
}
PUT - Edit Photo by ID

Endpoint: /photos/:id (Example: "BaseURL/photos/2")
Authorization token required in headers. Only the user is authorized to edit their own posts.
Requires a request body with the updated changes. Please see Data model portion of this documentation for required fields. Here is an example:

{
  "description": "Here is an updated description"
}

When successful will return status code of 201 (CREATED) and the updated user object:

{
  "id": 3,
  "photo_url": "www.phyoto.com",
  "title": "cool yolo photo",
  "description": "Here is an updated description",
  "created_at": "2019-11-24 23:38:30",
  "user_id": 9,
  "username": "amandalane",
  "avatar_url": "https://static.wixs...",
  "likes": {
    "count": 0,
    "list": []
  }
}
DELETE - Delete Photo by ID

Endpoint: /photos/:id (Example: "BaseURL/photos/2")
Authorization token required in headers. Only the user is authorized to delete their own posts.
No request body required.

When successful will return status code of 200 (OK) and a success message:

{
  "message": "Photo deleted."
}

Likes

POST - Like a photo by photo ID

Endpoint: /photos/:id/like (Example: "BaseURL/photos/2/like")
Authorization token required in headers. This is how the user_id is set. The id in the params is what sets the photo_id.
No request body required.

When successful will return status code of 200 (OK) and a list of all the posts and their updated likes:

{
  "photos": [
    {
      "id": 2,
      "photo_url": "www.phyoto.com",
      "title": "cool yolo photo",
      "description": "I forgot the details...",
      "created_at": "2019-11-24 23:27:55",
      "user_id": 8,
      "username": "Amanda",
      "avatar_url": "https://static.wixstatic.com/media/4151a5_7706b6198d164a3e947f4548166228ad~mv2.png",
      "likes": 1
    },
    {
      "id": 7,
      "photo_url": "www.phyoto.com",
      "title": "this is the coolest photo everrrrr",
      "description": null,
      "created_at": "2019-11-25 02:39:44",
      "user_id": 9,
      "username": "amandalane",
      "avatar_url": "https://static.wixstatic.com/media/4151a5_7706b6198d164a3e947f4548166228ad~mv2.png",
      "likes": 1
    }
  ]
}
DELETE - Unlike a photo by photo ID

Endpoint: /photos/:id/unlike (Example: "BaseURL/photos/2/unlike")
Authorization token required in headers. This is how the user_id is set. The id in the params is what sets the photo_id.
No request body required.

When successful will return status code of 200 (OK) and a list of all the posts and their updated likes:

{
  "photos": [
    {
      "id": 2,
      "photo_url": "www.phyoto.com",
      "title": "cool yolo photo",
      "description": "I forgot the details...",
      "created_at": "2019-11-24 23:27:55",
      "user_id": 8,
      "username": "Amanda",
      "avatar_url": "https://static.wixstatic.com/media/4151a5_7706b6198d164a3e947f4548166228ad~mv2.png",
      "likes": 1
    },
    {
      "id": 7,
      "photo_url": "www.phyoto.com",
      "title": "this is the coolest photo everrrrr",
      "description": null,
      "created_at": "2019-11-25 02:39:44",
      "user_id": 9,
      "username": "amandalane",
      "avatar_url": "https://static.wixstatic.com/media/4151a5_7706b6198d164a3e947f4548166228ad~mv2.png",
      "likes": 1
    }
  ]
}

Followers

POST - Follow a user by user ID

Endpoint: /follow/:id (Example: "BaseURL/follow/2")
Authorization token required in headers. This is how the follower_id is set. The id in the params is what sets the artist_id.
No request body required.

When successful will return status code of 200 (OK) and a list of all the artists the user follows:

{
  "friends": [
    {
      "created_at": "2019-11-25 02:49:36",
      "id": 5,
      "username": "amandalane",
      "email": "[email protected]",
      "avatar_url": "https://static.wixs...",
      "location": null
    }
  ]
}
DELETE - Unfollow a user by user ID

Endpoint: /follow/:id (Example: "BaseURL/follow/3")
Authorization token required in headers. This is how the follower_id is set. The id in the params is what sets the artist_id.
No request body required.

When successful will return status code of 200 (OK) and a list of all the artists the user follows:

{
  "followers": []
}

Comments

POST - Add a new comment by photo id

Endpoint: /comments/:id (Example: "BaseURL/comments/38")
Authorization token required in headers. This is how the user_id is set. The params id is what sets the photo_id.
Requires a request body with the post info. Please see Data model portion of this documentation for required fields. Here is an example:

{
  "content": "Whoa that's really cool artwork!"
}

When successful will return status code of 201 (CREATED) and the new comment object:

{
  "newComment": {
    "id": 3,
    "content": "Whoa that's really cool artwork!",
    "created_at": "2019-11-25 03:00:41",
    "photo_id": 2,
    "user_id": 10
  }
}
PUT - Edit Comment by ID

Endpoint: /comments/:id (Example: "BaseURL/comments/2")
Authorization token required in headers. Only the user is authorized to edit their own comments.
Requires a request body with the updated changes. Please see Data model portion of this documentation for required fields. Here is an example:

{
  "description": "Here is an updated description"
}

When successful will return status code of 201 (CREATED) and a message of number of records updated:

{
  "updatedComment": 0
}
DELETE - Delete Comment by ID

Endpoint: /comments/:id (Example: "BaseURL/comments/24")
Authorization token required in headers. Only the user is authorized to delete their own comments.
No request body required.

When successful will return status code of 200 (OK) and a success message:

{
  "message": "Comment deleted."
}

Data Model

USERS


{
  id: INT, primary key
  username: STRING, non-nullable
  email: STRING, non-nullable
  password: STRING, non-nullable
  created_at: TIMESTAMP
  avatar_url: STRING, defaults
  location: STRING
  about: STRING, defaults
}

PHOTOS


{
  id: INT, primary key
  photo_url: STRING, non-nullable
  title: STRING, non-nullable
  description: STRING
  created_at: TIMESTAMP
  user_id: INT, foreign key for user table
}

LIKES


{
  user_id: INT, foreign key for user table,
  photo_id: INT, foreign key for photo table
}

FOLLOWERS


{
  artist_id: INT, foreign key for user table,
  follower_id: INT, foreign key for user table
}

COMMENTS


{
  id: INT, primary key
  content: STRING, non-nullable
  created_at: TIMESTAMP
  photo_id: INT, foreign key for photo table
  user_id: INT, foreign key for user table
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •