Skip to content

RESTFul API developed with Java and Spring Boot created to be used in a social network of watches to ask questions, share experiences and make comments.

Notifications You must be signed in to change notification settings

ChristianRL23/timetalk-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TimeTalk API

TimeTalk API is a RESTFul API created to be used in a social network to ask questions, share experiences and make comments.

Used technologies

  • Java 22
  • Spring Boot 3
  • Spring Security
  • JWT
  • JPA/Hibernate
  • MySQL
  • Docker

Docker

The API has been containerized using Docker. A Dockerfile and a docker-compose.yml file are included. Also, the image is available on DockerHub under the name christian471/timetalk-api.

Features

The features of the API are the next:

Endpoints

Create an account

  • Method: POST
  • Route: /api/v1/auth/signup
  • Description: Create a new account and obtain a JWT token. Follow the password best practices (minimum length of 8 characters, and use of a number) for security. Specify the role USER.
  • Request Body:
{
  "firstName": "Christian",
  "lastName": "Ramírez",
  "email": "[email protected]",
  "password": "mypasswordissecure123",
  "roleRequest": {
    "roleListName": [
      "USER"
    ]
  }
}
  • Response:
    • Status Code: 200
    • Response Body:
{
  "email": "[email protected]",
  "jwt": "JWT_TOKEN",
  "status": true,
  "message": "User created successfully"
}

Login

  • Method: POST
  • Route: /api/v1/auth/login
  • Description: Authenticate a user and obtain a JWT token.
  • Request Body:
{
  "email": "[email protected]",
  "password": "mypasswordissecure123"
}
  • Response:
    • Status Code: 200
    • Response Body:
{
  "email": "[email protected]",
  "jwt": "JWT_TOKEN",
  "status": true,
  "message": "User logged successfully."
}

Get all the posts

  • Method: GET
  • Route: /api/v1/posts
  • Description: Returns all available posts. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN
  • Response:
    • Status Code: 200
    • Response Body:
[
  {
      "id": 1,
      "author": {
        "firstName": "John",
        "lastName": "Doe"
      },
      "creationDate": "2024-10-08T08:00:51.492769",
      "title": "What do you think of dive watches?",
      "description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?",
      "likes": [],
      "comments": []
  },
  {
    "id": 2,
    "author": {
      "firstName": "John",
      "lastName": "Doe"
    },
    "creationDate": "2024-10-08T08:47:54.180589",
    "title": "What features do you value most in a watch?",
    "description": "I'm trying to decide what to look for in my next watch. Is it the design, the mechanism, or perhaps water resistance?",
    "likes": [
      {
        "user": {
          "firstName": "Christian",
          "lastName": "Ramírez"
        }
      }
    ],
    "comments": [
      {
        "author": {
          "firstName": "Christian",
          "lastName": "Ramírez"
        },
        "creationDate": "2024-10-08T08:48:50.231948",
        "content": "I personally prioritize the durability and water resistance. It's important for me to have a watch that can withstand everyday activities. What about others?"
      }
    ]
  }
] 

Create a new post

  • Method: POST
  • Route: /api/v1/posts
  • Description: Create a new post. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN
  • Request Body:
{
  "title": "What do you think of dive watches?",
  "description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?"
}
  • Response:
    • Status Code: 200
    • Response Body:
{
  "id": 1,
  "author": {
    "firstName": "Christian",
    "lastName": "Ramírez"
  },
  "creationDate": "2024-10-08T08:59:40.9176076",
  "title": "What do you think of dive watches?",
  "description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?",
  "likes": [],
  "comments": []
}

Update an existing post

  • Method: PUT
  • Route: /api/v1/posts/{post-id}
  • Description: Updates an existing post. The {post-id} parameter should be replaced with the ID of the post you want to update. Only the author of the post can access this endpoint. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN
  • Request Body:
{
  "title": "What features are essential for a dive watch?",
  "description": "I’m interested in getting a dive watch, but I'm curious about what features really matter. Is it just about water resistance, or should I consider other factors like visibility and durability?"
}
  • Response:
    • Status Code: 200
    • Response Body:
{
  "id": 2,
  "author": {
    "firstName": "Christian",
    "lastName": "Ramírez"
  },
  "creationDate": "2024-10-08T09:08:18.681976",
  "title": "What features are essential for a dive watch?",
  "description": "I’m interested in getting a dive watch, but I'm curious about what features really matter. Is it just about water resistance, or should I consider other factors like visibility and durability?",
  "likes": [],
  "comments": []
}

Delete a post

  • Method: DELETE
  • Route: /api/v1/posts/{post-id}
  • Description: Deletes an existing post. The {post-id} parameter should be replaced with the ID of the post you want to delete. Only the author of the post can access this endpoint. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN.
  • Request Body: None
  • Response:
    • Status Code: 204
    • Response Body: None

Comment a post

  • Method: POST
  • Route: /api/v1/posts/{post-id}/comments
  • Description: Add a comment to an existing post. The {post-id} parameter should be replaced with the ID of the post you want to comment. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN.
  • Request Body:
{
  "content": "I think visibility is crucial for a dive watch, especially in low-light conditions. A good bezel and clear markings can make a big difference underwater."
}
  • Response:
    • Status Code: 201
    • Response Body:
{
  "author": {
    "firstName": "Christian",
    "lastName": "Ramírez"
  },
  "creationDate": "2024-10-08T09:13:55.4522113",
  "content": "I think visibility is crucial for a dive watch, especially in low-light conditions. A good bezel and clear markings can make a big difference underwater."
}

Give like to a post

  • Method: POST
  • Route: /api/v1/posts/{post-id}/likes
  • Description: Add a like to an existing post. The {post-id} parameter should be replaced with the ID of the post you want to give a like. A user cannot like the same post more than once. The author of the post is not allowed to like their own post. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN.
  • Request Body: None
  • Response:
    • Status Code: 200
    • Response Body:
{
  "postId": 1,
  "totalLikes": 1
}

Remove like from a post

  • Method: DELETE

  • Route: /api/v1/posts/{post-id}/likes

  • Description: Remove a like from an existing post. The {post-id} parameter should be replaced with the ID of the post from which you want to remove the like. Only the user who previously liked the post can use this endpoint. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN.

  • Request Body: None

  • Response:

    • Status Code: 204
    • Response Body: None

Get basic user data

  • Method: GET
  • Route: /api/v1/users/profile
  • Description: Get first name and last name from the authenticated user. Only the authenticated user can access this endpoint. You must include a valid JWT in the Authorization header of the request. For example: Authorization: Bearer YOUR_JWT_TOKEN.
  • Request Body: None
  • Response:
    • Status Code: 200
    • Response Body:
{
  "firstName": "Christian",
  "lastName": "Ramírez"
}

About

RESTFul API developed with Java and Spring Boot created to be used in a social network of watches to ask questions, share experiences and make comments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published