Skip to content

Repository files navigation

Nest Logo

Memories API - Nest.js + Typescript + Prisma + PostgreSQL /p>

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

RestAPI

  • The application will run at 8080, you can chnage the port from ./src/main.ts
  • This is a short documentation for the all routes handled.
  • The errors are handled - More infos will be added to the documentation later.

Authentication : /auth/


Register a new account

POST /auth/register

{
  # all fields are required
  "email":"tony@thesopranos.com",
  "username":"tony",
  "password":"tony123"
}

Response

Status: 201 CREATED

{
  "access_token": "jwt_token",
  "refresh_token": "jwt_token"
}

Signin

GET /auth/signin

{
  # all fields are required
  "email":"tony@thesopranos.com",
  "password":"tony123"
}

Response

Status: 200 OK

{
  "access_token": "jwt_token",
  "refresh_token": "jwt_token"
}

Logout

POST /auth/logout

# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "message": "Logged out!"
}

Refresh tokens

POST /auth/refresh

# Authorization header(Bearer) required. (refresh_token)

Response

Status: 200 OK

{
  "access_token": "jwt_token",
  "refresh_token": "jwt_token"
}

Memories : /memories/


Get all memories

GET /memories/

Response

Status: 200 OK

# array of memories
[
  {
    "memorieId": "",
    "title": "",
    "description": "",
    "image": "",
    # array of strings
    "hashtags": [],
    "ownerId": "",
    "owner": {
        "email": "",
        "username": "",
        "profile": {
            "image": "",
            "bio": "",
            "name": ""
        }
    },
    "_count": {
        "comments": 0 , # number of comments
        "likedBy": 2    # number of likes
    }
  }
]

Create a new memorie

POST /memories

# Authorization header(Bearer) required. (access_token)
{
  # all fields are required
  "title":"New memorie",
  "description":"This is a description!",
  "image":"image_link",
  "hashtags":["afc","pl"]
}

Response

Status: 201 CREATED

{
  "memorieId": "",
  "title": "New memorie",
  "description": "This is the description!!",
  "image": "",
  "hashtags": ["afc", "pl"],
  "ownerId": ""
}

Get detailed informations of a single memorie

GET /memories/:id

# id (valid uuid ) required

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": "",
  "owner": {
      "userId": "",
      "email": "",
      "username": "",
      "profile": {
          "image": "",
          "bio": "",
          "name": ""
      }
  },
  "comments": [ # array of comments
    {
      "commentId": "",
      "title": "",
      "content": "",
      "authorId": "",
      "memorieId": ""
    }
  ],
  "likedBy": [ # array of users who liked the memorie
    {
      "userId": "",
      "username": "",
      "profile": {
          "image": ""
      }
    }
  ]
}

Update an existing memorie

PUT /memories/:id

# id (valid uuid ) required
# Authorization header(Bearer) required. (access_token)
{
  # all fields are required
  "title":"",
  "description":"",
  "image":"",
  "hashtags":[]
}

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Delete a memorie

DELETE /memories/:id

# id (valid uuid ) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Like a memorie

POST /memories/:id/like

# id (valid uuid ) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Unlike a memorie (Remove like)

DELETE /memories/:id/like

# id (valid uuid ) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Create a new comment

POST /memories/:id/comments

# id (valid uuid ) is required. (id of the memorie)
# Authorization header(Bearer) required. (access_token)
{
  # all fields are required
  "title":"",
  "content":""
}

Response

Status: 201 CREATED

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Delete a comment

DELETE /memories/:id/comments/:commentId

# id (valid uuid ) is required. (id of the memorie)
# commentId (valid uuid ) is also required.
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "memorieId": "",
  "title": "",
  "description": "",
  "image": "",
  "hashtags": [],
  "ownerId": ""
}

Authenticated user: /me/

Get informations about the current user

Get /me/

# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  "userId": "",
  "email": "",
  "username": "",
  "profile": {
      "bio": "",
      "image": "",
      "name": ""
  },
  # array of liked memories
  "likedMemories": [],
  # array of current user's memories
  "memories": [],
  # array of users who follow the current user
  "followers": [],
  # array of users whom the current user follow
  "following": []
}

Get memories of the current user

Get /me/

# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

[
  {
    "memorieId": "",
    "title": "",
    "description": "",
    "image": "",
    "hashtags": [],
    "ownerId": ""
  }
]

Update user's profile

  • Update an exisiting profile, or create one if it doesn't exist.

PUT /me/profile

# Authorization header(Bearer) required. (access_token)
{
  "name": "",
  "bio": "",
  "image": ""
}

Response

Status: 200 OK

{
  "profileId": "",
  "name": "",
  "bio": "",
  "image": "",
  "userId": ""
}

Get current user's followers

GET /me/followers

# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

[
  # array of users
]

Remove a follower

DELETE /me/followers/:id

# id (valid uuid) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  # follower(user) removed
}

Get current user's following

GET /me/following

# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

[
  # array of users
]

Follow a user

POST /me/following/:id

# id (valid uuid) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  # user followed
}

Unfollow a user

DELETE /me/following/:id

# id (valid uuid) required
# Authorization header(Bearer) required. (access_token)

Response

Status: 200 OK

{
  # user unfollowed
}

Stay in touch

About

A documented Nest.js API for social media application. Users can create accounts, share their memories, follow each other and moore!

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages