Skip to content

Latest commit

 

History

History
93 lines (83 loc) · 2.66 KB

README.md

File metadata and controls

93 lines (83 loc) · 2.66 KB

Question And Answer GitHub

This is an exercise. This is a backend side of a system called QuestionsAndAnswers. It is similar to Quora/Stackoverflow and others with 1 major difference. It only allow 1 answer per question. If someone thinks they have a better answer, they will have to update the existing answer for that particular question instead of adding another answer.

Install

docker-compose up -d

Once running, the application will be available on localhost:8080.

API

Organization

The data used in this API is organized as follows:

Question

{
  "id": 1,
  "title": "How to exit from vim?",
  "body": "I hear Vim is a very respected editor. So I was willing to try it out, but not I am not able to exit from it. And if I kill the process, the content of the file gets lost. What should I do?",
  "user_id": 1
}

Answer

{
  "id": 1,
  "body": "In order to exit Vim, type ':q'. If you want to save before exiting, type ':wq'.!",
  "user_id": 1,
  "question_id": 1
}

User

{
    "id": 1,
    "username": "user"
}

QnA

{
  "question": {
    "id": 1,
    "title": "How to exit from vim??",
    "body": "I hear Vim is a very respected editor. So I was willing to try it out, but not I am not able to exit from it. And if I kill the process, the content of the file gets lost. What should I do?",
    "user_id": 1
  },
  "answer": {
    "id": 1,
    "body": "In order to exit Vim, type ':q'. If you want to save before exiting, type ':wq'.",
    "user_id": 1,
    "question_id": 1
  }
}

Endpoints

There are endpoints availables for questions, answers and users as follows:

Question endpoints:
POST /question
PUT /question/{id}
DELETE /question/{id}
GET /question/{id}
GET /questions
Answer endpoints:
POST /question/{id}/answer
PUT /question/{id}/answer
User endpoints:
POST /user
DELETE /user/{id-username}
GET /user/{id-username}
GET /user/{id-username}/questions
GET /users

Testing

This API can be tested automatically using go test or manually, by using the Postman file (which contains one test case for each route). Note: go test does not test the route handlers yet.

Things to add

  • Get answers by user: this feature could help checking who is more active in the community
  • Test each route handler.

Note: This project is for learning/testing. It is not taking any security measure. All the important data (as db username and password) is in plain text.