Skip to content

LozziKit/microservice-discussions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discussions microservice - LozziKit

Introduction

This microservice has been developed as part of the course AMT from the HEIG-VD (HES-SO) swiss university.

This service helps you to deploy a discussion system service. Once the server has been started, it exposes some REST endpoints your frontend can request to comment, react or retrieve all of the comments of a particular articleID you define yourself.

Basic ideas

You have developed an app or a website and you want to add some kind of interaction between the users you have. You are dealing with user authorization with JWTs (JSON Web Token) - maybe using the User and Team microservice from Lozzikit. (https://github.com/LozziKit/microservice-users-and-teams) - and now want the user to be able to comment on some of the pages of your app.

Commenting

With this service, your user will be able to comment on a specific page or article, defined by an integer articleID. When a user wants to comment a specific article, he will POST to the /comments endpoints, with the articleID as a parameter. The fact that it is the first comment or not does not make any difference: you don't have to deal with article creation.

Reacting

A user can react to a comment that has been already posted. For now, this service only handle upvotes, but is ready to handle more (like "dislike", "angry", etc.). When a user wants to react to a comment, the ID of the comment is passed as a path parameter when doing a POST to the comments/{id}/reactions endpoint. The user can DELETE some of the reactions he has made too.

Authorization

This service uses JWTs to let a user comment, react or modify a comment he has already posted. The JWT has to be within the Authorization HTTP header, as a Bearer token. The payload of a minimal JWT has to look like this:

{
  "sub": "remij1", // The username
  "userID": "4" // The userID
}

The username will be used to display an author's name, but the user is really defined by the userID.

How to deploy

Docker has been used to deploy this app easily. For more informations about its installation and execution, please follow https://www.docker.com/.

Once Docker has been installed, clone this repo and go to the /docker folder. From there, execute this command:

docker-compose up --build

Everything should now be up and running, including the server exposing the REST endpoints and the database persisting the comments.

Using Docker for Windows: you will have to use the Docker Quickstart Terminal for the docker-compose up to work properly.

Using it on linux or Mac OS: you will have to change the IP of the database from the code and recompile the whole project. You will have to modify the file located at /swagger/spring-server/src/main/resources/application.properties like so:

Before

spring.datasource.url = jdbc:mysql://192.168.99.100:3306/microservice-discussions?useSSL=false 

After

spring.datasource.url = jdbc:mysql://localhost:3306/microservice-discussions?useSSL=false 

REST API

Before cloning this repo, you may want to check all of the endpoints this server exposes. Theses are defined publicly here: https://app.swaggerhub.com/apis/HEIG-VD/microservice-discussion_api/0.0.1#/

It mainly exposes these endpoints:

  • /comments: used to POST, DELETE, PUT or GET comments.
  • /comments/{id}/reactions: used to POST, DELETE or GET reactions for a specific comment.

Bugs

When deleting a reaction, we receive the expeted response (the new number of reactions). But if we get the comment where the reaction has supposedly been deleted, we see, in fact, that the reaction is still there. The process to get the number of reactions with a GET to the /comments/{id}/reactions endpoint is the same as the one used to send a response when we send a DELETE to the same endpoint.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published